]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/mk-string-arrays.awk
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / mk-string-arrays.awk
index f1997334246022673216401a4366ccfce355e13b..880e3a74b775cae9e836ed94099c6067e0bf6efc 100644 (file)
@@ -1,8 +1,13 @@
+## Copyright (C) 1996-2021 The Squid Software Foundation and contributors
+##
+## Squid software is distributed under GPLv2+ license and includes
+## contributions from numerous individuals and organizations.
+## Please see the COPYING and CONTRIBUTORS files for details.
+##
+
 # tested with gawk, mawk, and nawk.
-# drop-in replacement for mk-string-arrays.pl.
 # creates "enum.c" (on stdout) from "enum.h".
-# invoke similarly: perl -f mk-string-arrays.pl         enum.h
-#              -->  awk -f mk-string-arrays.awk enum.h
+# when invoked:  awk -f mk-string-arrays.awk enum.h
 #
 # 2006 by Christopher Kerr.
 #
@@ -21,7 +26,7 @@ BEGIN {
 }
 
 # when namespace is encountered store it
-/^namespace [a-zA-Z]+/ {
+/^namespace *[a-zA-Z]+/        {
        nspath = tolower($2) "/"                # nested folder
        namespace = $2                          # code namespace reconstruct
        next
@@ -29,11 +34,22 @@ BEGIN {
 
 # Skip all lines outside of typedef {}
 /^typedef/             { codeSkip = 0; next }
+/^enum class / {
+  codeSkip = 0
+  type = $3
+  next;
+}
+/^enum / {
+  codeSkip = 0
+  type = $2
+  next;
+}
 codeSkip == 1          { next }
 
 /^[ \t]*[A-Z]/ {
        split($1, t, ",")                       # remove ,
-       Element[++e] = t[1]
+       if (sbuf) Element[++e] = "SBuf(\"" t[1] "\")"
+       else Element[++e] = "\"" t[1] "\""
        next
 }
 
@@ -44,24 +60,34 @@ codeSkip == 1               { next }
        next
 }
 
+/};/ {
+  codeSkip = 1;
+}
+
 /^} / {
        split($2, t, ";")                       # remove ;
-       type = t[1]
-        codeSkip = 1
+  if (!type)
+    type = t[1]
+  codeSkip = 1
+  next
+}
 
-       print "#include \"" nspath type ".h\""
+END {
+       if (sbuf) print "#include \"sbuf/SBuf.h\""
+       if (ifile != "") print "#include \"" ifile "\""
+        else print "#include \"" nspath type ".h\""
 
-       # if namesapce is not empty ??
+       # if namespace is not empty ??
        if (namespace) print "namespace " namespace
        if (namespace) print "{"
 
-       print "\nconst char *" type "_str[] = {"
+       if (sbuf) print "\nconst SBuf " type "_sb[] = {"
+       else print "\nconst char * " type "_str[] = {"
        for ( i = 1; i < e; ++i)
                if (Wrapper[i]) print Wrapper[i]
-               else print "\t\"" Element[i] "\","
+               else print "\t" Element[i] ","
 
-       print "\t\"" Element[i] "\""
+       print "\t" Element[i]
        print "};"
        if (namespace) print "}; // namespace " namespace
-       next
 }