#
# deliver: generate static routing rules for delivery
#

REVISION_ID='@(#)deliver	3.12 (motonori/WIDE) 2/26/94'

#|# static routing description file
#|#STATIC_ROUTE_FILE=
#|# use WIDE macro/class extension (yes/no)
#|#WIDE_EXTENDED_MACRO=no

: ${WIDE_EXTENDED_MACRO=no}
if [ "$STATIC_ROUTE_FILE" ]
then

	if [ "$REVISION_ID_LIST" ]
	then
		REVISION_ID_LIST="$REVISION_ID_LIST\\
# $REVISION_ID"
	else
		REVISION_ID_LIST="# $REVISION_ID"
	fi

	if [ "$WIDE_EXTENDED_MACRO" != no ]
	then
		_ALLOC_MODE=extend
	else
		_ALLOC_MODE=normal
	fi
	_ALLOC_TYPE=pair
	_ALLOC_DIR=up
	_ALLOC_USAGE='gateway/destination [deliver]'

	# preserve argument vector
	ARVG="$@"

HDRSTATIC='\
# static routing definition\
#DAuucp:gateway1\
#CAdom1.domain dom2.domain dom3.domain\
#DBsmtp:gateway2\
#CBdom4.domain dom5.domain dom6.domain'

STATICRULE='\
# static routing for uucp/smtp\
#R$*<@$*DOMAIN_NAME>$*	'"$DISPATCH"' <uucp:GATEWAY>:$1<@$2DOMAIN_NAME>$3\
#R$*<@$*DOMAIN_NAME>$*	'"$DISPATCH"' <smtp:GATEWAY>:$1<@$2DOMAIN_NAME>$3\
#R$*<@$*$=A>$*		'"$DISPATCH"' <$A>:$1<@$2$3>$4	sample rule with macro/class'

	for RF in $STATIC_ROUTE_FILE
	do

	    # if STATIC_ROUTE_FILE exists
	    if [ -f "$RF" ]
	    then

		# parse one of STATIC_ROUTE_FILE
		exec < "$RF"
		while read LINE
		do
			case "$LINE" in
			'') ;;	# skip
			\#*) ;;	# skip
			*error:*)
				if [ "$USE_DEFAULT_ERROR_MESSAGES" != yes ]
				then
					USE_DEFAULT_ERROR_MESSAGES=yes
					echo "deliver: USE_DEFAULT_ERROR_MESSAGES is changed to yes." 1>&2
				fi
				;;
			esac
			case "$LINE" in
			'') ;;	# skip
			\#*) ;;	# skip
			*)
# the next line can not support quoting in STATIC_ROUTE_FILE
#				set $LINE
				eval "set `echo $LINE`"
#				eval "set `echo $LINE | sed -e 's/(/\\\\\\(/g' -e 's/)/\\\\\\)/g' -e 's/\$/\\\\\\$/g'`"

				case "$1" in

				V*|v*)	# version number
shift
REVISION_ID_LIST="$REVISION_ID_LIST\\
# $@" ;;

				G*|g*)	# Gateway description line
					if [ "$CF_FORMAT" = NMTC ]
					then
echo "deliver: G record should not be used with NMTC." 1>&2
					fi
					# allocate class/macro character pair
					. $MASTERDIR/$CHARALLOC
					CHAR=$_ALLOC_CHAR

STATICRULE="$STATICRULE"'\
R$*<@$*$='$CHAR'>$*		'"$DISPATCH"' <$'$CHAR'>:$1<@$2$3>$4'
HDRSTATIC="$HDRSTATIC\\
D$CHAR$2$3" ;;

				D*|d*)	# Destination description line
					if [ "$CF_FORMAT" = NMTC ]
					then
echo "deliver: D record should not be used with NMTC." 1>&2
					fi
					case "$2" in
					/*)	# use file class
HDRSTATIC="$HDRSTATIC\\
F$CHAR $2" ;;
					*)	# define a member of the class
						# in config file
shift
HDRSTATIC="$HDRSTATIC\\
C$CHAR $@" ;;
					esac ;;

				S*|s*)	# static delivery definition
					#  without macro/class

STATICRULE="$STATICRULE"'\
R$*<@$*'"$2"'>$*	'"$DISPATCH"' <'"$3$4"'>:$1<@$2'"$2"'>$3' ;;

				A*|a*)	# static delivery definition
					#  without macro/class with aliasing

STATICRULE="$STATICRULE"'\
R$*<@$*'"$2"'>$*	'"$DISPATCH"' <'"$4$5"'>:$1<@$2'"$3"'>$3' ;;

				M*|m*)	# map address and MX lookup

STATICRULE="$STATICRULE"'\
R$*<@$*'"$2"'>$*	'"$DISPATCH"' <'"$4"'$2'"$3"'>:$1<@$2'"$2"'>$3' ;;

				*) ;;	# other lines should be comment lines
				esac ;;
			esac

		done

	    else
		# if STATIC_ROUTE_FILE can not be found
		echo "deliver: $RF not found." 1>&2
	    fi

	done

	# recover argument vector
	set "$ARGV"

fi
