diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2011-02-22 00:23:15 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2011-02-22 00:23:15 +0000 |
commit | 5781d736a118bdade041b009e089fff6f2b5e627 (patch) | |
tree | 0ce1bcdfd2a42d143816993ec0d1fc38faa0b4ee /libexec/makewhatis/OpenBSD | |
parent | 9427ae2c5de561e555c9ff82a44d384ec937ecbf (diff) |
shut up unless -v, and a few minor enhancements.
okay miod@
Diffstat (limited to 'libexec/makewhatis/OpenBSD')
-rw-r--r-- | libexec/makewhatis/OpenBSD/Makewhatis.pm | 27 | ||||
-rw-r--r-- | libexec/makewhatis/OpenBSD/Makewhatis/Formated.pm | 28 | ||||
-rw-r--r-- | libexec/makewhatis/OpenBSD/Makewhatis/Subject.pm | 46 | ||||
-rw-r--r-- | libexec/makewhatis/OpenBSD/Makewhatis/Unformated.pm | 36 |
4 files changed, 94 insertions, 43 deletions
diff --git a/libexec/makewhatis/OpenBSD/Makewhatis.pm b/libexec/makewhatis/OpenBSD/Makewhatis.pm index 157fd1e90d1..de9467716a6 100644 --- a/libexec/makewhatis/OpenBSD/Makewhatis.pm +++ b/libexec/makewhatis/OpenBSD/Makewhatis.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Makewhatis.pm,v 1.9 2010/10/25 17:42:29 espie Exp $ +# $OpenBSD: Makewhatis.pm,v 1.10 2011/02/22 00:23:14 espie Exp $ # Copyright (c) 2000-2004 Marc Espie <espie@openbsd.org> # # Permission to use, copy, modify, and distribute this software for any @@ -63,6 +63,11 @@ sub picky return shift->{picky}; } +sub verbose +{ + return shift->{verbose}; +} + sub testmode { return shift->{testmode}; @@ -89,10 +94,13 @@ sub scan_manpages my $_; my $done=[]; - for (@$list) { + require OpenBSD::Makewhatis::Subject; + my $h = OpenBSD::Makewhatis::SubjectHandler->new($p); + + for my $_ (@$list) { my ($file, $subjects); if (m/\.(?:Z|gz)$/) { - unless (open $file, '-|', "gzip -fdc $_") { + unless (open $file, '-|', "gzip", "-fdc", $_) { $p->errsay("#1: can't decompress #2: #3", $0, $_, $!); next; } @@ -107,23 +115,24 @@ sub scan_manpages next; } } + $h->set_filename($_); if (m/\.(?:[1-9ln][^.]*|tbl)$/) { require OpenBSD::Makewhatis::Unformated; - $subjects = OpenBSD::Makewhatis::Unformated::handle($file, $_, $p); + $subjects = OpenBSD::Makewhatis::Unformated::handle($file, $h); } elsif (m/\.0$/) { require OpenBSD::Makewhatis::Formated; - $subjects = OpenBSD::Makewhatis::Formated::handle($file, $_, $p); + $subjects = OpenBSD::Makewhatis::Formated::handle($file, $h); # in test mode, we try harder } elsif ($p->testmode) { require OpenBSD::Makewhatis::Unformated; - $subjects = OpenBSD::Makewhatis::Unformated::handle($file, $_, $p); + $subjects = OpenBSD::Makewhatis::Unformated::handle($file, $h); if (@$subjects == 0) { require OpenBSD::Makewhatis::Formated; - $subjects = OpenBSD::Makewhatis::Formated::handle($file, $_, $p); + $subjects = OpenBSD::Makewhatis::Formated::handle($file, $h); } } else { $p->errsay("Can't find type of #1", $_); @@ -240,6 +249,10 @@ sub makewhatis return; } + if (defined $opts->{'v'}) { + $p->{verbose} = 1; + } + if (defined $opts->{'d'}) { merge($opts->{'d'}, $args, $p); return; diff --git a/libexec/makewhatis/OpenBSD/Makewhatis/Formated.pm b/libexec/makewhatis/OpenBSD/Makewhatis/Formated.pm index 8a35adb59c2..820391d6910 100644 --- a/libexec/makewhatis/OpenBSD/Makewhatis/Formated.pm +++ b/libexec/makewhatis/OpenBSD/Makewhatis/Formated.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Formated.pm,v 1.5 2010/07/09 08:12:49 espie Exp $ +# $OpenBSD: Formated.pm,v 1.6 2011/02/22 00:23:14 espie Exp $ # Copyright (c) 2000-2004 Marc Espie <espie@openbsd.org> # # Permission to use, copy, modify, and distribute this software for any @@ -18,12 +18,12 @@ use strict; use warnings; package OpenBSD::Makewhatis::Formated; -# add_formated_subject($subjects, $_, $section, $filename, $p): +# add_formated_subject($subjects, $_, $section, $h): # add subject $_ to the list of current $subjects, in section $section. # sub add_formated_subject { - my ($subjects, $line, $section, $filename, $p) = @_; + my ($subjects, $line, $section, $h) = @_; my $_ = $line; if (m/-/) { @@ -43,7 +43,7 @@ sub add_formated_subject } } - $p->errsay("Weird subject line in #1:\n#2", $filename, $_) if $p->picky; + $h->weird_subject($_) if $h->p->picky; # try to find subject in line anyway if (m/^\s*(.*\S)(?:\s{3,}|\(\)\s+)(.*?)\s*$/) { @@ -55,10 +55,10 @@ sub add_formated_subject return; } - $p->errsay("Weird subject line in #1:\n#2", $filename, $_) unless $p->picky; + $h->weird_subject($_) unless $h->p->picky; } -# $lines = handle($file, $filename, $p) +# $lines = handle($file, $h) # # handle a formatted manpage in $file # @@ -66,7 +66,7 @@ sub add_formated_subject # sub handle { - my ($file, $filename, $p) = @_; + my ($file, $h) = @_; my $_; my ($section, $subject); my @lines=(); @@ -76,7 +76,7 @@ sub handle if (m/^$/) { # perl aggregates several subjects in one manpage # so we don't stop after we've got one subject - add_formated_subject(\@lines, $subject, $section, $filename, $p) + add_formated_subject(\@lines, $subject, $section, $h) if defined $subject; $subject = undef; next; @@ -96,15 +96,15 @@ sub handle } # Not all man pages are in english # weird hex is `Namae' in japanese - if (m/^(?:NAME|NAMES|NAMN|NOMBRE|NOME|Name|\xbe|\xcc\xbe\xbe\xce|\xcc\xbe\xc1\xb0)\s*$/) { + if (m/^(?:NAME|NAMES|NAZEV|NAMN|NOMBRE|NOME|Name|\xbe|\xcc\xbe\xbe\xce|\xcc\xbe\xc1\xb0)\s*$/) { unless (defined $section) { # try to retrieve section from filename - if ($filename =~ m/(?:cat|man)([\dln])\//) { + if ($h->filename =~ m/(?:cat|man)([\dln])\//) { $section = $1; - $p->errsay("Can't find section in #1, deducting #2 from context", $filename, $section) if $p->picky; + $h->errsay("Can't find section in #2, deducting #1 from context", $section) if $h->p->picky; } else { $section='??'; - $p->errsay("Can't find section in #1", $filename); + $h->errsay("Can't find section in #1"); } } $foundname = 1; @@ -112,7 +112,7 @@ sub handle } if ($foundname) { if (m/^\S/ || m/^\s+\*{3,}\s*$/) { - add_formated_subject(\@lines, $subject, $section, $filename, $p) + add_formated_subject(\@lines, $subject, $section, $h) if defined $subject; last; } else { @@ -132,7 +132,7 @@ sub handle } } - $p->errsay("Can't parse #1 (not a manpage ?)", $filename) if @lines == 0; + $h->cant_find_subject if @lines == 0; return \@lines; } diff --git a/libexec/makewhatis/OpenBSD/Makewhatis/Subject.pm b/libexec/makewhatis/OpenBSD/Makewhatis/Subject.pm index a88023e70fd..d349317d47c 100644 --- a/libexec/makewhatis/OpenBSD/Makewhatis/Subject.pm +++ b/libexec/makewhatis/OpenBSD/Makewhatis/Subject.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Subject.pm,v 1.1 2011/01/26 15:10:59 espie Exp $ +# $OpenBSD: Subject.pm,v 1.2 2011/02/22 00:23:14 espie Exp $ # Copyright (c) 2010 Marc Espie <espie@openbsd.org> # # Permission to use, copy, modify, and distribute this software for any @@ -21,14 +21,54 @@ package OpenBSD::Makewhatis::SubjectHandler; sub new { - my $class = shift; - bless {}, $class; + my ($class, $p) = @_; + return bless { p => $p}, $class; } sub add { } +sub p +{ + my $h = shift; + return $h->{p}; +} + +sub set_filename +{ + my ($h, $name) = @_; + $h->{current} = $name; + $h->{has_subjects} = 0; +} + +sub filename +{ + my $h = shift; + return $h->{current}; +} + +sub errsay +{ + my $h = shift; + if ($h->p->verbose) { + push(@_, $h->filename); + $h->p->errsay(@_); + } +} + +sub weird_subject +{ + my ($h, $line) = @_; + $h->errsay("Weird subject line in #2:\n#1", $line) ; +} + +sub cant_find_subject +{ + my $h = shift; + $h->errsay("No subject found in #1"); +} + package OpenBSD::MakeWhatis::Subject; sub new diff --git a/libexec/makewhatis/OpenBSD/Makewhatis/Unformated.pm b/libexec/makewhatis/OpenBSD/Makewhatis/Unformated.pm index dcdc5754d2a..03460681527 100644 --- a/libexec/makewhatis/OpenBSD/Makewhatis/Unformated.pm +++ b/libexec/makewhatis/OpenBSD/Makewhatis/Unformated.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Unformated.pm,v 1.6 2010/07/13 15:39:03 espie Exp $ +# $OpenBSD: Unformated.pm,v 1.7 2011/02/22 00:23:14 espie Exp $ # Copyright (c) 2000-2004 Marc Espie <espie@openbsd.org> # # Permission to use, copy, modify, and distribute this software for any @@ -18,20 +18,20 @@ use strict; use warnings; package OpenBSD::Makewhatis::Unformated; -# add_unformated_subject($lines, $toadd, $section, $filename, $toexpand, $p) : +# add_unformated_subject($lines, $toadd, $section, $p) : # # build subject from list of $toadd lines, and add it to the list # of current subjects as section $section # sub add_unformated_subject { - my ($subjects, $toadd, $section, $filename, $toexpand, $p) = @_; + my ($subjects, $toadd, $section, $toexpand, $h) = @_; my $exp = sub { if (defined $toexpand->{$_[0]}) { return $toexpand->{$_[0]}; } else { - $p->errsay("#1: can't expand #2", $filename, $_[0]); + $h->errsay("#2: can't expand #1", $_[0]); return ""; } }; @@ -64,7 +64,7 @@ sub add_unformated_subject {} unless (s/\s+\\-\s+/ ($section) - / || s/\s*\\\-/ ($section) -/ || s/\s-\s/ ($section) - /) { - $p->errsay("Weird subject line in #1:\n#2", $filename, $_) if $p->picky; + $h->weird_subject($_) if $h->p->picky; # Try guessing where the separation falls... s/\s+\:\s+/ ($section) - / || s/\S+\s+/$& ($section) - / || s/\s*$/ ($section) - (empty subject)/; } @@ -81,14 +81,13 @@ sub add_unformated_subject s/\s+/ /g; # some damage control if (m/^\Q($section) - \E/) { - $p->errsay("Rejecting non-subject line from #1:\n#2", $filename, $_) - if $p->picky; + $h->weird_subject($_) if $h->p->picky; return; } push(@$subjects, $_); } -# $lines = handle($file, $filename, $p) +# $lines = handle($file, $h) # # handle an unformated manpage in $file # @@ -96,7 +95,7 @@ sub add_unformated_subject # sub handle { - my ($f, $filename, $p) = @_; + my ($f, $h) = @_; my @lines = (); my %toexpand = (Tm => '(tm)'); my $so_found = 0; @@ -110,7 +109,7 @@ sub handle my $nd_seen = 0; my $_; # retrieve basename of file - my ($name, $section) = $filename =~ m|(?:.*/)?(.*)\.([\w\d]+)|; + my ($name, $section) = $h->filename =~ m|(?:.*/)?(.*)\.([\w\d]+)|; # scan until macro while (<$f>) { next unless m/^\./ || $found_old || $found_new; @@ -155,8 +154,7 @@ sub handle # several subjects in one manpage if (m/^\.\s*(?:PP|Pp|br|PD|LP|sp)/) { add_unformated_subject(\@lines, \@subject, - $section, $filename, \%toexpand, $p) - if @subject != 0; + $section, \%toexpand, $h) if @subject != 0; @subject = (); next; } @@ -169,8 +167,8 @@ sub handle chomp; s/\.\s*(?:B|I|IR|SM|BR)\s+//; if (m/^\.\s*(\S\S)/) { - $p->errsay("#1: not grokking #2", $filename, $_) - if $p->picky; + $h->errsay("#2: not grokking #1", $_) + if $h->p->picky; next; } push(@subject, $_) unless m/^\s*$/; @@ -190,7 +188,7 @@ sub handle if ($macro eq 'Nd') { if (@keep != 0) { add_unformated_subject(\@lines, \@keep, - $section, $filename, \%toexpand, $p); + $section, \%toexpand, $h); @keep = (); } push(@subject, "\\-"); @@ -206,16 +204,16 @@ sub handle } } if ($found_th && !$found_old) { - $p->errsay("Couldn't find subject in old manpage #1", $filename); + $h->cant_find_subject; } if ($found_dt && !$found_new) { - $p->errsay("Couldn't find subject in new manpage #1", $filename); + $h->cant_find_subject; } unshift(@subject, @keep) if @keep != 0; add_unformated_subject(\@lines, \@subject, $section, - $filename, \%toexpand, $p) if @subject != 0; + \%toexpand, $h) if @subject != 0; if (!$so_found && !$found_old && !$found_new) { - $p->errsay("Unknown manpage type #1", $filename); + $h->errsay("Unknown manpage type #1"); } return \@lines; } |