]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mk-string-arrays.awk
SourceFormat Enforcement
[thirdparty/squid.git] / src / mk-string-arrays.awk
1 ## Copyright (C) 1996-2017 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 # creates "enum.c" (on stdout) from "enum.h".
10 # when invoked: awk -f mk-string-arrays.awk enum.h
11 #
12 # 2006 by Christopher Kerr.
13 #
14 # 2009 modified by Amos Jeffries
15 # Adapted to convert individual enum headers
16 #
17
18 BEGIN {
19 print "/*"
20 print " * Auto-Generated File. Changes will be destroyed."
21 print " */"
22 print "#include \"squid.h\""
23 codeSkip = 1
24 e = 0
25 nspath = ""
26 }
27
28 # when namespace is encountered store it
29 /^namespace *[a-zA-Z]+/ {
30 nspath = tolower($2) "/" # nested folder
31 namespace = $2 # code namespace reconstruct
32 next
33 }
34
35 # Skip all lines outside of typedef {}
36 /^typedef/ { codeSkip = 0; next }
37 /^enum class / {
38 codeSkip = 0
39 type = $3
40 next;
41 }
42 /^enum / {
43 codeSkip = 0
44 type = $2
45 next;
46 }
47 codeSkip == 1 { next }
48
49 /^[ \t]*[A-Z]/ {
50 split($1, t, ",") # remove ,
51 if (sbuf) Element[++e] = "SBuf(\"" t[1] "\")"
52 else Element[++e] = "\"" t[1] "\""
53 next
54 }
55
56 /^#/ {
57 if (codeSkip) next
58
59 Wrapper[++e] = $0
60 next
61 }
62
63 /};/ {
64 codeSkip = 1;
65 }
66
67 /^} / {
68 split($2, t, ";") # remove ;
69 if (!type)
70 type = t[1]
71 codeSkip = 1
72 next
73 }
74
75 END {
76 if (sbuf) print "#include \"sbuf/SBuf.h\""
77 print "#include \"" nspath type ".h\""
78
79 # if namespace is not empty ??
80 if (namespace) print "namespace " namespace
81 if (namespace) print "{"
82
83 if (sbuf) print "\nconst SBuf " type "_sb[] = {"
84 else print "\nconst char * " type "_str[] = {"
85 for ( i = 1; i < e; ++i)
86 if (Wrapper[i]) print Wrapper[i]
87 else print "\t" Element[i] ","
88
89 print "\t" Element[i]
90 print "};"
91 if (namespace) print "}; // namespace " namespace
92 }