]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mk-string-arrays.awk
SBuf: convert HttpMethod internals
[thirdparty/squid.git] / src / mk-string-arrays.awk
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.
8 #
9 # 2009 modified by Amos Jeffries
10 # Adapted to convert individual enum headers
11 #
12
13 BEGIN {
14 print "/*"
15 print " * Auto-Generated File. Changes will be destroyed."
16 print " */"
17 print "#include \"squid.h\""
18 codeSkip = 1
19 e = 0
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
28 }
29
30 # Skip all lines outside of typedef {}
31 /^typedef/ { codeSkip = 0; next }
32 codeSkip == 1 { next }
33
34 /^[ \t]*[A-Z]/ {
35 split($1, t, ",") # remove ,
36 if (sbuf) Element[++e] = "SBuf(\"" t[1] "\")"
37 else Element[++e] = "\"" t[1] "\""
38 next
39 }
40
41 /^#/ {
42 if (codeSkip) next
43
44 Wrapper[++e] = $0
45 next
46 }
47
48 /^} / {
49 split($2, t, ";") # remove ;
50 type = t[1]
51 codeSkip = 1
52
53 if (sbuf) print "#include \"SBuf.h\""
54 print "#include \"" nspath type ".h\""
55
56 # if namesapce is not empty ??
57 if (namespace) print "namespace " namespace
58 if (namespace) print "{"
59
60 if (sbuf) print "\nconst SBuf " type "_sb[] = {"
61 else print "\nconst char * " type "_str[] = {"
62 for ( i = 1; i < e; ++i)
63 if (Wrapper[i]) print Wrapper[i]
64 else print "\t" Element[i] ","
65
66 print "\t" Element[i]
67 print "};"
68 if (namespace) print "}; // namespace " namespace
69 next
70 }