1USAGE_LICENSE="[-author?ATT]"
2########################################################################
3#                                                                      #
4#               This software is part of the ast package               #
5#          Copyright (c) 1986-2011 AT&T Intellectual Property          #
6#                      and is licensed under the                       #
7#                 Eclipse Public License, Version 1.0                  #
8#                    by AT&T Intellectual Property                     #
9#                                                                      #
10#                A copy of the License is available at                 #
11#          http://www.eclipse.org/org/documents/epl-v10.html           #
12#         (with md5 checksum b35adb5213ca9657e911e9befb180842)         #
13#                                                                      #
14#              Information and Software Systems Research               #
15#                            AT&T Research                             #
16#                           Florham Park NJ                            #
17#                                                                      #
18#                 Glenn Fowler <gsf@research.att.com>                  #
19#                                                                      #
20########################################################################
21:
22# Glenn Fowler
23# AT&T Bell Laboratories
24#
25# @(#)gentab (gsf@research.att.com) 07/17/94
26#
27# C table generator
28#
29#	%flags [ prefix=<prefix> ] [ index=<index> ] [ init=<init> ]
30#
31#	%keyword <name> [ prefix=<prefix> ] [ index=<index> ] [ init=<init> ] [ first=<id> ] [ last=<id> ]
32#
33#	%sequence [ prefix=<prefix> ] [ index=<index> ] [ init=<init> ]
34#
35
36case `(typeset -u s=a n=0; ((n=n+1)); print $s$n) 2>/dev/null` in
37A1)	shell=ksh
38	typeset -u ID
39	typeset -i counter err_line
40	;;
41*)	shell=bsh
42	;;
43esac
44command=$0
45counter=0
46define=1
47err_line=0
48type=""
49index=""
50first=""
51last=""
52table=1
53while	:
54do	case $1 in
55	-d)	table=0 ;;
56	-t)	define=0 ;;
57	*)	break ;;
58	esac
59	shift
60done
61case $1 in
62"")	err_file=""
63	;;
64*)	exec <$1
65	err_file="\"$1\", "
66	;;
67esac
68while	read line
69do	case $shell in
70	ksh)	((err_line=err_line+1)) ;;
71	*)	err_line=`expr $err_line + 1` ;;
72	esac
73	set '' $line
74	shift
75	case $1 in
76	[#]*)	echo "/*"
77		while	:
78		do	case $1 in
79			[#]*)	shift
80				echo " * $*"
81				read line
82				set '' $line
83				shift
84				;;
85			*)	break
86				;;
87			esac
88		done
89		echo " */"
90		echo
91		;;
92	esac
93	eval set '""' $line
94	shift
95	case $1 in
96	"")	;;
97	%flags|%keywords|%sequence)
98		case $define:$last in
99		1:?*)	case $shell in
100			ksh)	((n=counter-1)) ;;
101			*)	n=`expr $counter - 1` ;;
102			esac
103			echo "#define $prefix$last	$n"
104			;;
105		esac
106		case $type in
107		%flags|%sequence)
108			if	test $define = 1
109			then	echo
110			fi
111			;;
112		%keywords)
113			if	test $table = 1
114			then	echo "	0,	0"
115				echo "};"
116				echo
117			elif	test $define = 1
118			then	echo
119			fi
120			;;
121		esac
122		case $index in
123		?*)	eval $index=$counter ;;
124		esac
125		type=$1
126		shift
127		name=""
128		prefix=""
129		index=""
130		init=""
131		first=""
132		last=""
133		case $type in
134		%keywords)
135			case $1 in
136			"")	echo "$command: ${err_file}line $err_line: $type table name omitted" >&2
137				exit 1
138				;;
139			esac
140			name=$1
141			shift
142			if	test $table = 1
143			then	echo "$name"'[] ='
144				echo "{"
145			fi
146			;;
147		esac
148		eval "$@"
149		case $init in
150		"")	case $type in
151			%flags|%sequence)
152				init=0
153				;;
154			*)	init=1
155				;;
156			esac
157			;;
158		esac
159		case $index in
160		"")	counter=$init
161			;;
162		*)	eval value=\$$index
163			case $value in
164			"")		counter=$init ;;
165			[0123456789]*)	counter=$value ;;
166			esac
167			;;
168		esac
169		case $define:$first in
170		1:?*)	echo "#define $prefix$first	$counter" ;;
171		esac
172		;;
173	%*)	echo "$command: ${err_file}line $err_line: $1: unknown keyword" >&2
174		exit 1
175		;;
176	*)	while	:
177		do	case $1 in
178			"")	break
179				;;
180			*)	case $shell in
181				ksh)	ID=${1#[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]} ;;
182				*)	ID=`echo $1 | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | sed 's/^[^ABCDEFGHIJKLMNOPQRSTUVWXYZ_]//'` ;;
183				esac
184				case $type in
185				%flags)	if	test $define = 1
186					then	case $counter in
187						32) echo "$command: ${err_file}line $err_line: warning: $1: too many flag bits" >&2 ;;
188						1[56789]|[23][0123456789]) long=L ;;
189						*) long= ;;
190						esac
191						echo "#define $prefix$ID	(1$long<<$counter)"
192					fi
193					;;
194				%keywords)
195					if	test $define = 1
196					then	echo "#define $prefix$ID	$counter"
197					fi
198					if	test $table = 1
199					then	echo "	\"$1\",	$prefix$ID,"
200					fi
201					;;
202				%sequence)
203					if	test $define = 1
204					then	echo "#define $prefix$ID	$counter"
205					fi
206					;;
207				esac
208				case $shell in
209				ksh)	((counter=counter+1)) ;;
210				*)	counter=`expr $counter + 1` ;;
211				esac
212				shift
213				;;
214			esac
215		done
216		;;
217	esac
218done
219case $define:$last in
2201:?*)	case $shell in
221	ksh)	((n=counter-1)) ;;
222	*)	n=`expr $counter - 1` ;;
223	esac
224	echo "#define $prefix$last	$n"
225	;;
226esac
227case $type in
228%keywords)
229	if	test $table = 1
230	then	echo "	0,	0"
231		echo "};"
232	fi
233	;;
234esac
235exit 0
236