summaryrefslogtreecommitdiffstats
path: root/misc/gendoc.pl
diff options
context:
space:
mode:
Diffstat (limited to 'misc/gendoc.pl')
-rw-r--r--misc/gendoc.pl100
1 files changed, 72 insertions, 28 deletions
diff --git a/misc/gendoc.pl b/misc/gendoc.pl
index 5c201cf..7b76672 100644
--- a/misc/gendoc.pl
+++ b/misc/gendoc.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
#-
# Copyright (c) 2002-2003 Networks Associates Technology, Inc.
-# Copyright (c) 2004-2007 Dag-Erling Smørgrav
+# Copyright (c) 2004-2011 Dag-Erling Smørgrav
# All rights reserved.
#
# This software was developed for the FreeBSD Project by ThinkSec AS and
@@ -33,7 +33,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $Id: gendoc.pl 408 2007-12-21 11:36:24Z des $
+# $Id: gendoc.pl 465 2011-11-02 20:34:26Z des $
#
use strict;
@@ -41,11 +41,11 @@ use locale;
use Fcntl;
use Getopt::Std;
use POSIX qw(locale_h strftime);
-use vars qw($COPYRIGHT $TODAY %FUNCTIONS %PAMERR);
+use vars qw($COPYRIGHT %AUTHORS $TODAY %FUNCTIONS %PAMERR);
$COPYRIGHT = ".\\\"-
.\\\" Copyright (c) 2001-2003 Networks Associates Technology, Inc.
-.\\\" Copyright (c) 2004-2007 Dag-Erling Smørgrav
+.\\\" Copyright (c) 2004-2011 Dag-Erling Smørgrav
.\\\" All rights reserved.
.\\\"
.\\\" This software was developed for the FreeBSD Project by ThinkSec AS and
@@ -77,9 +77,18 @@ $COPYRIGHT = ".\\\"-
.\\\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\\\" SUCH DAMAGE.
.\\\"
-.\\\" \$" . "P4" . "\$
+.\\\" \$" . "Id" . "\$
.\\\"";
+%AUTHORS = (
+ THINKSEC => "ThinkSec AS and Network Associates Laboratories, the
+Security Research Division of Network Associates, Inc.\\& under
+DARPA/SPAWAR contract N66001-01-C-8035
+.Pq Dq CBOSS ,
+as part of the DARPA CHATS research program.",
+ DES => ".An Dag-Erling Sm\\(/orgrav Aq des\@FreeBSD.org .",
+);
+
%PAMERR = (
PAM_SUCCESS => "Success",
PAM_OPEN_ERR => "Failed to load module",
@@ -125,16 +134,18 @@ sub parse_source($) {
my $argnames;
my $man;
my $inlist;
+ my $intaglist;
my $inliteral;
my %xref;
my @errors;
+ my $author;
if ($fn !~ m,\.c$,) {
warn("$fn: not C source, ignoring\n");
return undef;
}
- sysopen(FILE, $fn, O_RDONLY)
+ open(FILE, "<", "$fn")
or die("$fn: open(): $!\n");
$source = join('', <FILE>);
close(FILE);
@@ -142,6 +153,11 @@ sub parse_source($) {
return undef
if ($source =~ m/^ \* NOPARSE\s*$/m);
+ $author = 'THINKSEC';
+ if ($source =~ s/^ \* AUTHOR\s+(.*?)\s*$//m) {
+ $author = $1;
+ }
+
$func = $fn;
$func =~ s,^(?:.*/)?([^/]+)\.c$,$1,;
if ($source !~ m,\n \* ([\S ]+)\n \*/\n\n([\S ]+)\n$func\((.*?)\)\n\{,s) {
@@ -181,7 +197,7 @@ sub parse_source($) {
# and surround with ()
$argnames =~ s/^\"(.*)\"$/($1)/;
# $argnames is now a regexp that matches argument names
- $inliteral = $inlist = 0;
+ $inliteral = $inlist = $intaglist = 0;
foreach (split("\n", $source)) {
s/\s*$//;
if (!defined($man)) {
@@ -194,12 +210,13 @@ sub parse_source($) {
s/^ \* ?//;
s/\\(.)/$1/gs;
if (m/^$/) {
+ # paragraph separator
if ($man ne "" && $man !~ m/\.Pp\n$/s) {
if ($inliteral) {
$man .= "\0\n";
- } elsif ($inlist) {
+ } elsif ($inlist || $intaglist) {
$man .= ".El\n.Pp\n";
- $inlist = 0;
+ $inlist = $intaglist = 0;
} else {
$man .= ".Pp\n";
}
@@ -207,35 +224,63 @@ sub parse_source($) {
next;
}
if (m/^>(\w+)(\s+\d)?$/) {
+ # "see also" cross-reference
my ($page, $sect) = ($1, $2 ? int($2) : 3);
++$xref{$sect}->{$page};
next;
}
- if (s/^\s+(=?\w+):\s*/.It $1/) {
+ if (s/^\s+-\s+//) {
+ # item in bullet list
if ($inliteral) {
$man .= ".Ed\n";
$inliteral = 0;
}
+ if ($intaglist) {
+ $man .= ".El\n.Pp\n";
+ $intaglist = 0;
+ }
if (!$inlist) {
$man =~ s/\.Pp\n$//s;
- $man .= ".Bl -tag -width 18n\n";
+ $man .= ".Bl -bullet\n";
$inlist = 1;
}
+ $man .= ".It\n";
+ # fall through
+ } elsif (s/^\s+(\S+):\s*/.It $1/) {
+ # item in tag list
+ if ($inliteral) {
+ $man .= ".Ed\n";
+ $inliteral = 0;
+ }
+ if ($inlist) {
+ $man .= ".El\n.Pp\n";
+ $inlist = 0;
+ }
+ if (!$intaglist) {
+ $man =~ s/\.Pp\n$//s;
+ $man .= ".Bl -tag -width 18n\n";
+ $intaglist = 1;
+ }
s/^\.It =([A-Z][A-Z_]+)$/.It Dv $1/gs;
$man .= "$_\n";
next;
- } elsif ($inlist && m/^\S/) {
+ } elsif (($inlist || $intaglist) && m/^\S/) {
+ # regular text after list
$man .= ".El\n.Pp\n";
- $inlist = 0;
+ $inlist = $intaglist = 0;
} elsif ($inliteral && m/^\S/) {
+ # regular text after literal section
$man .= ".Ed\n";
$inliteral = 0;
} elsif ($inliteral) {
+ # additional text within literal section
$man .= "$_\n";
next;
- } elsif ($inlist) {
+ } elsif ($inlist || $intaglist) {
+ # additional text within list
s/^\s+//;
} elsif (m/^\s+/) {
+ # new literal section
$man .= ".Bd -literal\n";
$inliteral = 1;
$man .= "$_\n";
@@ -257,12 +302,15 @@ sub parse_source($) {
$man .= "$_\n";
}
if (defined($man)) {
- if ($inlist) {
+ if ($inlist || $intaglist) {
$man .= ".El\n";
+ $inlist = $intaglist = 0;
}
if ($inliteral) {
$man .= ".Ed\n";
+ $inliteral = 0;
}
+ $man =~ s/\%/\\&\%/gs;
$man =~ s/(\n\.[A-Z][a-z] [\w ]+)\n([\.,:;-]\S*)\s*/$1 $2\n/gs;
$man =~ s/\s*$/\n/gm;
$man =~ s/\n+/\n/gs;
@@ -282,6 +330,7 @@ sub parse_source($) {
'man' => $man,
'xref' => \%xref,
'errors' => \@errors,
+ 'author' => $author,
};
if ($source =~ m/^ \* NODOC\s*$/m) {
$FUNCTIONS{$func}->{'nodoc'} = 1;
@@ -445,15 +494,9 @@ The
.Nm
function and this manual page were developed for the
.Fx
-Project by ThinkSec AS and Network Associates Laboratories, the
-Security Research Division of Network Associates, Inc.\\& under
-DARPA/SPAWAR contract N66001-01-C-8035
-.Pq Dq CBOSS ,
-as part of the DARPA CHATS research program.
-";
-
+Project by\n" . $AUTHORS{$func->{'author'} // 'THINKSEC_DARPA'} . "\n";
$fn = "$func->{'name'}.3";
- if (sysopen(FILE, $fn, O_RDWR|O_CREAT|O_TRUNC)) {
+ if (open(FILE, ">", $fn)) {
print(FILE $mdoc);
close(FILE);
} else {
@@ -467,7 +510,7 @@ sub readproto($) {
local *FILE;
my %func;
- sysopen(FILE, $fn, O_RDONLY)
+ open(FILE, "<", "$fn")
or die("$fn: open(): $!\n");
while (<FILE>) {
if (m/^\.Nm ((?:open)?pam_.*?)\s*$/) {
@@ -494,10 +537,11 @@ sub gensummary($) {
my $func;
my %xref;
- sysopen(FILE, "$page.3", O_RDWR|O_CREAT|O_TRUNC)
+ open(FILE, ">", "$page.3")
or die("$page.3: $!\n");
- $upage = uc($page);
+ $page =~ m/(\w+)$/;
+ $upage = uc($1);
print FILE "$COPYRIGHT
.Dd $TODAY
.Dt $upage 3
@@ -570,7 +614,7 @@ as part of the DARPA CHATS research program.
sub usage() {
- print(STDERR "usage: gendoc [-s] source [...]\n");
+ print(STDERR "usage: gendoc [-op] source [...]\n");
exit(1);
}
@@ -579,7 +623,7 @@ MAIN:{
usage()
unless (@ARGV && getopts("op", \%opts));
- setlocale(LC_ALL, "en_US.ISO8859-1");
+ setlocale(LC_ALL, "en_US.UTF-8");
$TODAY = strftime("%B %e, %Y", localtime(time()));
$TODAY =~ s,\s+, ,g;
if ($opts{'o'} || $opts{'p'}) {
OpenPOWER on IntegriCloud