source: openpam/trunk/misc/gendoc.pl @ 29

Last change on this file since 29 was 29, checked in by des, 13 years ago

libpam, not libfetch

File size: 4.9 KB
Line 
1#!/usr/bin/perl -w
2#-
3# Copyright (c) 2002 Networks Associates Technologies, Inc.
4# All rights reserved.
5#
6# This software was developed for the FreeBSD Project by ThinkSec AS and
7# NAI Labs, the Security Research Division of Network Associates, Inc.
8# under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
9# DARPA CHATS research program.
10#
11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions
13# are met:
14# 1. Redistributions of source code must retain the above copyright
15#    notice, this list of conditions and the following disclaimer.
16# 2. Redistributions in binary form must reproduce the above copyright
17#    notice, this list of conditions and the following disclaimer in the
18#    documentation and/or other materials provided with the distribution.
19# 3. The name of the author may not be used to endorse or promote
20#    products derived from this software without specific prior written
21#    permission.
22#
23# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33# SUCH DAMAGE.
34#
35# $Id$
36#
37
38use strict;
39use Fcntl;
40use POSIX qw(strftime);
41use vars qw($TODAY %FUNCTIONS);
42
43sub gendoc($) {
44    my $fn = shift;
45
46    local *FILE;
47    my $source;
48    my $mdoc;
49    my $func;
50    my $descr;
51    my $type;
52    my $args;
53    my $name;
54
55    if ($fn !~ m,\.c$,) {
56        warn("$fn: not C source, ignoring\n");
57        return;
58    }
59   
60    sysopen(FILE, $fn, O_RDONLY)
61        or die("$fn: open(): $!\n");
62    $source = join('', <FILE>);
63    close(FILE);
64
65    if ($source =~ m,^(/\*-\n.*?)\s*\*/,s) {
66        $mdoc = $1;
67        $mdoc =~ s,^.\*,.\\\",gm;
68        $mdoc .= "\n.\\\"\n";
69    } else {
70        $mdoc = ".\\\" \$" . "Id" . "\$\n";
71    }
72    $func = $fn;
73    $func =~ s,^(?:.*/)?([^/]+)\.c$,$1,;
74    if ($source !~ m,\n \* ([\S ]+)\n \*/\n\n([\S ]+)\n$func\((.*?)\)\n\{,s) {
75        warn("$fn: can't find $func\n");
76        return;
77    }
78    ($descr, $type, $args) = ($1, $2, $3);
79    $descr =~ s,^([A-Z][a-z]),lc($1),e;
80    $descr =~ s,[\.\s]*$,,;
81    while ($args =~ s/^((?:[^\(]|\([^\)]*\))*),\s*/$1\" \"/g) {
82        # nothing
83    }
84    $args =~ s/,\s+/, /gs;
85    $args = "\"$args\"";
86
87    $FUNCTIONS{$func} = [ $type, $args ];
88   
89    $mdoc .= ".Dd $TODAY
90.Dt " . uc($func) . " 3
91.Os
92.Sh NAME
93.Nm $func
94.Nd $descr
95.Sh LIBRARY
96.Lb libpam
97.Sh SYNOPSIS
98.In security/pam_appl.h
99.Ft $type
100.Fn $func $args
101.Sh DESCRIPTION
102The
103.Nm
104function is not yet documented.
105.Sh RETURN VALUES
106The
107.Fn
108function returns one of the following values:
109.Bl -tag -width PAM_AUTHTOK_DISABLE_AGING
110.El
111.Sh SEE ALSO
112.Xr pam_strerror 3 ,
113.Xr pam 3
114.Sh STANDARDS
115.Rs
116.%T \"X/Open Single Sign-On Service (XSSO) - Pluggable Authentication Modules\"
117.%D \"June 1997\"
118.Re
119.AUTHORS
120The
121.Nm
122function and this manual page were developed for the FreeBSD Project
123by ThinkSec AS and NAI Labs, the Security Research Division of Network
124Associates, Inc.  under DARPA/SPAWAR contract N66001-01-C-8035
125.Pq .Dq CBOSS ,
126as part of the DARPA CHATS research program.
127";
128
129     $fn =~ s,\.c$,.3,;
130     sysopen(FILE, $fn, O_RDWR|O_CREAT|O_TRUNC)
131        or die("$fn: open(): $!\n");
132     print(FILE $mdoc);
133     close(FILE);
134}
135
136sub gensummary() {
137
138    print ".Dd $TODAY
139.Dt PAM 3
140.Os
141.Sh NAME
142";
143    my @funcs = sort(keys(%FUNCTIONS));
144    while (@funcs) {
145        print ".Nm " . shift(@funcs) . (@funcs ? " ,\n" : "\n");
146    }
147    print ".Nd Pluggable Authentication Modules
148.Sh LIBRARY
149.Lb libpam
150.Sh SYNOPSIS
151.In security/pam_appl.h
152";
153    foreach my $func (sort(keys(%FUNCTIONS))) {
154        print ".Ft $FUNCTIONS{$func}->[0]\n";
155        print ".Fn $func $FUNCTIONS{$func}->[1]\n";
156    }
157    print ".Sh DESCRIPTION
158Foo
159.Sh RETURN VALUES
160.Sh SEE ALSO
161";
162    foreach my $func (sort(keys(%FUNCTIONS))) {
163        print ".Xr $func 4 ,\n";
164    }
165    print ".Xr pam.conf 5
166.Sh STANDARDS
167.Rs
168.%T \"X/Open Single Sign-On Service (XSSO) - Pluggable Authentication Modules\"
169.%D \"June 1997\"
170.Re
171.AUTHORS
172The OpenPAM library and this manual page were developed for the
173FreeBSD Project by ThinkSec AS and NAI Labs, the Security Research
174Division of Network Associates, Inc.  under DARPA/SPAWAR contract
175N66001-01-C-8035
176.Pq .Dq CBOSS ,
177as part of the DARPA CHATS research program.
178"
179}
180
181MAIN:{
182    $TODAY = strftime("%B %e, %Y", localtime(time()));
183    $TODAY =~ s,\s+, ,g;
184    foreach my $fn (@ARGV) {
185        gendoc($fn);
186    }
187    gensummary();
188}
Note: See TracBrowser for help on using the repository browser.