]> git.ipfire.org Git - thirdparty/squid.git/blame - src/mk-string-arrays.awk
SourceFormat: report broken file and continue after errors.
[thirdparty/squid.git] / src / mk-string-arrays.awk
CommitLineData
0f3f9baa 1# tested with gawk, mawk, and nawk.
2# drop-in replacement for mk-string-arrays.pl.
3# creates "enum.c" (on stdout) from "enum.h".
4# invoke similarly: perl -f mk-string-arrays.pl enum.h
5# --> awk -f mk-string-arrays.awk enum.h
6#
7# 2006 by Christopher Kerr.
8
9BEGIN { # converted to "const char *"TypedefEnum[?]"_str[]"
10 TypedefEnum["err_type"] = 1
11 TypedefEnum["lookup_t"] = 1
12 TypedefEnum["icp_opcode"] = 1
13 TypedefEnum["swap_log_op"] = 1
14}
15
16/^ \*\/$/ && Copyright != 1 { Copyright = 1; print; next }
17Copyright != 1 { print; next }
18/^typedef/ { e = 0; next }
19
20/^[ \t]*[A-Z]/ {
21 split($1, t, ",") # remove ,
22 Element[++e] = t[1]
23 next
24}
25
26/^} / {
27 split($2, t, ";") # remove ;
28 type = t[1]
29 if (TypedefEnum[type]) {
30 print "\nconst char *" type "_str[] = {"
31 for ( i = 1; i < e; ++i)
32 print "\t\"" Element[i] "\","
33 print "\t\"" Element[i] "\""
34 print "};"
35 }
36 next
37}
38