Re: perl

From: <abc@dont-contact.us>
Date: Thu, 23 Feb 2006 03:26:59 GMT

> Have you had any chance to test building Squid with the awk scripts?

in:

    src/Makefile.am
    src/Makefile.in

i changed:

    PERL -> AWK
    .pl -> .awk

and:

    i had to add the "-f" option to the 2 command
    lines in each file that call the mk-* scripts.

i only keep "sent mail" and did not
have the script you sent me, so i
used the following, and they do work.

it's still compiling and may take a while.
but it got past all the trouble spots.
i'm on a Pentium 100 :)
 
> Regards
> Henrik

--
80 columns, no tabs:
--
# 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 }                                           # output other lines.
###############################################################################
--
# tested with gawk, mawk, and nawk.
# drop-in replacement for mk-string-arrays.pl.
# modified to work with Solaris awk (junk).
# creates "enums.c" (on stdout) from "enums.h".
# invoke similarly: perl -f mk-string-arrays.pl  enums.h
#               -->  awk -f mk-string-arrays.awk enums.h
#
# 2006 by Christopher Kerr.
###############################################################################
BEGIN { Copyright = 0; # convert TE's to "const char *"TypedefEnum[?]"_str[]".
    TypedefEnum[1]="err_type"
    TypedefEnum[2]="lookup_t"
    TypedefEnum[3]="icp_opcode"
    TypedefEnum[4]="swap_log_op"
}
###############################################################################
Copyright != 1  &&  /^ \*\/$/   { Copyright = 1; print; next }
Copyright != 1                  {                print; next }
/SQUID_GLOBALS_H/               {                       next }
###############################################################################
/^    [A-Z]/ {                                          # Typedef enum element.
                                                        # store in Element[e].
    # WARNING: expects "^    ELEMENT,"
    # format in enums.h, EXACTLY 4 spaces!
    # AND beginning with a capital letter.
    pos0 = 5; pos1 = index($0, ",")                     # element, comma end.
    if ( pos1 == 0 ) pos1 = length($0)+1                # element, w/o comma.
    Element[++e] = substr($0, pos0, pos1-pos0)          # store element in E[].
}
###############################################################################
/^}/ {                                                  # Typedef enum ends.
                                                        # output declaration.
    # WARNING: expects "^} identifier;"
    # format in enums.h, EXACTLY 1 space!
    # OR just "^}" in line (no identifier).
    str  = substr($0, 3, index($0, ";")-3)              # Typedef name, store.
    for ( te = 1; TypedefEnum[te] != 0; ++te ) {        # try to match TE[]'s.
        if ( str == TypedefEnum[te] ) {                 # matching TypedefEnum?
            print "\nconst char *" str "_str[] = {\n"   # then declare array,
            for ( i = 1; i <= e; ++i ) {                # ... with Elements.
                if ( i < e ) print "    \""Element[i]"\","      # end w/comma.
                else         print "    \""Element[i]"\"\n};"   # last Element.
            }
        }
    }
    for ( i = 1; i <= e; ++i ) Element[i] = 0; e = 0    # delete Element[e].
}
###############################################################################
Received on Wed Feb 22 2006 - 21:19:31 MST

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