Re: perl

From: <abc@dont-contact.us>
Date: Wed, 22 Feb 2006 11:09:58 GMT

> 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().

ok - i did follow a manpage for Solaris on the web,
and it did have match(). index() is fine, i was trying
to be consistent with a more versatile function in case
of further changes being necessary by someone not
familiar with awk.

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

yes, ok - i just used // to make the pattern-action
rules explicit for people not too familiar with awk.
i suppose /^/ may have worked as well, i don't know.

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

yes, ok - now i understand - i initially thought you
were talking about empty arrays in awk having to do
with the Solaris-unsupported awk "delete" function.
i saw the discrepency in the output compared with perl,
but i thought it was a bug in the perl script not
processing all lines :(
 
> 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.

whatever works is fine - i like squid, and
i just wanted to help. i apologize if i was
more work than help. thank you for your
guiding criticisms and corrections.

Chris (NetBSD/FreeBSD admin/user).

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

/\[\];/ { next } # skip unspecified C arrays.
                                            # ... (defined elsewhere).
/^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 - 05:13:16 MST

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