Commit | Line | Data |
---|---|---|
2b262aec KB |
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.1 (Berkeley) %G% | |
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 | ||
17 | cat > /tmp/ka$$ <<\! | |
18 | TEOF 1 end of file | |
19 | TNL 0 newline | |
20 | TSEMI 0 ";" | |
21 | TBACKGND 0 "&" | |
22 | TAND 0 "&&" | |
23 | TOR 0 "||" | |
24 | TPIPE 0 "|" | |
25 | TLP 0 "(" | |
26 | TRP 1 ")" | |
27 | TENDCASE 1 ";;" | |
28 | TENDBQUOTE 1 "`" | |
29 | TREDIR 0 redirection | |
30 | TWORD 0 word | |
31 | TIF 0 "if" | |
32 | TTHEN 1 "then" | |
33 | TELSE 1 "else" | |
34 | TELIF 1 "elif" | |
35 | TFI 1 "fi" | |
36 | TWHILE 0 "while" | |
37 | TUNTIL 0 "until" | |
38 | TFOR 0 "for" | |
39 | TDO 1 "do" | |
40 | TDONE 1 "done" | |
41 | TBEGIN 0 "{" | |
42 | TEND 1 "}" | |
43 | TCASE 0 "case" | |
44 | TESAC 1 "esac" | |
45 | ! | |
46 | nl=`wc -l /tmp/ka$$` | |
47 | exec > token.def | |
48 | awk '{print "#define " $1 " " NR-1}' /tmp/ka$$ | |
49 | echo ' | |
50 | /* Array indicating which tokens mark the end of a list */ | |
51 | const char tokendlist[] = {' | |
52 | awk '{print "\t" $2 ","}' /tmp/ka$$ | |
53 | echo '}; | |
54 | ||
55 | char *const tokname[] = {' | |
56 | sed -e 's/"/\\"/g' \ | |
57 | -e 's/[^ ]*[ ][ ]*[^ ]*[ ][ ]*\(.*\)/ "\1",/' \ | |
58 | /tmp/ka$$ | |
59 | echo '}; | |
60 | ' | |
61 | sed 's/"//g' /tmp/ka$$ | awk ' | |
62 | /TIF/{print "#define KWDOFFSET " NR-1; print ""; print "char *const parsekwd[] = {"} | |
63 | /TIF/,/neverfound/{print " \"" $3 "\","}' | |
64 | echo ' 0 | |
65 | };' | |
66 | ||
67 | rm /tmp/ka$$ |