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