:
#
#
# gennttab generates ntcontab.o
# usage: gennttab [ -n protocol-name  ... ]
#    -n: do not include protocol adapters with given names
#
# generates .s file for SunOS 5, AIXRIOS, SVR4_386, NCR 
#           .c file for all others
#

if [ "$ORACLE_TRACE" ]; then
  set -x
fi

if [ -z "$TMPDIR" ] ; 
then

  TMPDIR=/var/tmp

fi

##if [ -f ${ORACLE_HOME}/bin/lsnrctl ]; then
##  VER=`${ORACLE_HOME}/bin/lsnrctl foo | 2>/dev/null grep -i version | awk -F: '{print $2}' | awk -F. '{print $1}' | awk '{print $2}'`
##else
  VER=8
##fi

LIBPATH=${ORACLE_HOME}/lib
LIBNET="libn${VER}"
LIBNETPATH=${LIBPATH}/${LIBNET}

TRANSPORTS="US TCP ITCP BEQ TCPS SPX ISPX DEC DCE LU62 NMP RAW"
TtoINI="US:ntusini TCP:nttini BEQ:ntpini TCPS:ntzini SPX:ntsini DEC:ntdini DCE:ntodrini LU62:ntlini ITCP:ntitini ISPX:ntsini NMP:ntnini RAW:ntrini"
TtoBAS="US:ntus TCP:ntt BEQ:ntp TCPS:ntz SPX:nts DEC:ntd DCE:ntodr LU62:ntl ITCP:ntit ISPX:ntis NMP:ntn RAW:ntr"
TtoNAM="US:IPC TCP:TCP/IP BEQ:BEQueath TCPS:SSL SPX:SPX ISPX:TLI/SPX DEC:DECNet DCE:DCE LU62:LU6.2 ITCP:TLI/TCP NMP:NamedPipes RAW:RAW"
TtoLIB="US:us TCP:tcp BEQ:beq TCPS:tcps SPX:spx DEC:dec DCE:dce LU62:lu62 ITCP:tlit ISPX:tlis NMP:nmp RAW:raw"

  nm ${LIBNETPATH}.*        > $TMPDIR/net$$ 2> /dev/null

for T in $TRANSPORTS; do
# Default is to use all available drivers
  eval NTUSE$T="true"

  LIB=`echo ${TtoLIB}  | sed 's/ /\\
/g' | grep "^${T}:" | awk -F: '{print $2}'`
  INI=`echo ${TtoINI}  | sed 's/ /\\
/g' | grep "^${T}:" | awk -F: '{print $2}'`
  BAS=`echo ${TtoBAS} | sed 's/ /\\
/g' | grep "^${T}:" | awk -F: '{print $2}'`

  if [ -z "${LIB}" ] ; then
    ln -s $TMPDIR/net$$ $TMPDIR/${T}$$
  else

    nm        ${LIBPATH}/libn${LIB}${VER}.* > ${TMPDIR}/${T}$$ 2> /dev/null

  fi

  if [ "`grep ${INI} ${TMPDIR}/${T}$$ 2> /dev/null`" = "" ]; then

    eval NTUSE${T}="false"
  fi
done

#
# Now begins the big divide between SunOS 5 and the rest of the world...
#

# Print the comment header for the output file
echo '!'
echo '!'
echo '! This File Is GENERATED By gennttab on SunOS 5.'
echo '!'
echo '!'

echo '! define cpp macros'
echo
echo '#define DATA	.section ".data"'
echo '#define STRING	.section ".data1",#write,#alloc'
echo '#define CONSTANT .section ".rodata"'
echo '#define TYPE(label, size) .type	label, #object; .size label, size'

echo
echo '! More macros'

echo '#define NTCON_RECORD(str1, ptr, str2, str3) \'
echo '	.align	4	;\'
echo '	.word	str1	;\'
echo '	.align  4	;\'
echo '	.word	ptr	;\'
echo '	.align	4	;\'
echo '	.word	str2	;\'
echo '	.align	4	;\'
echo '	.word	str3'

echo '
! Declare the string table

	STRING
.RINI:	.asciz	"raw"
	.align	4
.RINI2:	.asciz	"ntrini"
	.align	4
.RINI3:	.asciz	"ntr"
	.align	4
.TINI:	.asciz	"tcp"
	.align	4
.TINI2:	.asciz	"nttini"
	.align	4
.TINI3:	.asciz	"ntt"
	.align	4
.TINI4:	.asciz	"ntitcn"
	.align	4
.TINI5:	.asciz	"ntlit"
	.align	4
.TZ1:	.asciz	"tcps"
	.align	4
.TZ2:	.asciz	"ntzini"
	.align	4
.TZ3:   .asciz	"ntcps"
	.align	4
.X:	.asciz	"x25"
	.align	4
.X2:	.asciz	"ntxini"
	.align	4
.X3:	.asciz	"ntx"
	.align	4
.SPX:	.asciz	"spx"
	.align	4
.SPX2:	.asciz	"ntsini"
	.align	4
.SPX3:	.asciz	"nts"
	.align	4
.SPX4:	.asciz	"ntlis"
	.align	4
.NTB:	.asciz	"ntb"
	.align	4
.NTB2:	.asciz	"ntbini"
	.align	4
.NTB3:	.asciz	"ntb"
	.align	4
.DEC:	.asciz	"decnet"
	.align	4
.DEC2:	.asciz	"ntdini"
	.align	4
.DEC3:	.asciz	"ntd"
	.align	4
.DEC4:	.asciz	"ntidini"
	.align	4
.DEC5:	.asciz	"ntid"
	.align	4
.IPC:	.asciz	"beq"
	.align	4
.IPC2:	.asciz	"ntpini"
	.align	4
.IPC3:	.asciz	"ntp"
	.align	4
.SOC:	.asciz	"ipc"
	.align	4
.SOC2:	.asciz	"ntusini"
	.align	4
.SOC3:	.asciz	"ntus"
	.align	4
.NMP:	.asciz	"nmp"
	.align	4
.NMP2:	.asciz	"ntnini"
	.align	4
.NMP3:	.asciz	"ntn"
	.align	4
.OSI:	.asciz	"osi4"
	.align	4
.OSI2:	.asciz	"ntio4cn"
	.align	4
.OSI3:	.asciz	"nto4"
	.align	4
.LU62:	.asciz	"lu62"
	.align	4
.LU622: .asciz	"ntlini"
	.align	4
.LU623: .asciz	"ntls"
	.align	4
.ASYNC:	.asciz	"async"
	.align	4
.ASYNC2: .asciz	"ntasgini"
	.align	4
.ASYNC3: .asciz	"ntas"
	.align	4
.DCE: 	.asciz  "dce"
	.align  4
.DCE2:  .asciz	"ntodrini"
	.align  4
.DCE3: .asciz "ntod"
	.align  4

! Now the protocol table

	DATA
	.global	ntcontab
ntcontab:

'

# Count number of entries

count=0
count=`expr $count + 1`
echo 'NTCON_RECORD(.RINI, ntrini, .RINI2, .RINI3)'

##if [ "${NTUSETCP}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.TINI, nttini, .TINI2, .TINI3)'
##fi
if [ "${NTUSETCPS}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.TZ1, ntzini, .TZ2, .TZ3)'
fi
if [ "${NTUSEITCP}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.TINI, ntitini, .TINI4, .TINI5)'
fi
if [ "${NTUSEX25}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.X, ntxini, .X2, .X3)'
fi
if [ "${NTUSESPX}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.SPX, ntsini, .SPX2, .SPX3)'
fi
if [ "${NTUSEISPX}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.SPX, ntsini, .SPX2, .SPX4)'
fi
if [ "${NTUSENTB}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.NTB, nttini, .NTB2, .NTB3)'
fi
if [ "${NTUSEDNT}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.DEC, ntdini, .DEC2, .DEC3)'
fi
if [ "${NTUSEIDNT}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.DEC, ntidini, .DEC4, .DEC5)'
fi
count=`expr $count + 1`
echo 'NTCON_RECORD(.IPC, ntpini, .IPC2, .IPC3)'
count=`expr $count + 1`
echo 'NTCON_RECORD(.SOC, ntusini, .SOC2, .SOC3)'

if [ "${NTUSENMP}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.NMP, ntnini, .NMP2, .NMP3)'
fi
if [ "${NTUSEIOSI}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.OSI, ntio4ini, .OSI2, .OSI3)'
fi
if [ "${NTUSELU62}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.LU62, ntlini, .LU622, .LU623)'
fi
if [ "${NTUSEASYNC}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.ASYNC, ntasgini, .ASYNC2, .ASYNC3)'
fi
if [ "${NTUSEDCE}" = "true" ]; then
	count=`expr $count + 1`
	echo 'NTCON_RECORD(.DCE, ntodrini, .DCE2, .DCE3)'
fi

echo '

! Similar to C : { 0,0,0,0 }
	.align	4
	.word	0
	.align	4
	.word	0
	.align	4
	.word	0
	.align	4
	.word	0

! const int ntconent = sizeof(ntcontab)/sizeof(ntcontab[0]) - 1

	CONSTANT
	.global	ntconent
ntconent:
	.align	4
'
# Double quotes need for count to print

echo "	.word	$count"

echo '
! Epilog

'

