]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mk-string-arrays.awk
Merge from trunk rev.13584
[thirdparty/squid.git] / src / mk-string-arrays.awk
1 ## Copyright (C) 1996-2014 The Squid Software Foundation and contributors
2 ##
3 ## Squid software is distributed under GPLv2+ license and includes
4 ## contributions from numerous individuals and organizations.
5 ## Please see the COPYING and CONTRIBUTORS files for details.
6 ##
7
8 # tested with gawk, mawk, and nawk.
9 # drop-in replacement for mk-string-arrays.pl.
10 # creates "enum.c" (on stdout) from "enum.h".
11 # invoke similarly: perl -f mk-string-arrays.pl enum.h
12 # --> awk -f mk-string-arrays.awk enum.h
13 #
14 # 2006 by Christopher Kerr.
15 #
16 # 2009 modified by Amos Jeffries
17 # Adapted to convert individual enum headers
18 #
19
20 BEGIN {
21 print "/*"
22 print " * Auto-Generated File. Changes will be destroyed."
23 print " */"
24 print "#include \"squid.h\""
25 codeSkip = 1
26 e = 0
27 nspath = ""
28 }
29
30 # when namespace is encountered store it
31 /^namespace *[a-zA-Z]+/ {
32 nspath = tolower($2) "/" # nested folder
33 namespace = $2 # code namespace reconstruct
34 next
35 }
36
37 # Skip all lines outside of typedef {}
38 /^typedef/ { codeSkip = 0; next }
39 codeSkip == 1 { next }
40
41 /^[ \t]*[A-Z]/ {
42 split($1, t, ",") # remove ,
43 if (sbuf) Element[++e] = "SBuf(\"" t[1] "\")"
44 else Element[++e] = "\"" t[1] "\""
45 next
46 }
47
48 /^#/ {
49 if (codeSkip) next
50
51 Wrapper[++e] = $0
52 next
53 }
54
55 /^} / {
56 split($2, t, ";") # remove ;
57 type = t[1]
58 codeSkip = 1
59
60 if (sbuf) print "#include \"SBuf.h\""
61 print "#include \"" nspath type ".h\""
62
63 # if namesapce is not empty ??
64 if (namespace) print "namespace " namespace
65 if (namespace) print "{"
66
67 if (sbuf) print "\nconst SBuf " type "_sb[] = {"
68 else print "\nconst char * " type "_str[] = {"
69 for ( i = 1; i < e; ++i)
70 if (Wrapper[i]) print Wrapper[i]
71 else print "\t" Element[i] ","
72
73 print "\t" Element[i]
74 print "};"
75 if (namespace) print "}; // namespace " namespace
76 next
77 }