summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2000-02-05 22:15:17 +0000
committerMarc Espie <espie@cvs.openbsd.org>2000-02-05 22:15:17 +0000
commit456fb07557d109ce9616d179ed46717eeaa06b50 (patch)
tree2f083fd63c201d6a90a01d5ff771b77a9eb17c10 /libexec
parent479a01bbe03f2bed82d0f50d2bb12844978a3f43 (diff)
Much better at handling formatted manpages.
- remove all boldface c^Hc -> c, - handle `multiple subjets' manpages correctly (e.g. perl), - warns about stuff that ought to be manpages, but isn't proper (ffs_softupdates and safe_finger are missing subject lines, BTW). So, all the perl documentation is finally grokked correctly. Todd's baby is missing quite a few manpages links...
Diffstat (limited to 'libexec')
-rw-r--r--libexec/makewhatis/makewhatis.pl88
1 files changed, 64 insertions, 24 deletions
diff --git a/libexec/makewhatis/makewhatis.pl b/libexec/makewhatis/makewhatis.pl
index 8791d2065fa..5b39c3d48a0 100644
--- a/libexec/makewhatis/makewhatis.pl
+++ b/libexec/makewhatis/makewhatis.pl
@@ -1,6 +1,7 @@
#!/usr/bin/perl -w
+# ex:ts=4 sw=4:
-# $OpenBSD: makewhatis.pl,v 1.1 2000/02/03 18:10:48 espie Exp $
+# $OpenBSD: makewhatis.pl,v 1.2 2000/02/05 22:15:16 espie Exp $
#
# Copyright (c) 2000 Marc Espie.
#
@@ -76,39 +77,78 @@ sub handle_unformated
close $cmd;
}
-# $line = handle_formated($file)
+sub add_subject
+{
+ my $lines = shift;
+ local $_ = shift;
+ my $section = shift;
+
+ if (m/-/) {
+ # some twits underline the command name
+ while (s/_\cH//g || s/(.)\cH\1/$1/g)
+ {}
+ s/([-+.\w\d,])\s+/$1 /g;
+ s/([a-z][A-z])-\s+/$1/g;
+ # some twits use: func -- description
+ if (m/^[^-+.\w\d]*(.*) -(?:-?)\s+(.*)$/) {
+ my ($func, $descr) = ($1, $2);
+ $func =~ s/,\s*$//;
+ push(@$lines, "$func ($section) - $descr");
+ return;
+ }
+ }
+ print STDERR "Weird subject line $_ in ", shift, "\n";
+}
+
+# $lines = handle_formated($file)
#
# handle a formatted manpage in $file
#
+# may return several subjects, perl(3p) do !
+#
sub handle_formated
{
my $file = shift;
+ my $filename = shift;
local $_;
my ($section, $subject);
+ my @lines=();
while (<$file>) {
+ next if /^$/;
chomp;
- last if m/^N\cHNA\cHAM\cHME\cHE/;
- if (m/\w[-+.\w\d]*\(([\/\-+.\w\d]+)\)/) {
+ # Remove boldface and underlining
+ while (s/_\cH//g || s/(.)\cH\1/$1/g)
+ {}
+ if (m/\w[-+.\w\d]*\(([-+.\w\d\/]+)\)/) {
$section = $1;
}
+ # Not all man pages are in english
+ if (m/^(?:NAME|NAMN)\s*$/) {
+ unless (defined $section) {
+ print STDERR "Can't find section in $filename\n";
+ $section='??';
+ }
+ while (<$file>) {
+ chomp;
+ # perl agregates several subjects in one manpage
+ if (m/^$/) {
+ add_subject(\@lines, $subject, $section, $filename)
+ if defined $subject;
+ $subject = undef;
+ } elsif (m/^\S/ || m/^\s+\*{3,}\s*$/) {
+ add_subject(\@lines, $subject, $section, $filename)
+ if defined $subject;
+ last;
+ } else {
+ $subject.=$_;
+ }
+ }
+ last;
+ }
}
- while (<$file>) {
- chomp;
- last if m/^\S/;
- # some twits underline the command name
- s/_\cH//g;
- $subject.=$_;
- }
- $_ = $subject;
- if (defined $_ and m/-/) {
- s/.\cH//g;
- s/([-+.,\w\d])\s+/$1 /g;
- s/([a-z][A-z])-\s+/$1/g;
- s/^[^-+.\w\d]*(.*) - (.*)$/$1 ($section) - $2/;
- return $_;
- } else {
- return undef;
- }
+
+ print STDERR "Can't parse $filename (not a manpage ?)\n" if @lines == 0;
+ return \@lines;
}
# $list = find_manpages($dir)
@@ -144,7 +184,7 @@ sub scan_manpages
$done=[];
for (@$list) {
- my ($file, $line);
+ my ($file, $subjects);
if (m/\.[1-9]$/) {
push(@todo, $_);
if (@todo > 5000) {
@@ -158,8 +198,8 @@ sub scan_manpages
$file = new IO::File $_ or die "$0: Can't read $_\n";
}
- $line = handle_formated($file);
- push @$done, $line if defined $line;
+ $subjects = handle_formated($file, $_);
+ push @$done, @$subjects;
}
if (@todo > 0) {
handle_unformated($done, \@todo);