diff options
author | joerg <joerg@FreeBSD.org> | 1995-03-31 04:00:53 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 1995-03-31 04:00:53 +0000 |
commit | 256869e2ccd101dbeaa858a22b8ed9a10d99ac9a (patch) | |
tree | e8110866e723ef7eddb1ace73a637ab6e096b402 /gnu | |
parent | 74c679e3d7f79520d731ccb3dfe3aeec85dabaf8 (diff) | |
download | FreeBSD-src-256869e2ccd101dbeaa858a22b8ed9a10d99ac9a.zip FreeBSD-src-256869e2ccd101dbeaa858a22b8ed9a10d99ac9a.tar.gz |
Wolfram's latest update.
Submitted by: wosch@cs.tu-berlin.de (Wolfram Schneider)
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/usr.bin/man/catman/catman.1 | 23 | ||||
-rw-r--r-- | gnu/usr.bin/man/catman/catman.perl | 140 | ||||
-rw-r--r-- | gnu/usr.bin/man/makewhatis/makewhatis.1 | 34 | ||||
-rw-r--r-- | gnu/usr.bin/man/makewhatis/makewhatis.perl | 410 |
4 files changed, 368 insertions, 239 deletions
diff --git a/gnu/usr.bin/man/catman/catman.1 b/gnu/usr.bin/man/catman/catman.1 index 0783a80..b8715d7 100644 --- a/gnu/usr.bin/man/catman/catman.1 +++ b/gnu/usr.bin/man/catman/catman.1 @@ -30,7 +30,7 @@ .\" .\" E-mail: Wolfram Schneider <wosch@cs.tu-berlin.de> .\" -.\" $Id: catman.1,v 1.2 1995/03/18 02:11:55 ache Exp $ +.\" $Id: catman.1,v 1.9 1995/03/27 19:51:14 w Exp $ .\" .Dd Mar 12, 1995 @@ -42,9 +42,10 @@ .Sh SYNOPSIS .Nm catman -.Op Fl h | Fl help .Op Fl f | Fl force +.Op Fl h | Fl help .Op Fl p | Fl print +.Op Fl r | Fl remove .Op Fl v | Fl verbose .Op Ar directories... @@ -66,19 +67,25 @@ defined. .Sh OPTIONS .Bl -tag -width Ds -.It Fl h , Fl help -Print options and exit. - -.It Fl v , Fl verbose -More warnings. - .It Fl f , Fl force Force overwriting old cat pages. Normally only those pages will be formatted which are not up to date. This option is a waste of time, CPU and RAM. +.It Fl h , Fl help +Print options and exit. + .It Fl p , Fl print Don't actually format man pages. Show what would be done. +.It Fl r , Fl remove +Remove garbage, e.\& g. catpage without manpage, uncompressed catpage but +a compressed catpage exist, filenames with non-alphanumeric +characters, uncompressed manpage but a compressed manpage exist. + +.It Fl v , Fl verbose +More warnings. + + .Sh EXAMPLES .Pp .Dl $ catman diff --git a/gnu/usr.bin/man/catman/catman.perl b/gnu/usr.bin/man/catman/catman.perl index 1c9180a..ab87c4b 100644 --- a/gnu/usr.bin/man/catman/catman.perl +++ b/gnu/usr.bin/man/catman/catman.perl @@ -35,14 +35,14 @@ # Bugs: sure # Email: Wolfram Schneider <wosch@cs.tu-berlin.de> # -# $Id: catman.perl,v 1.2 1995/03/18 02:11:56 ache Exp $ +# $Id: catman.pl,v 1.10 1995/03/18 19:57:22 w Exp $ # sub usage { warn <<EOF; -usage: catman [-h|-help] [-f|-force] [-p|-print] - [-v|-verbose] directories ... +usage: catman [-h|-help] [-f|-force] [-p|-print] [-r|remove] + [-v|-verbose] [directories ...] EOF exit 1; @@ -69,12 +69,12 @@ sub variables { $SIG{'TERM'} = 'Exit'; $tmp = ''; # tmp file - $ENV{'PATH'} = "/bin:/usr/bin"; + $ENV{'PATH'} = '/bin:/usr/bin'; } sub Exit { - unlink($tmp) if $tmp =~ /^\//; # unlink if a filename - die "catman: die on signal SIG@_\n"; + unlink($tmp) if $tmp ne ""; # unlink if a filename + die "$0: die on signal SIG@_\n"; } sub parse { @@ -85,24 +85,47 @@ sub parse { last if /^--$/; if (/^--?(f|force)$/) { $force = 1 } elsif (/^--?(p|print)$/) { $print = 1 } -# elsif (/^--?(r|remove)$/) { $remove = 1 } + elsif (/^--?(r|remove)$/) { $remove = 1 } elsif (/^--?(v|verbose)$/) { $verbose = 1 } else { &usage } } - return @argv if $#argv >= 0; + return &absolute_path(@argv) if $#argv >= 0; return @defaultmanpath if $#defaultmanpath >= 0; warn "Missing directories\n"; &usage; } -# stript unused '/' +# make relative path to absolute path +sub absolute_path { + local(@dirlist) = @_; + local($pwd, $dir, @a); + + $pwd = $ENV{'PWD'}; + + foreach $dir (@dirlist) { + if ($dir !~ "^/") { + chop($pwd = `pwd`) if (!$pwd || $pwd !~ /^\//); + push(@a, "$pwd/$dir"); + } else { + push(@a, $dir); + } + } + return @a; +} + +# strip unused '/' # e.g.: //usr///home// -> /usr/home sub stripdir { local($dir) = @_; $dir =~ s|/+|/|g; # delete double '/' $dir =~ s|/$||; # delete '/' at end + $dir =~ s|/(\.\/)+|/|g; # delete ././././ + + $dir =~ s|/+|/|g; # delete double '/' + $dir =~ s|/$||; # delete '/' at end + $dir =~ s|/\.$||; # delete /. at end return $dir if $dir ne ""; return '/'; } @@ -111,14 +134,15 @@ sub stripdir { sub parse_dir { local($dir) = @_; local($subdir, $catdir); - local($pwd); + local($dev,$ino) = (stat($dir))[01]; - # not absolute path - if ($dir !~ /^\//) { - chop($cwd = `pwd`); - $dir = "$cwd/$dir"; + if ($dir_visit{$dev,$ino}) { + warn "$dir already parsed: $dir_visit{$dev,$ino}\n"; + return 1; } - + $dir_visit{$dev,$ino} = $dir; + # $| = 1 if $verbose; + if ($dir =~ /man$/) { warn "open manpath directory ``$dir''\n" if $verbose; if (!opendir(DIR, $dir)) { @@ -154,6 +178,7 @@ sub catdir_create { $exit = 1; return 0; } + return 1; } warn "mkdir ``$catdir''\n" if $verbose || $print; @@ -164,8 +189,8 @@ sub catdir_create { $exit = 1; return 0; } + return 1; } - return 1; } # I: /usr/share/man/man9 @@ -173,7 +198,7 @@ sub catdir_create { sub man2cat { local($man) = @_; - $man =~ s/man(\w+)/cat$1/; + $man =~ s/man(\w+)$/cat$1/; return $man; } @@ -181,10 +206,10 @@ sub parse_subdir { local($subdir) = @_; local($file, $f, $catdir, $catdir_short); local($mtime_man, $mtime_cat); - local($read); + local(%read); if (!opendir(D, $subdir)) { - warn "opendir ``$subdir'': $!\n"; return 0; + warn "opendir ``$subdir'': $!\n"; $exit = 1; return 0; } $catdir = &man2cat($subdir); @@ -199,12 +224,28 @@ sub parse_subdir { warn "open man directory: ``$subdir''\n" if $verbose; foreach $file (readdir(D)) { - next if $file =~ /^(\.|\.\.)$/; # skip current and parent directory + # skip current and parent directory + next if $file eq "." || $file eq ".."; - $read{$file} = 1; + # fo_09-o.bar0 + if ($file !~ /^[\w\-\[\.]+\.\w+$/) { + &garbage("$subdir/$file", "Assume garbage") + unless -d $file; + next; + } + + if ($file !~ /\.gz$/) { + if (-e "$file.gz") { + &garbage("$subdir/$file", + "Manpage unused, see compressed version"); + next; + } + warn "$subdir/$file is uncompressed\n" if $verbose; + $cfile = "$file.gz"; + } else { + $cfile = "$file"; + } - # replace readable_file with stat && ... - # faster, hackers choise :-) if (!(($mtime_man = ((stat("$file"))[9])) && -r _ && -f _)) { if (! -d _) { warn "Cannot read file: ``$subdir/$file''\n"; @@ -216,38 +257,23 @@ sub parse_subdir { next; } - # fo_09-o.bar0 - if ($file !~ /^[\w\-\[\.]+\.\w+$/) { - warn "Assume garbage: ``$subdir/$file''\n"; - next; - } + $read{$file} = 1; # Assume catpages always compressed - # if ($mtime_cat = &readable_file("$catdir_short/$file")) { - if (($mtime_cat = ((stat("$catdir_short/$file"))[9])) + if (($mtime_cat = ((stat("$catdir_short/$cfile"))[9])) && -r _ && -f _) { if ($mtime_man > $mtime_cat || $force) { - &nroff("$subdir/$file", "$catdir/$file"); - } else { - warn "up to date: $subdir/$file\n" if $verbose; - } - } elsif (($mtime_cat = ((stat("$catdir_short/$file$ext"))[9])) - && -r _ && -f _) { - if ($mtime_man > $mtime_cat || $force) { - &nroff("$subdir/$file", "$catdir/$file"); + &nroff("$subdir/$file", "$catdir/$cfile"); } else { warn "up to date: $subdir/$file\n" if $verbose; + #print STDERR "." if $verbose; } } else { - # be paranoid - unlink("$catdir/$file"); - - &nroff("$subdir/$file", "$catdir/$file"); + &nroff("$subdir/$file", "$catdir/$cfile"); } } closedir D; - if (!opendir(D, $catdir)) { warn "opendir ``$catdir'': $!\n"; return 0; } @@ -257,25 +283,41 @@ sub parse_subdir { next if $file =~ /^(\.|\.\.)$/; # skip current and parent directory if ($file !~ /^[\w\-\[\.]+\.\w+$/) { - warn "Assume garbage: ``$catdir/$file''\n" + &garbage("$catdir/$file", "Assume garbage") unless -d "$catdir/$file"; + next; } - unless ($read{$file}) { + if ($file !~ /\.gz$/ && $read{"$file.gz"}) { + &garbage("$catdir/$file", + "Catpage unused, see compressed version"); + } elsif (!$read{$file}) { # maybe a bug in man(1) # if both manpage and catpage are uncompressed, man reformats # the manpage and puts a compressed catpage to the # already existing uncompressed catpage - $f = $file; $f =~ s/$ext$//; - # man page is uncompressed - next if $read{$f}; + ($f = $file) =~ s/\.gz$//; - warn "Catpage without manpage: $catdir/$file\n"; + # man page is uncompressed, catpage is compressed + next if $read{$f}; + &garbage("$catdir/$file", "Catpage without manpage"); } } closedir D; } +sub garbage { + local($file, @text) = @_; + + warn "@text: ``$file''\n"; + if ($remove) { + warn "unlink $file\n"; + unless ($print) { + unlink($file) || warn "unlink $file: $!\n" ; + } + } +} + sub nroff { local($man,$cat) = @_; local($nroff) = "nroff -Tascii -man | col"; diff --git a/gnu/usr.bin/man/makewhatis/makewhatis.1 b/gnu/usr.bin/man/makewhatis/makewhatis.1 index f7cf036..4570b58 100644 --- a/gnu/usr.bin/man/makewhatis/makewhatis.1 +++ b/gnu/usr.bin/man/makewhatis/makewhatis.1 @@ -30,7 +30,7 @@ .\" .\" Email: Wolfram Schneider <wosch@cs.tu-berlin.de> .\" -.\" $Id: makewhatis.1,v 1.2 1995/01/15 14:26:12 w Exp w $ +.\" $Id: makewhatis.1,v 1.1 1995/02/15 22:52:51 joerg Exp $ .\" .Dd Jan, 12, 1995 @@ -42,12 +42,12 @@ .Sh SYNOPSIS .Nm makewhatis -.Op Fl format Ar column -.Op Fl name Ar name -.Op Fl outfile Ar file -.Op Fl verbose -.Op Fl help -.Ar directory ... +.Op Fl i | Fl indent Ar column +.Op Fl n | Fl name Ar name +.Op Fl o | Fl outfile Ar file +.Op Fl v | Fl verbose +.Op Fl h | Fl help +.Op Ar directories ... .Sh DESCRIPTION .Nm Makewhatis @@ -69,20 +69,30 @@ are allowed. .Sh OPTIONS .Bl -tag -width Ds -.It Fl help +.It Fl h , Fl help Print options and exit. -.It Fl verbose +.It Fl v, Fl verbose Issue more warnings .Pq to stderr . -.It Fl format Ar column +For every parsed man page write a single char: +.Ql \&. +for an uncompressed page, +.Ql * +for a compressed page, and +.Ql + +for a link. + +.It Fl i , Fl indent Ar column Justify description strings to .Ar column Pq default 24 . -.It Fl outfile Ar file + +.It Fl o , Fl outfile Ar file Write all output to .Ar file instead of .Pa dirname/whatis Ns . -.It Fl name Ar name + +.It Fl n , Fl name Ar name Use .Ar name instead of diff --git a/gnu/usr.bin/man/makewhatis/makewhatis.perl b/gnu/usr.bin/man/makewhatis/makewhatis.perl index 3fd8852..14be120 100644 --- a/gnu/usr.bin/man/makewhatis/makewhatis.perl +++ b/gnu/usr.bin/man/makewhatis/makewhatis.perl @@ -1,6 +1,7 @@ #!/usr/bin/perl # -# Copyright (c) Nov 1994 Wolfram Schneider. All rights reserved. +# Copyright (c) 1994, 1995 Wolfram Schneider. All rights reserved. +# Alle Rechte vorbehalten. Es gilt das kontinentaleuropäische Urheberrecht. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -32,29 +33,17 @@ # # makewhatis -- update the whatis database in the man directories. # -# /etc/weekly: makewhatis `manpath -q` +# E-Mail: Wolfram Schneider <wosch@cs.tu-berlin.de> # - -# Bugs: You need perl! -# My English :( -# Features: faster!!! -# tested with /usr/share/man (1414 Files) -# uncompressed manpages: -# perl: 53.65 real 27.20 user 6.81 sys -# shell: 1036.27 real 597.27 user 654.93 sys -# compressed manpages: -# perl: 192.70 real 80.06 user 90.26 sys -# shell: 1077.26 real 671.64 user 664.27 sys +# $Id: makewhatis.pl,v 1.10 1995/03/29 09:44:34 w Exp $ # -# Send bugs and comments to: Wolfram Schneider <wosch@cs.tu-berlin.de> sub usage { warn <<EOF; -usage: makewhatis [-verbose] [-help] [-format colum] [-name name] - [-outfile file] directory [...] +usage: makewhatis [-v|-verbose] [-h|-help] [-i|-indent colum] + [-n|-name name] [-o|-outfile file] [directories ...] EOF - exit 1; } @@ -68,27 +57,18 @@ sub open_output { if ($outfile) { # Write all Output to $outfile $whatisdb = $outfile; } else { # Use man/whatis - $dir =~ s|/$||; $whatisdb = $dir . "/$whatis_name.tmp"; } + $tmp = $whatisdb; # for signals - if (!open(A, ">> $whatisdb")) { - if ($outfile) { - die "$whatisdb: $!\n"; - } else { - warn "$whatisdb: $!\n"; $err++; - return 0; - } - } - close A; + if (!open(A, "> $whatisdb")) { + die "$whatisdb: $!\n" if $outfile; - if ($unix_sort) { - open(A, "|sort -u > $whatisdb"); - } else { - open(A, "> $whatisdb"); - @a = ''; + warn "$whatisdb: $!\n"; $err++; return 0; } - warn "Open $whatisdb\n" if $debug; + @a = (); + + warn "Open $whatisdb\n" if $verbose; select A; return 1; } @@ -97,96 +77,105 @@ sub close_output { local($success) = @_; local($w) = $whatisdb; local($counter) = 0; - + local($i, $last,@b); $w =~ s/\.tmp$//; - if ($success) { # success - if ($unix_sort) { - close A; select STDOUT; - open(R, "$whatisdb"); - while(<R>) { $counter++; } - close R; - } else { - local($i, $last,@b); - # uniq - foreach $i (sort @a) { - if ($i ne $last) { - push(@b, $i); - $counter++; - } - $last =$i; + if ($success) { # success + + # uniq + @b = (); + warn "\n" if $verbose && $pointflag; + warn "sort -u > $whatisdb\n" if $verbose; + foreach $i (sort @a) { + if ($i ne $last) { + push(@b, $i); + $counter++; } - print @b; close A; select STDOUT; + $last =$i; } + print @b; close A; select STDOUT; if (!$outfile) { rename($whatisdb, $w); - warn "Rename $whatisdb to $w\n" if $debug; + warn "Rename $whatisdb to $w\n" if $verbose; $counter_all += $counter; - warn "$counter entries in $w\n" if $debug; + warn "$counter entries in $w\n" if $verbose; } else { $counter_all = $counter; } } else { # building whatisdb failed unlink($whatisdb); - warn "building whatisdb: $whatisdb failed\n" if $debug; + warn "building whatisdb: $whatisdb failed\n" if $verbose; } return 1; } +sub parse_subdir { + local($dir) = @_; + local($file, $dev,$ino); -# find manpages (recursive) -# -# find /man/man* \( -type f -or -type l \) -print -sub find_manuals { - local(@dirlist) = @_; - local($subdir,$file,$flag,$dir); - local($m) = "man/man"; - - line: - while($dir = $dirlist[0]) { # - shift @dirlist; - $flag = 0; - $dir =~ s|/$||; - warn "traverse $dir\n" if $debug; - - if (! -e $dir) { - warn "$dir does not exist!\n"; $err++; next line; - } elsif (-d _) { - opendir(M, $dir); - # } elsif ($debug && (-f _ || -l _)) { - # allow files as arguments for testing - # return &manual($dir); - } else { - warn "$dir is not a dir\n"; $err++; next line; - } + warn "\n" if $pointflag; + warn "traverse $dir\n" if $verbose; + $pointflag = 0; - foreach $subdir (sort (readdir(M))) { - if ($subdir !~ /^(\.|\.\.)$/ && "$dir/$subdir" =~ $m) { - $flag++; - if (! -e "$dir/$subdir") { - warn "Cannot find file: $dir/$subdir\n"; $err++; - } elsif (-d _) { - &find_manuals("$dir/$subdir"); - } elsif (-f _ || -l _) { - &manual("$dir/$subdir"); - } else { - warn "Cannot find file: $dir/$subdir\n"; $err++; - } - } elsif ($subdir eq "." && $dir =~ $m) { - # Empty subdir, no manpages - $flag++; + if (!opendir(M, $dir)) { + warn "$dir: $!\n"; $err++; return 0; + } + + $| = 1 if $verbose; + foreach $file (readdir(M)) { + next if $file =~ /^(\.|\.\.)$/; + + ($dev, $ino) = ((stat("$dir/$file"))[01]); + if (-f _) { + if ($man_red{"$dev.$ino"}) { + # Link + print STDERR "+" if $verbose; + $pointflag++ if $verbose; + } else { + &manual("$dir/$file"); } + $man_red{"$dev.$ino"} = 1; + } elsif (! -d _) { + warn "Cannot find file: $dir/$file\n"; $err++; } - closedir M; - if (!$flag) { - warn <<EOF; -No subdirs found. Maybe ``$dir'' is not a ``*/man/'' dir. -Please use full path name, e. g.: makewhatis /usr/local/man -EOF - $err++; - return 0; + } + closedir M; + return 1; +} + +# read man directory +sub parse_dir { + local($dir) = @_; + local($subdir, $file); + + # clean up, in case mandir and subdirs are called simultaneously + # e. g.: ~/man/man1 ~/man/man2 ~/man + #~/man/ man1 and ~/man/man2 are a subset of ~/man + foreach $file (keys %man_red) { + delete $man_red{$file}; + } + + if ($dir =~ /man$/) { + warn "\n" if $verbose && $pointflag; + warn "open manpath directory ``$dir''\n" if $verbose; + $pointflag = 0; + if (!opendir(DIR, $dir)) { + warn "opendir ``$dir'':$!\n"; $err = 1; return 0; + } + foreach $subdir (sort(readdir(DIR))) { + if ($subdir =~ /^man\w+$/) { + $subdir = "$dir/$subdir"; + &parse_subdir($subdir); + } } + closedir DIR + + } elsif ($dir =~ /man\w+$/) { + &parse_subdir($dir); + } else { + warn "Assume ``$dir'' is not a man directory.\n"; + $err = 1; return 0; } return 1; } @@ -197,7 +186,7 @@ sub dir_redundant { local ($dev,$ino) = (stat($dir))[0..1]; if ($dir_redundant{"$dev.$ino"}) { - warn "$dir is equal to: $dir_redundant{\"$dev.$ino\"}\n" if $debug; + warn "$dir is equal to: $dir_redundant{\"$dev.$ino\"}\n" if $verbose; return 0; } $dir_redundant{"$dev.$ino"} = $dir; @@ -208,20 +197,23 @@ sub dir_redundant { # ``/usr/man/man1/foo.l'' -> ``l'' sub ext { local($filename) = @_; - local($ext) = $filename; - - $ext =~ s/\.gz$//g; - $ext =~ s/.*\///g; - - if ($ext !~ /\./) { - $ext = $filename; - $ext =~ s|/[^/]+$||; - $ext =~ s/.*(.)/\1/; - warn "$filename has no extension, try section ``$ext''\n" if $debug; + local($extension) = $filename; + + $extension =~ s/$ext$//g; # strip .gz + $extension =~ s/.*\///g; # basename + + if ($extension !~ /\./) { # no dot + $extension = $filename; + #$extension =~ s|/[^/]+$||; + $extension =~ s/.*(.)/$1/; # last character + warn "\n" if $verbose && $pointflag; + warn "$filename has no extension, try section ``$extension''\n" + if $verbose; + $pointflag = 0; } else { - $ext =~ s/.*\.//g; + $extension =~ s/.*\.//g; # foo.bla.1 -> 1 } - return "$ext"; + return "$extension"; } # ``/usr/man/man1/foo.1'' -> ``foo'' @@ -229,7 +221,7 @@ sub name { local($name) = @_; $name =~ s/.*\///g; - $name =~ s/\..*$//; + $name =~ s/\.[^.]*$//; return "$name"; } @@ -247,46 +239,54 @@ sub out { s/\\\*p//g; s/\(OBSOLETED\)[ ]?//; s/\\&//g; - s/^@INDOT@//; + s/^\@INDOT\@//; s/[\"\\]//g; #" s/[. \t-]+$//; s/ / - / unless / - /; ($man,$desc) = split(/ - /); - + $man = $name unless $man; $man =~ s/[,. ]+$//; - $man =~ s/,/($ext),/g; - $man .= "($ext)"; + $man =~ s/,/($extension),/g; + $man .= "($extension)"; $desc =~ s/^[ \t]+//; - for($i = length($man); $i< $format && $desc; $i++) { + + for($i = length($man); $i < $indent && $desc; $i++) { $man .= ' '; } - if ($desc) { $man .= "$delim$desc\n" } else { $man .= "\n" } - if ($unix_sort) { print $man } else { push(@a, $man) } + if ($desc) { + push(@a, "$man$delim$desc\n"); + } else { + push(@a, "$man\n"); + } } -# looking for NAME +# looking for NAME sub manual { local($file) = @_; - local($list, $desc, $ext); + local($list, $desc, $extension); local($ofile) = $file; # Compressed man pages - if ($ofile =~ /\.gz$/) { + if ($ofile =~ /$ext$/) { $ofile = "gzcat $file |"; + print STDERR "*" if $verbose; + } else { + print STDERR "." if $verbose; } + $pointflag++ if $verbose; if (!open(F, "$ofile")) { warn "Cannot open file: $ofile\n"; $err++; return 0; } # extension/section - $ext = &ext($file); + $extension = &ext($file); $name = &name($file); local($source) = 0; - local($l, $list); + local($list); while(<F>) { # ``man'' style pages # &&: it takes you only half the user time, regexp is slow!!! @@ -330,68 +330,138 @@ sub manual { } &out($list); close F; return 1; - } elsif(/^\.so/ && /^\.so[ \t]+man/) { + } elsif(/^\.so/ && /^\.so[ \t]+man/) { close F; return 1; - # source File - $source++; - s/[ \t]*\.so[ \t]+//; - s/[ \t\n]*$//; - local($so) = $file; - $so =~ s|/[^/]+/[^/]+$|/|; - # redundant - &manual($so . $_); - return 1; } } - warn "Maybe $file is not a manpage\n" if (!$source && $debug); + if (!$source && $verbose) { + warn "\n" if $pointflag; + warn "Maybe $file is not a manpage\n" ; + $pointflag = 0; + } return 0; } +# make relative path to absolute path +sub absolute_path { + local(@dirlist) = @_; + local($pwd, $dir, @a); + + $pwd = $ENV{'PWD'}; + foreach $dir (@dirlist) { + if ($dir !~ "^/") { + chop($pwd = `pwd`) if (!$pwd || $pwd !~ /^\//); + push(@a, "$pwd/$dir"); + } else { + push(@a, $dir); + } + } + return @a; +} + +# strip unused '/' +# e.g.: //usr///home// -> /usr/home +sub stripdir { + local($dir) = @_; + + $dir =~ s|/+|/|g; # delete double '/' + $dir =~ s|/$||; # delete '/' at end + $dir =~ s|/(\.\/)+|/|g; # delete ././././ + + $dir =~ s|/+|/|g; # delete double '/' + $dir =~ s|/$||; # delete '/' at end + $dir =~ s|/\.$||; # delete /. at end + return $dir if $dir ne ""; + return '/'; +} + +sub variables { + $verbose = 0; # Verbose + $indent = 24; # indent for description + $outfile = 0; # Don't write to ./whatis + $whatis_name = "whatis"; # Default name for DB + + # if no argument for directories given + @defaultmanpath = ( '/usr/share/man' ); + + $ext = ".gz"; # extension + umask(022); + + $err = 0; # exit code + $whatisdb = ''; + $counter_all = 0; + $dir_redundant = ''; # redundant directories + $man_red = ''; # redundant man pages + @a = (); # Array for output + + # Signals + $SIG{'INT'} = 'Exit'; + $SIG{'HUP'} = 'Exit'; + $SIG{'TRAP'} = 'Exit'; + $SIG{'QUIT'} = 'Exit'; + $SIG{'TERM'} = 'Exit'; + $tmp = ''; # tmp file + + $ENV{'PATH'} = "/bin:/usr/bin:$ENV{'PATH'}"; +} + +sub Exit { + unlink($tmp) if $tmp ne ""; # unlink if a filename + die "$0: die on signal SIG@_\n"; +} + +sub parse { + local(@argv) = @_; + local($i); + + while ($_ = $argv[0], /^-/) { + shift @argv; + last if /^--$/; + if (/^--?(v|verbose)$/) { $verbose = 1 } + elsif (/^--?(h|help|\?)$/) { &usage } + elsif (/^--?(o|outfile)$/) { $outfile = $argv[0]; shift @argv } + elsif (/^--?(f|format|i|indent)$/) { $i = $argv[0]; shift @argv } + elsif (/^--?(n|name)$/) { $whatis_name = $argv[0];shift @argv } + else { &usage } + } + + if ($i =~ /^[0-9]+$/) { + $indent = $i; + } else { + warn "Ignore wrong indent value: ``$i''\n"; + } + + return &absolute_path(@argv) if $#argv >= 0; + return @defaultmanpath if $#defaultmanpath >= 0; + + warn "Missing directories\n"; &usage; +} + ## ## Main ## -$debug = 0; # Verbose -$unix_sort = 0; # Use sort(1) instead of builtin sort -@a = ''; # Array for output if $unix_sort=0 -$outfile = 0; # Don't write to ./whatis -$whatis_name = "whatis"; # Default name for DB - -$whatisdb = ''; -$counter_all = 0; -$err = 0; -$format = 24; -$dir_redundant = ''; # - - -while ($_ = $ARGV[0], /^-/) { - shift @ARGV; - last if /^--$/; - if (/^-(debug|verbose|d|v)$/) { $debug = 1 } - elsif (/^--?(h|help|\?)$/) { &usage } - elsif (/^--?(o|outfile)$/) { $outfile = $ARGV[0]; shift @ARGV } - elsif (/^--?(f|format)$/) { $format = $ARGV[0]; shift @ARGV } - elsif (/^--?(n|name)$/) { $whatis_name = $ARGV[0]; shift @ARGV } - else { &usage } -} -&usage if $#ARGV < 0; - +&variables; # allow colons in dir: ``makewhatis dir1:dir2:dir3'' -@argv = split($", join($", (split(/:/, join($", @ARGV))))); #" +@argv = &parse(split(/[: ]/, join($", @ARGV))); # " + if ($outfile) { - if(&open_output($outfile)){ - foreach $dir (@argv) { &dir_redundant($dir) && &find_manuals($dir); } + if(&open_output($outfile)){ + foreach $dir (@argv) { + $dir = &stripdir($dir); + &dir_redundant($dir) && &parse_dir($dir); + } } &close_output(1); } else { foreach $dir (@argv) { - &dir_redundant($dir) && - &close_output(&open_output($dir) && &find_manuals($dir)); + $dir = &stripdir($dir); + &dir_redundant($dir) && + &close_output(&open_output($dir) && &parse_dir($dir)); } } -warn "Total entries: $counter_all\n" if $debug && ($#argv > 0 || $outfile); +warn "Total entries: $counter_all\n" if $verbose && ($#argv > 0 || $outfile); exit $err; - |