Annotation of libwww/config/makedefs.pl, revision 1.4

1.1       eric        1: #!/usr/local/bin/perl
1.3       eric        2: # 
                      3: # syntax: makedefs.pl [options] [files | @[filelist]]
                      4: #   where options are 
                      5: #     -d<directory>: look for files in <directory>.
                      6: #     -header<text>: add <text> to top of file.
                      7: #     -e: no more options (like grep -e). Allows access to files with
                      8: #         a leading - in their name.
                      9: #     <files> is one or more files in the form <filename[@<offset>]>
                     10: #       where <filename> is a file in which to look for functions.
                     11: #     <offset> is the desired offset for the first functions. The <offset> 
                     12: #       directive will be ignored if it will cause a conflict with a 
                     13: #       function offset already defined in the def file.
                     14: #     [filelist] is a file containing these lists. If ommited, makedefs
                     15: #       looks to stdin for a filelist.
                     16: #
                     17: # example call: ../../../config/makedefs.pl -headerEXPORTS -d.. @wwwcore.files
                     18: #   read the list of files from wwwcore.files, grep these files for 'PUBLIC',
                     19: #   and send the output to stdout.
                     20: #
                     21: # EGP July 5 96
                     22: #
1.1       eric       23: 
1.3       eric       24: $NumberDefs'granularity = 100;  # how much the index changes for each file
1.1       eric       25: $NumberDefs'at = 24;            # target at sign column
                     26: $NumberDefs'tab = 8;            # how wide a tab looks in your editor
                     27: $NumberDefs'offset = 0;         # starting number
                     28: $NumberDefs'index;
1.3       eric       29: $WorkDir = '';
1.1       eric       30: 
                     31: sub NumberDefs'numberEach
                     32: {
                     33:     package NumberDefs;
1.3       eric       34:     local($name, $passedOffset) = @_;
1.1       eric       35:     if ($name eq "") {
                     36:        print "\n";
                     37:        next;
                     38:     }
1.3       eric       39: 
                     40:     if ($passedOffset && $passedOffset > $offset) {
                     41:        $index = $offset = $passedOffset;
                     42:     } elsif ($name =~ /^;/) {
                     43:        $index = $offset = (int($index / $granularity) +1) * $granularity;
1.1       eric       44:     }
1.3       eric       45: 
1.1       eric       46:     print $name;
1.3       eric       47: 
1.1       eric       48:     $len = length($name);
                     49:     if ($len >= $at) {
                     50:        print " ";
                     51:     } else {
                     52:        $tabz = (($at-$len)/$tab);
                     53:        for ($i = 0; $i < $tabz; $i++) {
                     54:            print "\t";
                     55:        }
                     56:     }
                     57:     print "@ ", $index, "\n";
                     58:     $index ++;
                     59: }
                     60: 
                     61: # numberAll - call this to renumber a def file
                     62: #
                     63: sub NumberDefs'numberAll
                     64: {
                     65:     package NumberDefs;
                     66:     $INPUT = $_[0];
                     67:     while(<$INPUT>) {
                     68:        local($name) =  split(" ",$_);
                     69:        &NumberDefs'numberEach($name);
                     70:     }
                     71: }
                     72: 
                     73: sub GrepPublic
                     74: {
1.3       eric       75:     local($source, $offset) = split('@', @_[0]);
                     76:     if (!open (SOURCE, $WorkDir.$source)) {
                     77:        warn "Can't open $WorkDir$source: $!\n"; 
1.1       eric       78:        return;
                     79:     }
1.3       eric       80:     &NumberDefs'numberEach(';'.$source, $offset); # add source file as a source
1.1       eric       81:     while (<SOURCE>) {
                     82:        if (!/^PUBLIC\s/) {
                     83:             next;
                     84:         }
                     85:         if (!/(\w*)\W*\(/) {
                     86:             warn "assuming global: ", $_;
                     87:             next;
                     88:         }
                     89:         local($func) = $1;
                     90: #       printf "\$_:\"%s\" \$func:\"%s\"\n", $_, $func;
                     91:         &NumberDefs'numberEach($func);
                     92:     }
                     93: }
                     94: 
1.3       eric       95: sub ReadArg
                     96: {
                     97:     local($arg) = substr(@_[0], 1);
                     98:     return 0 if ($arg eq 'e');
                     99:     if (substr($arg, 0, 6) eq 'header') {
                    100:        print substr($arg, 6), "\n";
                    101:     } elsif (substr($arg, 0, 1) eq 'd') {
                    102:        $WorkDir = substr($arg, 1);
                    103:        $WorkDir .= '/' if (!($WorkDir =~ /\/$/));
                    104:     } else {
                    105:        print "unknown argument \"$arg\".\n";
                    106:     }
                    107:     return 1;
                    108: }
                    109: 
                    110: while (@ARGV[0] =~ /^-/ && &ReadArg(shift(@ARGV))) {}
                    111: if (@ARGV[0] =~ /^@(.*)/) {
1.1       eric      112:     local($name) = $1;
                    113:     if ($name =~ /\w+/) {
                    114:        if (!open(LIST, $name)) {
1.4     ! frystyk   115:            die "Can't open \"$name\", $!";
1.1       eric      116:        }
                    117:        while (<LIST>) {
                    118:            chop;
                    119:            &GrepPublic($_);
                    120:            print "\n";
                    121:        }
                    122:        exit 0;
                    123:     }
                    124:     while (<STDIN>) {
                    125:        chop;
                    126:        &GrepPublic($_);
                    127:        print "\n";
                    128:     }
                    129:     exit 0;
                    130: }
                    131: foreach $source (@ARGV) {
                    132:     &GrepPublic($source);
                    133: }
                    134: 
                    135: #&NumberDefs'numberAll(STDIN);
                    136: 

Webmaster