]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
AWK version of the build time mk-xxx scripts by Christopher Kerr.
authorhno <>
Wed, 22 Feb 2006 16:34:43 +0000 (16:34 +0000)
committerhno <>
Wed, 22 Feb 2006 16:34:43 +0000 (16:34 +0000)
src/mk-globals-c.awk [new file with mode: 0644]
src/mk-string-arrays.awk [new file with mode: 0644]

diff --git a/src/mk-globals-c.awk b/src/mk-globals-c.awk
new file mode 100644 (file)
index 0000000..b933f21
--- /dev/null
@@ -0,0 +1,38 @@
+# tested with gawk, mawk, and nawk.
+# drop-in replacement for mk-globals-c.pl.
+# modified to work with Solaris awk (junk).
+# creates "globals.c" (on stdout) from "globals.h".
+# invoke similarly: perl -f mk-globals-c.pl  globals.h
+#              -->  awk -f mk-globals-c.awk globals.h
+#
+# 2006 by Christopher Kerr.
+
+BEGIN                          { Copyright = 0
+                                 print "#include \"squid.h\"" }
+
+Copyright != 1 &&  /^ \*\/$/   { Copyright = 1; print; next }
+Copyright != 1                 {                print; next }
+/SQUID_GLOBALS_H/              {                       next }
+
+# arrays defined elsewhere
+/\[\];/                                {                       next }
+
+/^extern / {                                # process "^extern " input lines.
+                                            #           0 1      2    #######
+    # extern int variable; /* val */   -->   int variable; /* val */   #######
+    ##########################################################################
+    len = length($0) - 7                               # sub(/extern /, "")
+    str = substr($0, 8, len)                           # strip "^extern ".
+
+    pos0 = index(str, ";")                             # position of ";".
+    pos1 = index(str, "/*")                            # position of "/*".
+    pos2 = index(str, "*/")                            # position of "*/".
+
+    if ( pos1 != 0 ) {                                 # make assignment.
+
+       val = substr(str, pos1+3, pos2-pos1-4)          # get comment value.
+       str = substr(str, 1, pos0-1) " = " val ";"      # string to semi-colon.
+    }
+    print str; next                                    # get next input line.
+}
+{ print }                                              # C preprocessor lines.
diff --git a/src/mk-string-arrays.awk b/src/mk-string-arrays.awk
new file mode 100644 (file)
index 0000000..72995a5
--- /dev/null
@@ -0,0 +1,38 @@
+# 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
+#
+# 2006 by Christopher Kerr.
+
+BEGIN { # converted to "const char *"TypedefEnum[?]"_str[]"
+       TypedefEnum["err_type"] = 1
+       TypedefEnum["lookup_t"] = 1
+       TypedefEnum["icp_opcode"] = 1
+       TypedefEnum["swap_log_op"] = 1
+}
+
+/^ \*\/$/ && Copyright != 1    { Copyright = 1; print; next }
+Copyright != 1                 {                print; next }
+/^typedef/                     { e = 0;                next }
+
+/^[ \t]*[A-Z]/ {
+       split($1, t, ",")                       # remove ,
+       Element[++e] = t[1]
+       next
+}
+
+/^} / {
+       split($2, t, ";")                       # remove ;
+       type = t[1]
+       if (TypedefEnum[type]) {
+               print "\nconst char *" type "_str[] = {"
+               for ( i = 1; i < e; ++i)
+                       print "\t\"" Element[i] "\","
+               print "\t\"" Element[i] "\""
+               print "};"
+       }
+       next
+}
+