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