Changeset 283 in openpam for trunk


Ignore:
Timestamp:
Jan 28, 2005, 1:56:15 PM (14 years ago)
Author:
Dag-Erling Smørgrav
Message:

Numerous improvements inspired by comments from ru@. Mainly, this
fixes a couple of markup bugs, improves reference sorting, and
improves handling of function argument names (function pointer
arguments were not properly handled).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/misc/gendoc.pl

    r280 r283  
    3333# SUCH DAMAGE.
    3434#
    35 # $P4: //depot/projects/openpam/misc/gendoc.pl#28 $
     35# $P4: //depot/projects/openpam/misc/gendoc.pl#29 $
    3636#
    3737
     
    157157
    158158    %xref = (
    159         "pam 3" => 1
     159        3 => { 'pam' => 1 },
    160160    );
    161161
     
    165165            push(@errors, $1);
    166166        }
    167         $xref{"pam_strerror 3"} = 1;
     167        ++$xref{3}->{'pam_strerror'};
    168168    }
    169169
    170170    $argnames = $args;
     171    # extract names of regular arguments
    171172    $argnames =~ s/\"[^\"]+\*?\b(\w+)\"/\"$1\"/g;
     173    # extract names of function pointer arguments
     174    $argnames =~ s/\"([\w\s\*]+)\(\*?(\w+)\)\([^\)]+\)\"/\"$2\"/g;
     175    # escape metacharacters (there shouldn't be any, but...)
    172176    $argnames =~ s/([\|\[\]\(\)\.\*\+\?])/\\$1/g;
     177    # separate argument names with |
    173178    $argnames =~ s/\" \"/|/g;
     179    # and surround with ()
    174180    $argnames =~ s/^\"(.*)\"$/($1)/;
     181    # $argnames is now a regexp that matches argument names
    175182    $inliteral = $inlist = 0;
    176183    foreach (split("\n", $source)) {
     
    198205            next;
    199206        }
    200         if (m/^>(\w+)(?:\s+(\d))?$/) {
    201             ++$xref{$2 ? "$1 $2" : "$1 3"};
     207        if (m/^>(\w+)(\s+\d)?$/) {
     208            my ($page, $sect) = ($1, $2 ? int($2) : 3);
     209            ++$xref{$sect}->{$page};
    202210            next;
    203211        }
     
    233241        }
    234242        s/\s*=$func\b\s*/\n.Nm\n/gs;
    235         s/\s*=$argnames\b\s*/\n.Va $1\n/gs;
     243        s/\s*=$argnames\b\s*/\n.Fa $1\n/gs;
    236244        s/\s*=(struct \w+(?: \*)?)\b\s*/\n.Vt $1\n/gs;
    237245        s/\s*:([a-z_]+)\b\s*/\n.Va $1\n/gs;
    238246        s/\s*;([a-z_]+)\b\s*/\n.Dv $1\n/gs;
    239247        while (s/\s*=([a-z_]+)\b\s*/\n.Xr $1 3\n/s) {
    240             ++$xref{"$1 3"};
     248            ++$xref{3}->{$1};
    241249        }
    242250        s/\s*\"(?=\w)/\n.Do\n/gs;
     
    334342}
    335343
     344sub genxref($) {
     345    my $xref = shift;           # References
     346
     347    my $mdoc = '';
     348    my @refs = ();
     349    foreach my $sect (sort(keys(%{$xref}))) {
     350        foreach my $page (sort(keys(%{$xref->{$sect}}))) {
     351            push(@refs, "$page $sect");
     352        }
     353    }
     354    while ($_ = shift(@refs)) {
     355        $mdoc .= ".Xr $_" .
     356            (@refs ? " ,\n" : "\n");
     357    }
     358    return $mdoc;
     359}
     360
    336361sub gendoc($) {
    337362    my $func = shift;           # Ref to function hash
     
    392417        }
    393418    }
    394     $mdoc .= ".Sh SEE ALSO\n";
    395     my @xref = sort(keys(%{$func->{'xref'}}));
    396     while (@xref) {
    397         $mdoc .= ".Xr " . shift(@xref) . (@xref ? " ,\n" : "\n");
    398     }
     419    $mdoc .= ".Sh SEE ALSO\n" . genxref($func->{'xref'});
    399420    $mdoc .= ".Sh STANDARDS\n";
    400421    if ($func->{'openpam'}) {
     
    416437.Fx
    417438Project by ThinkSec AS and Network Associates Laboratories, the
    418 Security Research Division of Network Associates, Inc.  under
     439Security Research Division of Network Associates, Inc.\& under
    419440DARPA/SPAWAR contract N66001-01-C-8035
    420441.Pq Dq CBOSS ,
     
    496517    while (<STDIN>) {
    497518        if (m/^\.Xr (\S+)\s*(\d)\s*$/) {
    498             $xref{$1} = $2;
     519            ++$xref{int($2)}->{$1};
    499520        }
    500521        print FILE $_;
     
    504525        print FILE ".Sh RETURN VALUES
    505526The following return codes are defined by
    506 .Aq Pa security/pam_constants.h :
     527.In security/pam_constants.h :
    507528.Bl -tag -width 18n
    508529";
     
    514535    print FILE ".Sh SEE ALSO
    515536";
    516     print FILE ".Xr openpam 3 ,\n"
    517         if ($page eq 'pam');
     537    if ($page eq 'pam') {
     538        ++$xref{3}->{'openpam'};
     539    }
    518540    foreach $func (keys(%FUNCTIONS)) {
    519         $xref{$func} = 3;
    520     }
    521     my @refs = sort(keys(%xref));
    522     while ($_ = shift(@refs)) {
    523         print FILE ".Xr $_ $xref{$_}";
    524         print FILE " ,"
    525             if (@refs);
    526         print FILE "\n";
    527     }
     541        ++$xref{3}->{$func};
     542    }
     543    print FILE genxref(\%xref);
    528544    print FILE ".Sh STANDARDS
    529545.Rs
     
    535551.Fx
    536552Project by ThinkSec AS and Network Associates Laboratories, the
    537 Security Research Division of Network Associates, Inc.  under
     553Security Research Division of Network Associates, Inc.\& under
    538554DARPA/SPAWAR contract N66001-01-C-8035
    539555.Pq Dq CBOSS ,
Note: See TracChangeset for help on using the changeset viewer.