From 3bb9b4fe56a9f1e3769ef40d11a156ab8581f823 Mon Sep 17 00:00:00 2001 From: schwarze Date: Mon, 22 Aug 2016 19:41:18 +0000 Subject: [PATCH] This code served us well for many years, but we are unlikely to reactivate it; espie@ agrees. The new code is in /usr/src/usr.bin/mandoc/mandocdb.c. --- libexec/makewhatis/Makefile | 29 -- libexec/makewhatis/OpenBSD/Makewhatis.pm | 293 ------------------ .../makewhatis/OpenBSD/Makewhatis/Check.pm | 83 ----- libexec/makewhatis/OpenBSD/Makewhatis/Find.pm | 73 ----- .../makewhatis/OpenBSD/Makewhatis/Formated.pm | 133 -------- .../makewhatis/OpenBSD/Makewhatis/Subject.pm | 99 ------ .../OpenBSD/Makewhatis/Unformated.pm | 220 ------------- .../makewhatis/OpenBSD/Makewhatis/Whatis.pm | 66 ---- libexec/makewhatis/makewhatis | 37 --- libexec/makewhatis/makewhatis.8 | 170 ---------- 10 files changed, 1203 deletions(-) delete mode 100644 libexec/makewhatis/Makefile delete mode 100644 libexec/makewhatis/OpenBSD/Makewhatis.pm delete mode 100644 libexec/makewhatis/OpenBSD/Makewhatis/Check.pm delete mode 100644 libexec/makewhatis/OpenBSD/Makewhatis/Find.pm delete mode 100644 libexec/makewhatis/OpenBSD/Makewhatis/Formated.pm delete mode 100644 libexec/makewhatis/OpenBSD/Makewhatis/Subject.pm delete mode 100644 libexec/makewhatis/OpenBSD/Makewhatis/Unformated.pm delete mode 100644 libexec/makewhatis/OpenBSD/Makewhatis/Whatis.pm delete mode 100644 libexec/makewhatis/makewhatis delete mode 100644 libexec/makewhatis/makewhatis.8 diff --git a/libexec/makewhatis/Makefile b/libexec/makewhatis/Makefile deleted file mode 100644 index be9b992bccf..00000000000 --- a/libexec/makewhatis/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# $OpenBSD: Makefile,v 1.10 2013/01/29 11:08:55 espie Exp $ - -MAN=makewhatis.8 -NOPROG= -PACKAGES= \ - OpenBSD/Makewhatis.pm \ - OpenBSD/Makewhatis/Check.pm \ - OpenBSD/Makewhatis/Find.pm \ - OpenBSD/Makewhatis/Formated.pm \ - OpenBSD/Makewhatis/Subject.pm \ - OpenBSD/Makewhatis/Unformated.pm \ - OpenBSD/Makewhatis/Whatis.pm - -SCRIPTS= \ - makewhatis - -LIBBASE=/usr/libdata/perl5 - -realinstall: -.for i in ${PACKAGES} - ${INSTALL} -d -o ${LIBOWN} -g ${LIBGRP} -m ${DIRMODE} \ - ${DESTDIR}${LIBBASE}/${i:H} - ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ - ${.CURDIR}/$i ${DESTDIR}${LIBBASE}/$i -.endfor - ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ - ${.CURDIR}/makewhatis ${DESTDIR}${BINDIR}/makewhatis - -.include diff --git a/libexec/makewhatis/OpenBSD/Makewhatis.pm b/libexec/makewhatis/OpenBSD/Makewhatis.pm deleted file mode 100644 index 82ed463f3c1..00000000000 --- a/libexec/makewhatis/OpenBSD/Makewhatis.pm +++ /dev/null @@ -1,293 +0,0 @@ -# ex:ts=8 sw=4: -# $OpenBSD: Makewhatis.pm,v 1.14 2014/03/21 10:59:31 espie Exp $ -# Copyright (c) 2000-2004 Marc Espie -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -use strict; -use warnings; - -# used to print everything. People using makewhatis internally can -# override this - -package OpenBSD::Makewhatis::Printer; -sub new -{ - my $class = shift; - return bless {}, $class; -} - -sub print -{ - my $self = shift; - print $self->f(@_); -} - -sub errsay -{ - my $self = shift; - print STDERR $self->f(@_), "\n"; -} - -sub fatal -{ - my $self = shift; - die $self->f(@_); -} - -sub f -{ - my $self = shift; - if (@_ == 0) { - return ''; - } - my ($fmt, @l) = @_; - # make it so that #0 is # - unshift(@l, '#'); - $fmt =~ s/\#(\d+)/$l[$1]/ge; - return $fmt; -} - -sub picky -{ - return shift->{picky}; -} - -sub verbose -{ - return shift->{verbose}; -} -sub testmode -{ - return shift->{testmode}; -} - -sub check_dir -{ - my ($self, $dir) = @_; - unless (-d $dir) { - $self->fatal("#1: #2 is not a directory", $0, $dir); - } -} - -package OpenBSD::Makewhatis; - - -# $subjects = scan_manpages(\@list, $p) -# -# scan a set of manpages, return list of subjects -# -sub scan_manpages -{ - my ($list, $p) = @_; - - require OpenBSD::Makewhatis::Subject; - my $h = OpenBSD::Makewhatis::SubjectHandler->new($p); - - for my $filename (@$list) { - my $file; - if ($filename =~ m/\.(?:Z|gz)$/) { - unless (open $file, '-|', "gzip", "-fdc", $filename) { - $p->errsay("#1: can't decompress #2: #3", - $0, $filename, $!); - next; - } - $filename = $`; - } else { - if (-z $filename) { - $p->errsay("Empty file #1", $filename); - next; - } - unless (open $file, '<', $filename) { - $p->errsay("#1: can't read #2: #3", $0, - $filename, $!); - next; - } - } - $h->set_filename($filename); - if ($filename =~ m/\.(?:[1-9ln][^.]*|tbl)$/) { - require OpenBSD::Makewhatis::Unformated; - - OpenBSD::Makewhatis::Unformated::handle($file, $h); - } elsif ($filename =~ m/\.0$/) { - require OpenBSD::Makewhatis::Formated; - - OpenBSD::Makewhatis::Formated::handle($file, $h); - # in test mode, we try harder - } elsif ($p->testmode) { - require OpenBSD::Makewhatis::Unformated; - - OpenBSD::Makewhatis::Unformated::handle($file, $h); - if ($h->no_subjects) { - require OpenBSD::Makewhatis::Formated; - - OpenBSD::Makewhatis::Formated::handle($file, - $h); - } - } else { - $p->errsay("Can't find type of #1", $filename); - next; - } - } - if ($p->picky) { - require OpenBSD::Makewhatis::Check; - - while (my ($s, $f) = each %{$h->subject_hash}) { - OpenBSD::Makewhatis::Check::verify_subject($s, - $f, $p); - } - } - my @done = $h->subjects; - return \@done; -} - -# build_index($dir, $p) -# -# build index for $dir -# -sub build_index -{ - require OpenBSD::Makewhatis::Find; - require OpenBSD::Makewhatis::Whatis; - - my ($dir, $p) = @_; - my $list = OpenBSD::Makewhatis::Find::find_manpages($dir); - my $subjects = scan_manpages($list, $p); - OpenBSD::Makewhatis::Whatis::write($subjects, $dir, $p); -} - -# merge($dir, \@pages, $p) -# -# merge set of pages into directory index -# -sub merge -{ - require OpenBSD::Makewhatis::Whatis; - - my ($mandir, $args, $p) = @_; - $p //= OpenBSD::Makewhatis::Printer->new; - $p->check_dir($mandir); - my $whatis = "$mandir/whatis.db"; - my $subjects = scan_manpages($args, $p); - if (open(my $old, '<', $whatis)) { - while (my $l = <$old>) { - chomp $l; - push(@$subjects, $l); - } - close($old); - } - OpenBSD::Makewhatis::Whatis::write($subjects, $mandir, $p); -} - -# open_whatis(dir, file, $p) -# -# open existing whatis database, or recreate it in case of problem -# -sub open_whatis -{ - my ($mandir, $whatis, $p) = @_; - my $fh; - - if (!open($fh , '<', $whatis) && $!{ENOENT}) { - build_index($mandir, $p); - open($fh , '<', $whatis); - } - return $fh; -} - -# remove(dir, \@pages, $p) -# -# remove set of pages from directory index -# -sub remove -{ - require OpenBSD::Makewhatis::Whatis; - - my ($mandir, $args, $p) = @_; - $p //= OpenBSD::Makewhatis::Printer->new; - $p->check_dir($mandir); - my $whatis = "$mandir/whatis.db"; - my $old = open_whatis($mandir, $whatis, $p) or - $p->fatal("#1: can't open #2 to merge with: #3", $0, $whatis, $!); - my $subjects = scan_manpages($args, $p); - my %remove = map {$_ => 1 } @$subjects; - $subjects = []; - while (my $l = <$old>) { - chomp $l; - push(@$subjects, $l) unless defined $remove{$l}; - } - close($old); - OpenBSD::Makewhatis::Whatis::write($subjects, $mandir, $p); -} - -# $dirs = default_dirs($p) -# -# read list of default directories from man.conf -# -sub default_dirs -{ - my $p = shift; - my $args=[]; - open(my $conf, '<', '/etc/man.conf') or - $p->fatal("#1: can't open #2: #3", $0, "/etc/man.conf", $!); - while (my $l = <$conf>) { - chomp $l; - push(@$args, $1) if $l =~ m/^_whatdb\s+(.*)\/whatis\.db\s*$/; - } - close $conf; - return $args; -} - -# makewhatis(\@args, \%opts) -# -# glue for front-end, see makewhatis(8) -# -sub makewhatis -{ - my ($args, $opts) = @_; - my $p = OpenBSD::Makewhatis::Printer->new; - if (defined $opts->{'p'}) { - $p->{picky} = 1; - } - if (defined $opts->{'t'}) { - $p->{testmode} = 1; - my $subjects = scan_manpages($args, $p); - $p->print("#1", join("\n", @$subjects)."\n"); - return; - } - if (defined $opts->{'v'}) { - $p->{verbose} = 1; - } - - if (defined $opts->{'d'}) { - merge($opts->{'d'}, $args, $p); - return; - } - if (defined $opts->{'u'}) { - remove($opts->{'u'}, $args, $p); - return; - } - if (@$args == 0) { - $args = default_dirs($p); - } - - for my $mandir (@$args) { - if (-d $mandir) { - build_index($mandir, $p); - } elsif (-e $mandir || $p->picky) { - $p->errsay("#1: #2 is not a directory", $0, $mandir); - } - } -} - -1; diff --git a/libexec/makewhatis/OpenBSD/Makewhatis/Check.pm b/libexec/makewhatis/OpenBSD/Makewhatis/Check.pm deleted file mode 100644 index 15ed522d754..00000000000 --- a/libexec/makewhatis/OpenBSD/Makewhatis/Check.pm +++ /dev/null @@ -1,83 +0,0 @@ -# ex:ts=8 sw=4: -# $OpenBSD: Check.pm,v 1.4 2014/03/21 10:59:31 espie Exp $ -# Copyright (c) 2000-2004 Marc Espie -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -use strict; -use warnings; -package OpenBSD::Makewhatis::Check; - -sub found -{ - my ($pattern, $filename) = @_; - my @candidates = glob $pattern; - if (@candidates > 0) { - # quick check of inode, dev number - my ($dev_cmp, $inode_cmp) = (stat $filename)[0,1]; - for my $f (@candidates) { - my ($dev, $inode) = (stat $f)[0, 1]; - if ($dev == $dev_cmp && $inode == $inode_cmp) { - return 1; - } - } - # slow check with File::Compare - require File::Compare; - - for my $f (@candidates) { - if (File::Compare::compare($f, $filename) == 0) { - return 1; - } - } - } - return 0; -} -# verify_subject($subject, $filename, $p): -# -# reparse the subject we're about to add, and check whether it makes -# sense, e.g., is there a man page around. -sub verify_subject -{ - my ($s, $filename, $p) = @_; - if ($s =~ m/\s*(.*?)\s*\((.*?)\)\s-\s/) { - my $man = $1; - my $section = $2; - my @mans = split(/\s*,\s*|\s+/, $man); - my $base = $filename; - if ($base =~ m|/|) { - $base =~ s,/[^/]*$,,; - } else { - $base = '.'; - } - my @notfound = (); - for my $func (@mans) { - my $i = $func; - next if found("$base/$i.*", $filename); - # try harder - $i =~ s/\(\)//; - $i =~ s/\-//g; - $i =~ s,^etc/,,; - next if found("$base/$i.*", $filename); - # and harder... - $i =~ tr/[A-Z]/[a-z]/; - next if found("$base/$i.*", $filename); - push(@notfound, $func); - } - if (@notfound > 0) { - $p->errsay("Couldn't find #1 in #2:\n#3", - join(', ', @notfound), $filename, $s); - } - } -} - -1; diff --git a/libexec/makewhatis/OpenBSD/Makewhatis/Find.pm b/libexec/makewhatis/OpenBSD/Makewhatis/Find.pm deleted file mode 100644 index 0e9e2febd34..00000000000 --- a/libexec/makewhatis/OpenBSD/Makewhatis/Find.pm +++ /dev/null @@ -1,73 +0,0 @@ -# ex:ts=8 sw=4: -# $OpenBSD: Find.pm,v 1.4 2014/03/21 10:59:31 espie Exp $ -# Copyright (c) 2000-2004 Marc Espie -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -use strict; -use warnings; -package OpenBSD::Makewhatis::Find; - -use File::Find; - -# Find out all file names that correspond to existing stuff - -sub equivalents -{ - my $f = shift; - my @l = (); - $f =~ s/(?:\.Z|\.gz)$//; - push(@l, $f, "$f.Z", "$f.gz"); - if ($f =~ s,/cat([\dln]\w*?)/(.*)\.0$,/man$1/$2.$1,) { - push(@l, $f, "$f.Z", "$f.gz"); - } elsif ($f =~ s,/man([\dln]\w*?)/(.*)\.\1$,/cat$1/$2.0,) { - push(@l, $f, "$f.Z", "$f.gz"); - } - return @l; -} - -# $list = find_manpages($dir) -# -# find all manpages under $dir, trim some duplicates. -# -sub find_manpages($) -{ - my $dir = shift; - my $h = {}; - my $list=[]; - my $nodes = {}; - my $done = {}; - find( - sub { - return unless m/\.[\dln]\w*(?:\.Z|\.gz)?$/; - return unless -f $_; - my $unique = join("/", (stat _)[0,1]); - return if defined $nodes->{$unique}; - $nodes->{$unique} = 1; - push @$list, $File::Find::name; - $h->{$File::Find::name} = (stat _)[9]; - }, $dir); - for my $i (keys %$h) { - next if $done->{$i}; - # only keep stuff that actually exists - my @l = grep {defined $h->{$_}} equivalents($i); - # don't do it twice - $done->{$_} = 1 for @l; - # find the most recent one - @l = sort {$h->{$a} <=> $h->{$b}} @l; - push @$list, pop @l; - } - return $list; -} - -1; diff --git a/libexec/makewhatis/OpenBSD/Makewhatis/Formated.pm b/libexec/makewhatis/OpenBSD/Makewhatis/Formated.pm deleted file mode 100644 index ce34d44b46b..00000000000 --- a/libexec/makewhatis/OpenBSD/Makewhatis/Formated.pm +++ /dev/null @@ -1,133 +0,0 @@ -# ex:ts=8 sw=4: -# $OpenBSD: Formated.pm,v 1.9 2014/03/21 10:59:31 espie Exp $ -# Copyright (c) 2000-2004 Marc Espie -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -use strict; -use warnings; -package OpenBSD::Makewhatis::Formated; - -# add_formated_subject($_, $section, $h): -# add subject $_ to the list of current subjects in $h, in section $section. -# -sub add_formated_subject -{ - my ($s, $section, $h) = @_; - - if ($s =~ m/\-/) { - $s =~ s/([-+.\w\d,])\s+/$1 /g; - $s =~ s/([a-z][A-z])-\s+/$1/g; - # some twits use: func -- description - if ($s =~ m/^[^-+.\w\d]*(.*?) -(?:-?)\s+(.*)/) { - my ($func, $descr) = ($1, $2); - $func =~ s/,\s*$//; - # nroff will tend to cut function names at the weirdest places - if (length($func) > 40 && $func =~ m/,/ && $section =~ /^3/) { - $func =~ s/\b \b//g; - } - $h->add("$func ($section) - $descr"); - return; - } - } - - $h->weird_subject($s) if $h->p->picky; - - # try to find subject in line anyway - if ($s =~ m/^\s*(.*\S)(?:\s{3,}|\(\)\s+)(.*?)\s*$/) { - my ($func, $descr) = ($1, $2); - $func =~ s/\s+/ /g; - $descr =~ s/\s+/ /g; - $h->add("$func ($section) - $descr"); - return; - } - - $h->weird_subject($s) unless $h->p->picky; -} - -# handle($file, $h) -# -# handle a formatted manpage in $file -# -# may return several subjects, perl(3p) do ! -# -sub handle -{ - my ($file, $h) = @_; - # my $_; - my ($section, $subject); - my $foundname = 0; - while (<$file>) { - chomp; - if (m/^$/) { - # perl aggregates several subjects in one manpage - # so we don't stop after we've got one subject - add_formated_subject($subject, $section, $h) if defined $subject; - $subject = undef; - next; - } - # Remove boldface from wide characters - while (s/(..)\cH\cH\1/$1/g) - {} - # Remove boldface and underlining - while (s/_\cH//g || s/(.)\cH\1/$1/g) - {} - if (!$foundname && m/\w[-+.\w\d]*\(([-+.\w\d\/]+)\)/) { - $section = $1; - # Find architecture - if (m/Manual\s+\((.*?)\)/) { - $section = "$section/$1"; - } - } - # Not all man pages are in english - # weird hex is `Namae' in japanese - 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 ($h->filename =~ m/(?:cat|man)([\dln])\//) { - $section = $1; - $h->errsay("Can't find section in #2, deducting #1 from context", $section) if $h->p->picky; - } else { - $section='??'; - $h->errsay("Can't find section in #1"); - } - } - $foundname = 1; - next; - } - if ($foundname) { - if (m/^\S/ || m/^\s+\*{3,}\s*$/) { - add_formated_subject($subject, $section, $h) - if defined $subject; - last; - } else { - # deal with troff hyphenations - if (defined $subject and $subject =~ m/\xad\s*$/) { - $subject =~ s/(?:\xad\cH)*\xad\s*$//; - s/^\s*//; - } - # more troff hyphenation - if (defined $subject and $subject =~ m/[^\s-](?:\-\cH)*\-$/) { - $subject =~ s/(?:\-\cH)*\-$//; - s/^\s*//; - } - s/^\s+/ /; - $subject.=$_; - } - } - } - - $h->cant_find_subject if $h->no_subjects; -} - -1; diff --git a/libexec/makewhatis/OpenBSD/Makewhatis/Subject.pm b/libexec/makewhatis/OpenBSD/Makewhatis/Subject.pm deleted file mode 100644 index 1bca546f073..00000000000 --- a/libexec/makewhatis/OpenBSD/Makewhatis/Subject.pm +++ /dev/null @@ -1,99 +0,0 @@ -# ex:ts=8 sw=4: -# $OpenBSD: Subject.pm,v 1.4 2014/03/21 10:58:46 espie Exp $ -# Copyright (c) 2010 Marc Espie -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -use strict; -use warnings; - -package OpenBSD::Makewhatis::SubjectHandler; - -sub new -{ - my ($class, $p) = @_; - return bless { p => $p, subjects => {}}, $class; -} - -sub add -{ - my ($h, $s) = @_; - $h->{subjects}{$s} = $h->{current}; - $h->{has_subjects} = 1; -} - -sub no_subjects -{ - my $h = shift; - return !$h->{has_subjects}; -} - -sub subjects -{ - my $h = shift; - return keys %{$h->{subjects}}; -} - -sub subject_hash -{ - my $h = shift; - return $h->{subjects}; -} - -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 -{ -} - -1; diff --git a/libexec/makewhatis/OpenBSD/Makewhatis/Unformated.pm b/libexec/makewhatis/OpenBSD/Makewhatis/Unformated.pm deleted file mode 100644 index 51db8ba3bd9..00000000000 --- a/libexec/makewhatis/OpenBSD/Makewhatis/Unformated.pm +++ /dev/null @@ -1,220 +0,0 @@ -# ex:ts=8 sw=4: -# $OpenBSD: Unformated.pm,v 1.10 2014/03/21 10:59:31 espie Exp $ -# Copyright (c) 2000-2004 Marc Espie -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -use strict; -use warnings; -package OpenBSD::Makewhatis::Unformated; - -# add_unformated_subject($toadd, $section, $toexpand, $h) : -# -# build subject from list of $toadd lines, and add it to the list -# of current subjects as section $section -# -sub add_unformated_subject -{ - my ($toadd, $section, $toexpand, $h) = @_; - - my $exp = sub { - if (defined $toexpand->{$_[0]}) { - return $toexpand->{$_[0]}; - } else { - $h->errsay("#2: can't expand #1", $_[0]); - return ""; - } - }; - - my $s = join(' ', @$toadd); - # do interpolations - $s =~ s/\\\*\((..)/&$exp($1)/ge; - $s =~ s/\\\*\[(.*?)\]/&$exp($1)/ge; - - # horizontal space adjustments - while ($s =~ s/\\s[-+]?\d+//g) - {} - # unbreakable spaces - $s =~ s/\\\s+/ /g; - # unbreakable em dashes - $s =~ s/\\\|\\\(em\\\|/-/g; - # em dashes - $s =~ s/\\\(em\s+/- /g; - # single quotes - $s =~ s/\\\(aq/\'/g; - # em dashes in the middle of lines - $s =~ s/\\\(em/-/g; - $s =~ s/\\\*[LO]//g; - $s =~ s/\\\(tm/(tm)/g; - # font changes - $s =~ s/\\f[BIRP]//g; - $s =~ s/\\f\(..//g; - # fine space adjustments - while ($s =~ s/\\[vh]\'.*?\'//g) - {} - unless ($s =~ s/\s+\\-\s+/ ($section) - / || - $s =~ s/\s?\\\-/ ($section) -/ || - $s =~ s/\s-\s/ ($section) - /) { - $h->weird_subject($s) if $h->p->picky; - # Try guessing where the separation falls... - $s =~ s/\s+\:\s+/ ($section) - / || $s =~ s/\S+\s/$& ($section) - / || - $s =~ s/$/ ($section) - (empty subject)/; - } - # other dashes - $s =~ s/\\-/-/g; - # escaped characters - $s =~ s/\\\&(.)/$1/g; - $s =~ s/\\\|/|/g; - # gremlins... - $s =~ s/\\c//g; - # sequence of spaces - $s =~ s/\s+$//; - $s =~ s/^\s+//; - $s =~ s/\s+/ /g; - # some damage control - if ($s =~ m/^\Q($section) - \E/) { - $h->weird_subject($s) if $h->p->picky; - return; - } - $h->add($s); -} - -# handle($file, $h) -# -# handle an unformated manpage in $file -# -# may return several subjects, perl(3p) do ! -# -sub handle -{ - my ($f, $h) = @_; - my %toexpand = (Na => 'NaN', Tm => '(tm)'); - my $so_found = 0; - my $found_th = 0; - my $found_old = 0; - my $found_dt = 0; - my $found_new = 0; - # subject/keep is the only way to deal with Nm/Nd pairs - my @subject = (); - my @keep = (); - my $nd_seen = 0; - # retrieve basename of file - my ($name, $section) = $h->filename =~ m|(?:.*/)?(.*)\.([\w\d]+)|; - # scan until macro - local $_; - while (<$f>) { - next unless m/^\./ || $found_old || $found_new; - next if m/^\.\\\"/; - next if m/^\.if\s+t\s+/; - s/^\.i[ef]\s+n\s+//; - s/^\.i[ef]\s+\\n\(\.g\s+//; - if (m/^\.\s*de/) { - while (<$f>) { - last if m/^\.\s*\./; - } - next; - } - if (m/^\.\s*ds\s+(\S+)\s+/) { - chomp($toexpand{$1} = $'); - next; - } - # Some cross-refs just link to another manpage - $so_found = 1 if m/^\.\s*so/; - if (m/^\.\s*TH/ || m/^\.\s*th/) { - # in pricky mode, we should try to match these - # ($name2, $section2) = m/^\.(?:TH|th)\s+(\S+)\s+(\S+)/; - # scan until first section - $found_th = 1; - next; - } - if ($found_th && !$found_old && (m/^\.\s*SH/ || m/^\.\s*sh/)) { - $found_old = 1; - next; - } - if (m/^\.\s*Dt/) { - $section .= "/$1" if (m/^\.\s*Dt\s+\S+\s+\d\S*\s+(\S+)/); - $found_dt = 1; - next; - } - if ($found_dt && !$found_new && m/^\.\s*Sh/) { - $found_new = 1; - next; - } - if ($found_old) { - last if m/^\.\s*(?:SH|sh|SS|ss|nf|LI)/; - # several subjects in one manpage - if (m/^\.\s*(?:PP|Pp|br|PD|LP|sp)/) { - add_unformated_subject(\@subject, - $section, \%toexpand, $h) if @subject != 0; - @subject = (); - next; - } - next if m/^\'/ || m/^\.\s*tr\s+/ || m/^\.\s*\\\"/ || - m/^\.\s*sv/ || m/^\.\s*Vb\s+/ || m/\.\s*HP\s+/; - # Motif index entries, don't do anything for now. - next if m/^\.\s*iX/; - # Some other index (cook) - next if m/^\.\s*XX/; - chomp; - s/\.\s*(?:B|I|IR|SM|BR)\s+//; - if (m/^\.\s*(\S\S)/) { - $h->errsay("#2: not grokking #1", $_) if $h->p->picky; - next; - } - push(@subject, $_) unless m/^\s*$/; - next; - } - if ($found_new) { - last if m/^\.\s*Sh/; - s/\s,/,/g; - if (s/^\.\s*(\S\S)\s+//) { - my $macro = $1; - next if $macro eq "\\\""; - s/\"(.*?)\"/$1/g; - s/\\-/-/g; - $macro eq 'Xr' and s/^(\S+)\s+(\d\S*)/$1 ($2)/; - $macro eq 'Ox' and s/^/OpenBSD /; - $macro eq 'Nx' and s/^/NetBSD /; - if ($macro eq 'Nd') { - if (@keep != 0) { - add_unformated_subject(\@keep, - $section, \%toexpand, $h); - @keep = (); - } - push(@subject, "\\-"); - $nd_seen = 1; - } - if ($nd_seen && $macro eq 'Nm') { - @keep = @subject; - @subject = (); - $nd_seen = 0; - } - } - push(@subject, $_) unless m/^\s*$/; - } - } - if ($found_th && !$found_old) { - $h->cant_find_subject; - } - if ($found_dt && !$found_new) { - $h->cant_find_subject; - } - unshift(@subject, @keep) if @keep != 0; - add_unformated_subject(\@subject, $section, - \%toexpand, $h) if @subject != 0; - if (!$so_found && !$found_old && !$found_new) { - $h->errsay("Unknown manpage type #1"); - } -} - -1; diff --git a/libexec/makewhatis/OpenBSD/Makewhatis/Whatis.pm b/libexec/makewhatis/OpenBSD/Makewhatis/Whatis.pm deleted file mode 100644 index 8c31fa3d5e1..00000000000 --- a/libexec/makewhatis/OpenBSD/Makewhatis/Whatis.pm +++ /dev/null @@ -1,66 +0,0 @@ -# ex:ts=8 sw=4: -# $OpenBSD: Whatis.pm,v 1.4 2010/07/09 08:12:49 espie Exp $ -# Copyright (c) 2000-2004 Marc Espie -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -use strict; -use warnings; -package OpenBSD::Makewhatis::Whatis; - -use constant MAXLINELEN => 8192; - -use File::Temp qw/tempfile/; -use File::Compare; - -# write($list, $dir): -# -# write $list to file named $file, removing duplicate entries. -# Change $file mode/owners to expected values -# Write to temporary file first, and do the copy only if changes happened. -# -sub write -{ - my ($list, $dir, $p) = @_; - my $f = "$dir/whatis.db"; - - my ($out, $tempname); - ($out, $tempname) = tempfile('/tmp/makewhatis.XXXXXXXXXX') or die "$0: Can't open temporary file"; - - my @sorted = sort @$list; - my $last; - - while (my $l = shift @sorted) { - next if length $l > MAXLINELEN; - print $out $l, "\n" unless defined $last and $l eq $last; - $last = $l; - } - close $out; - if (compare($tempname, $f) == 0) { - unlink($tempname); - } else { - require File::Copy; - - unlink($f); - if (File::Copy::move($tempname, $f)) { - chmod 0444, $f; - chown 0, (getgrnam 'bin')[2], $f; - } else { - $p->errsay("#1: Can't create #2: #3", $0, $f, $!); - unlink($tempname); - exit 1; - } - } -} - -1; diff --git a/libexec/makewhatis/makewhatis b/libexec/makewhatis/makewhatis deleted file mode 100644 index bc9f6fe5cc2..00000000000 --- a/libexec/makewhatis/makewhatis +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/perl -w -# ex:ts=8 sw=4: - -# $OpenBSD: makewhatis,v 1.3 2013/01/29 11:08:55 espie Exp $ -# Copyright (c) 2000-2004 Marc Espie -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -require 5.006_000; - -use strict; -use warnings; - -use Getopt::Std; -use OpenBSD::Makewhatis; - - -# main code - -my %opts; -getopts('tpvd:u:', \%opts); - -OpenBSD::Makewhatis::makewhatis(\@ARGV, \%opts); - -#while (my ($key, $value) = each %INC) { -# print "$key => $value\n"; -#} diff --git a/libexec/makewhatis/makewhatis.8 b/libexec/makewhatis/makewhatis.8 deleted file mode 100644 index 74a0b968465..00000000000 --- a/libexec/makewhatis/makewhatis.8 +++ /dev/null @@ -1,170 +0,0 @@ -.\" $OpenBSD: makewhatis.8,v 1.20 2012/01/22 13:45:22 schwarze Exp $ -.\" $NetBSD: makewhatis.8,v 1.2.2.1 1997/11/10 19:57:45 thorpej Exp $ -.\" -.\" Copyright (c) 1997 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Robert Dobbs . -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS -.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS -.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd $Mdocdate: January 22 2012 $ -.Dt MAKEWHATIS 8 -.Os -.Sh NAME -.Nm makewhatis -.Nd create a whatis.db database -.Sh SYNOPSIS -.Nm makewhatis -.Op Fl pv -.Op Ar manpath ... -.Nm makewhatis -.Op Fl pv -.Fl d Ar manpath -.Ar files ... -.Nm makewhatis -.Op Fl pv -.Fl u Ar manpath -.Ar files ... -.Nm makewhatis -.Op Fl pv -.Fl t -.Ar files -.Sh DESCRIPTION -.Nm -extracts the NAME lines from compiled or raw -.Xr man 1 -pages and creates -a whatis.db database (that is, a subject index) -for use with -.Xr apropos 1 , -.Xr whatis 1 , -and -.Xr man 1 Ns 's -.Fl k -option. -If -.Ar manpath -is unspecified, -.Nm -by default creates databases for each directory prefixed by -the _whatdb keyword in -.Pa /etc/man.conf . -Man pages compressed with -.Xr compress 1 -and -.Xr gzip 1 -are uncompressed before processing. -.Pp -If the -.Fl d -option is used, -.Nm -merges the description of -.Ar files -with an existing -.Pa whatis.db -database in -.Ar manpath . -.Pp -If the -.Fl u -option is used, -.Nm -removes the description of -.Ar files -from an existing -.Pa whatis.db -database in -.Ar manpath . -.Pp -By default, -.Nm -is relatively silent. -If the -.Fl v -is used, -.Nm -will be more verbose about manpages with problems. -If the -.Fl p -option is used, -.Nm -is less forgiving and warns about incorrect man pages. -.Pp -The -.Fl t -option can be used to check a set of potential man pages without -changing any -.Pa whatis.db -database. -.Sh FILES -.Bl -tag -width /etc/man.conf -compact -.It Pa whatis.db -index to man pages in directory -.It Pa /etc/man.conf -man configuration information -.El -.Sh SEE ALSO -.Xr apropos 1 , -.Xr man 1 , -.Xr whatis 1 , -.Xr man.conf 5 -.Sh HISTORY -A -.Nm -utility first appeared in -.Bx 2 . -It was rewritten in -.Xr perl 1 -for -.Ox 2.7 . -.Pp -The -.Ar dir -argument first appeared in -.Nx 1.0 ; -the options -.Fl dptu -in -.Ox 2.7 ; -and the option -.Fl v -in -.Ox 4.9 . -.Sh AUTHORS -.An Bill Joy -wrote the original -.Bx -.Nm -in February 1979. -.An Marc Espie -started the Perl version in 2000. -.Sh BUGS -.Nm -should parse -.Pa /etc/man.conf -and deal with extra configuration information. -.Pp -The use of heuristics to retrieve subjects -from most man pages is not 100% accurate. -- 2.20.1