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