-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_parserflags.sh
executable file
·47 lines (39 loc) · 1.42 KB
/
gen_parserflags.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Generate error flags and messages
# to be used in conjunction with error.c and error.h
# searches the sources for commentlines following the pattern:
# // ERRORFLAG <FLAGNAME> "<message string>"
#
# it generates a macro by the name FLAGNAME and adds a string to the error string array
# the defines are in errorflags.h"
# the message array in "errormessages.h"
# the errorflags.h should be included in all sources that throw errors
# the "errormessages.h" is a private include for the error.c
FILE="parsedef.h"
echo "/* File generated by gen_parserflags.sh, do not edit by hand */" > $FILE
NFLAGS=0;
echo "#ifndef PARSEDEF_H" >> $FILE
echo "#define PARSEDEF_H" >> $FILE
# first collect all error flags in one file
for s in $@
do
echo Collecting error flags from $s
egrep -o '^// PARSEFLAG.*' $s | sort | uniq >>tmpflags
done
# create the parse flag defines
awk '{print "void "$4"(char *in);"}' tmpflags | sort | uniq>>$FILE
echo "typedef void (*ParserFun)(char *in);">>$FILE
echo "typedef struct {">>$FILE
echo " char *key;">>$FILE
echo " ParserFun fun;">>$FILE
echo "} KeyWord;">>$FILE
echo "const KeyWord KeyTable[] = {">>$FILE
awk '{print "\t{\""$3"\", &"$4"},"}' tmpflags>>$FILE
echo " {NULL, NULL}">>$FILE
echo "};">>$FILE
echo "char *Usage[] = {" >> $FILE
sed -n 's/\/\/ PARSEFLAG.*\(\".*\"\)/\t\1,/gp' tmpflags>> $FILE
echo " NULL" >> $FILE
echo "};" >> $FILE
echo "#endif /*PARSEDEF_H*/" >> $FILE
rm tmpflags