]> git.ipfire.org Git - thirdparty/squid.git/blame_incremental - src/mk-string-arrays.awk
Simplify appending SBuf to String (#2108)
[thirdparty/squid.git] / src / mk-string-arrays.awk
... / ...
CommitLineData
1## Copyright (C) 1996-2025 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
18BEGIN {
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}
47codeSkip == 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
75END {
76 if (sbuf) print "#include \"sbuf/SBuf.h\""
77 if (ifile != "") print "#include \"" ifile "\""
78 else print "#include \"" nspath type ".h\""
79
80 # if namespace is not empty ??
81 if (namespace) print "namespace " namespace
82 if (namespace) print "{"
83
84 if (sbuf) print "\nconst SBuf " type "_sb[] = {"
85 else print "\nconst char * " type "_str[] = {"
86 for ( i = 1; i < e; ++i)
87 if (Wrapper[i]) print Wrapper[i]
88 else print "\t" Element[i] ","
89
90 print "\t" Element[i]
91 print "};"
92 if (namespace) print "}; // namespace " namespace
93}