:
#	@(#) cvttai.sh 23.3 91/08/29 
#
#	Copyright (C) 1990-1991 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#
# Convert MMDF-II rel 32 mmdftailor file to equivalent
#         MMDF-II rel 43 mmdftailor file
#
trap "rm -f /tmp/$$*; exit" 0 1 2 3 5

cat >/tmp/$$.sed <<\END_OF_SED
1{
	h
	d
}

$b last

/^[ 	]*;/b subs

/^[ 	]*$/{
	s/.*//
	b subs
}

/^[ 	]/{
	H
	d
}

:subs
x
/^[ 	]*;/ {
	p
	d
}
s/\n/ /g
s/[,	]/ /g
s/   */ /g
p
d

:last
/^[ 	][ 	]*[^;]/{
H
b subs
}

x
/^[ 	]*;/ {
	p
	d
}
s/\n/ /g
s/[,	]/ /g
s/   */ /g
p

x
/^[ 	]*;/ {
	p
	d
}
s/\n/ /g
s/[,	]/ /g
s/   */ /g
END_OF_SED

cat >/tmp/$$.awk <<\END_OF_AWK
BEGIN		{
			MDMN="^[mM][dD][mM][nN]$"
		}

$1 ~ MDMN	{
			table=$2
			for (i = 3; i <= NF; ++i) {
				if ($i ~ /^table=/)
					table = substr($i, 7)
			}

			printf("/^[Mm][Tt][Bb][Ll][ \\t]+(%s|(.*name=\\\"?%s([ \t,])|$))/", table, table)
			printf(" {\n\tprint $0 \"\\,\"\n")
			printf("\tprintf(\"\\tflags=domain, flags=partial, flags=route\\n\")\n")
			printf("\tnext\n}\n")
		}
END		{
			printf("{\n\tprint\n}\n")
		}
END_OF_AWK

sed -f /tmp/$$.sed mmdftailor | awk -f /tmp/$$.awk >/tmp/$$.gen
awk -f /tmp/$$.gen mmdftailor >mmdftailor.new

echo "conversion done.  new mmdftailor in mmdftailor.new"
