#!/bin/sh
#
#  ehelp: table listing program for EGTS (UNIX version)

	usage="ehelp devicetype"

#	version control:
#	===============
#  	V1.0  KH  5 May 90:	initial version
#  	V1.1  KH 30 May 90:	cleaned up nawk error output
#  	V1.2  KH 19 Oct 90:	bg replaces bics
#  	V1.3  KH 29 Oct 90:	BARCO_EGTS_DATA_DIR replaces BARCO_EGTS_CONFIG
#  	V1.4  KH 14 Dec 90:	graceful exit from no datafile
#  	V1.5  KH 15 Jan 91:	env vars become BG_XXX

datafile=${BG_EGTS_DATA_DIR:-${BG_DIR:-/usr/local/bg}/egts/dat}/config.dat
if [ ! -f $datafile ]
then 	echo ehelp: data file $datafile does not exist
	exit 1
fi
if [ $# -lt 1 ]
then	echo $usage
	exit 1
fi
echo $* | tr '[a-z]' '[A-Z]' | nawk '
	BEGIN			{ FS = " " }
	NR == 1			{ devicetype = $1; FS = "," }
	/^\[[A-Z]+\]$/		{ running = (match($0, devicetype)? 1: 0) }
	$0 ~ /^[^;\[]/ && $0 ~ /[^\t\ ]/	{
		 if (running)
			if ($2) {
				n = split($2, address, ":")
				if (n > 2)
					break
				if (n == 2) 
					eth_dev = address[1]
				else 
					eth_dev = ""
				gsub("-", ":", address[n])
				eth_dst = address[n]
				printf("%s\t%s\n", $1, eth_dst)
			}
	}
' - $datafile 2>/dev/null
if [ $? -ne 0 ]
then	echo ehelp: unsuccesful termination
	exit 1
fi
