Re: perl

From: Henrik Nordstrom <hno@dont-contact.us>
Date: Wed, 22 Feb 2006 10:33:23 +0100

ons 2006-02-22 klockan 08:25 +0000 skrev
abc@ai1.anchorage.mtaonline.net:

> but it seems
> i would've had to redo it all anyway since Solaris
> awk is such a deficient implementation. the Solaris
> manpage i read says to use another awk in the /usr/xpg4
> directory. i don't have access to Solaris.

There is indeed a more functional awk in /usr/xpg4 more close to nawk in
functionality. But I do not want to probe around for which awk to use.
Additionally if it works in the Solaris awk then chances is very high it
will work in any other vendors awk.

Anyway I have massaged your mk-globals-c.awk so that it now works on
Solaris AWK. There were only two things it didn't like

  no match() in Solaris awk. Replaced by index().

  barfs on empty regex patterns //. Just deleted it as no pattern
expression at all also matches all input lines.

and you had not taken care of the empty arrays. Added another trivial
rule to skip input lines with the pattern [];

The massaged version is attached to this message.

For mk-string-arrays I think I stick with the simpler version I sent you
yesterday, unless you saw some problem with this.

Regards
Henrik

# 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 }

# Unspecified 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.

Received on Wed Feb 22 2006 - 02:33:27 MST

This archive was generated by hypermail pre-2.1.9 : Tue Feb 28 2006 - 12:00:05 MST