]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mk-globals-c.awk
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / mk-globals-c.awk
1 ## Copyright (C) 1996-2014 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 # drop-in replacement for mk-globals-c.pl.
10 # modified to work with Solaris awk (junk).
11 # creates "globals.c" (on stdout) from "globals.h".
12 # invoke similarly: perl mk-globals-c.pl globals.h
13 # --> awk -f mk-globals-c.awk globals.h
14 #
15 # 2006 by Christopher Kerr.
16
17 BEGIN { Copyright = 0
18 print "#include \"squid.h\"" }
19
20 Copyright != 1 && /^ \*\/$/ { Copyright = 1; print; next }
21 Copyright != 1 { print; next }
22 /SQUID_GLOBALS_H/ { next }
23
24 # arrays defined elsewhere
25 /\[\];/ { next }
26 /^extern \"C\"/ { print; next }
27
28 #
29 # Check exactly for lines beginning with " extern", generated
30 # from astyle (grrrrr ...)
31 #
32 /^ *extern / { # process "^extern " input lines.
33 # 0 1 2 #######
34 # extern int variable; /* val */ --> int variable; /* val */ #######
35 ##########################################################################
36 pos0 = index($0,"extern") #find how much whitespeace there is
37 str = substr($0,pos0,length($0))
38 len = length(str) - length("extern ") # sub(/extern /, "")
39 str = substr($0, length("extern ")+1, len) # strip "^extern ".
40
41 pos0 = index(str, ";") # position of ";".
42 pos1 = index(str, "/*") # position of "/*".
43 pos2 = index(str, "*/") # position of "*/".
44
45 if ( pos1 != 0 ) { # make assignment.
46
47 val = substr(str, pos1+3, pos2-pos1-4) # get comment value.
48 str = substr(str, 1, pos0-1) " = " val ";" # string to semi-colon.
49 }
50 print str; next # get next input line.
51 }
52 { print } # C preprocessor lines.