]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mk-string-arrays.awk
Maintenance: remove unused mk-string-arrays.pl script
[thirdparty/squid.git] / src / mk-string-arrays.awk
1 ## Copyright (C) 1996-2015 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 codeSkip == 1 { next }
38
39 /^[ \t]*[A-Z]/ {
40 split($1, t, ",") # remove ,
41 if (sbuf) Element[++e] = "SBuf(\"" t[1] "\")"
42 else Element[++e] = "\"" t[1] "\""
43 next
44 }
45
46 /^#/ {
47 if (codeSkip) next
48
49 Wrapper[++e] = $0
50 next
51 }
52
53 /^} / {
54 split($2, t, ";") # remove ;
55 type = t[1]
56 codeSkip = 1
57
58 if (sbuf) print "#include \"SBuf.h\""
59 print "#include \"" nspath type ".h\""
60
61 # if namesapce is not empty ??
62 if (namespace) print "namespace " namespace
63 if (namespace) print "{"
64
65 if (sbuf) print "\nconst SBuf " type "_sb[] = {"
66 else print "\nconst char * " type "_str[] = {"
67 for ( i = 1; i < e; ++i)
68 if (Wrapper[i]) print Wrapper[i]
69 else print "\t" Element[i] ","
70
71 print "\t" Element[i]
72 print "};"
73 if (namespace) print "}; // namespace " namespace
74 next
75 }