]>
Commit | Line | Data |
---|---|---|
0f3f9baa | 1 | # tested with gawk, mawk, and nawk. |
2 | # drop-in replacement for mk-string-arrays.pl. | |
3 | # creates "enum.c" (on stdout) from "enum.h". | |
4 | # invoke similarly: perl -f mk-string-arrays.pl enum.h | |
5 | # --> awk -f mk-string-arrays.awk enum.h | |
6 | # | |
7 | # 2006 by Christopher Kerr. | |
4b981814 AJ |
8 | # |
9 | # 2009 modified by Amos Jeffries | |
10 | # Adapted to convert individual enum headers | |
11 | # | |
0f3f9baa | 12 | |
4b981814 AJ |
13 | BEGIN { |
14 | print "/*" | |
15 | print " * Auto-Generated File. Changes will be destroyed." | |
16 | print " */" | |
f7f3304a | 17 | print "#include \"squid.h\"" |
4b981814 AJ |
18 | codeSkip = 1 |
19 | e = 0 | |
331632e5 AJ |
20 | nspath = "" |
21 | } | |
22 | ||
23 | # when namespace is encountered store it | |
24 | /^namespace [a-zA-Z]+/ { | |
25 | nspath = tolower($2) "/" # nested folder | |
26 | namespace = $2 # code namespace reconstruct | |
27 | next | |
0f3f9baa | 28 | } |
29 | ||
4b981814 AJ |
30 | # Skip all lines outside of typedef {} |
31 | /^typedef/ { codeSkip = 0; next } | |
32 | codeSkip == 1 { next } | |
0f3f9baa | 33 | |
34 | /^[ \t]*[A-Z]/ { | |
35 | split($1, t, ",") # remove , | |
36 | Element[++e] = t[1] | |
37 | next | |
38 | } | |
39 | ||
0d03fdb8 AJ |
40 | /^#/ { |
41 | if (codeSkip) next | |
42 | ||
43 | Wrapper[++e] = $0 | |
44 | next | |
45 | } | |
46 | ||
0f3f9baa | 47 | /^} / { |
48 | split($2, t, ";") # remove ; | |
49 | type = t[1] | |
4b981814 AJ |
50 | codeSkip = 1 |
51 | ||
331632e5 AJ |
52 | print "#include \"" nspath type ".h\"" |
53 | ||
54 | # if namesapce is not empty ?? | |
55 | if (namespace) print "namespace " namespace | |
56 | if (namespace) print "{" | |
57 | ||
4b981814 AJ |
58 | print "\nconst char *" type "_str[] = {" |
59 | for ( i = 1; i < e; ++i) | |
0d03fdb8 AJ |
60 | if (Wrapper[i]) print Wrapper[i] |
61 | else print "\t\"" Element[i] "\"," | |
62 | ||
4b981814 AJ |
63 | print "\t\"" Element[i] "\"" |
64 | print "};" | |
331632e5 | 65 | if (namespace) print "}; // namespace " namespace |
0f3f9baa | 66 | next |
67 | } |