xref: /original-bsd/bin/sh/mktokens (revision 94e7bb75)
1#!/bin/sh -
2#
3# Copyright (c) 1991 The Regents of the University of California.
4# All rights reserved.
5#
6# This code is derived from software contributed to Berkeley by
7# Kenneth Almquist.
8#
9# %sccs.include.redist.sh%
10#
11#	@(#)mktokens	5.2 (Berkeley) 04/16/92
12
13# The following is a list of tokens.  The second column is nonzero if the
14# token marks the end of a list.  The third column is the name to print in
15# error messages.
16
17cat > /tmp/ka$$ <<\!
18TEOF	1	end of file
19TNL	0	newline
20TSEMI	0	";"
21TBACKGND 0	"&"
22TAND	0	"&&"
23TOR	0	"||"
24TPIPE	0	"|"
25TLP	0	"("
26TRP	1	")"
27TENDCASE 1	";;"
28TENDBQUOTE 1	"`"
29TREDIR	0	redirection
30TWORD	0	word
31TIF	0	"if"
32TTHEN	1	"then"
33TELSE	1	"else"
34TELIF	1	"elif"
35TFI	1	"fi"
36TWHILE	0	"while"
37TUNTIL	0	"until"
38TFOR	0	"for"
39TDO	1	"do"
40TDONE	1	"done"
41TBEGIN	0	"{"
42TEND	1	"}"
43TCASE	0	"case"
44TESAC	1	"esac"
45TNOT	0	"!"
46!
47nl=`wc -l /tmp/ka$$`
48exec > token.def
49awk '{print "#define " $1 " " NR-1}' /tmp/ka$$
50echo '
51/* Array indicating which tokens mark the end of a list */
52const char tokendlist[] = {'
53awk '{print "\t" $2 ","}' /tmp/ka$$
54echo '};
55
56char *const tokname[] = {'
57sed -e 's/"/\\"/g' \
58    -e 's/[^	 ]*[	 ][	 ]*[^	 ]*[	 ][	 ]*\(.*\)/	"\1",/' \
59    /tmp/ka$$
60echo '};
61'
62sed 's/"//g' /tmp/ka$$ | awk '
63/TIF/{print "#define KWDOFFSET " NR-1; print ""; print "char *const parsekwd[] = {"}
64/TIF/,/neverfound/{print "	\"" $3 "\","}'
65echo '	0
66};'
67
68rm /tmp/ka$$
69