]> 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 197eb9bb3f263e401bbb68eb3ec934713eedfa6c..880e3a74b775cae9e836ed94099c6067e0bf6efc 100644 (file)
@@ -1,4 +1,4 @@
-## Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+## 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.
@@ -6,10 +6,8 @@
 ##
 
 # 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.
 #
@@ -36,6 +34,16 @@ 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]/ {
@@ -52,15 +60,24 @@ codeSkip == 1               { next }
        next
 }
 
+/};/ {
+  codeSkip = 1;
+}
+
 /^} / {
        split($2, t, ";")                       # remove ;
-       type = t[1]
-        codeSkip = 1
+  if (!type)
+    type = t[1]
+  codeSkip = 1
+  next
+}
 
-       if (sbuf) print "#include \"SBuf.h\""
-       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 "{"
 
@@ -73,5 +90,4 @@ codeSkip == 1         { next }
        print "\t" Element[i]
        print "};"
        if (namespace) print "}; // namespace " namespace
-       next
 }