--- man-1.5m2/src/makewhatis.sh.vns 2004-05-27 17:50:58 +0400 +++ man-1.5m2/src/makewhatis.sh 2004-05-27 17:51:12 +0400 @@ -1,8 +1,9 @@ -#!/bin/sh +#!/bin/sh -e # makewhatis: create the whatis database # Created: Sun Jun 14 10:49:37 1992 # Revised: Sat Jan 8 14:12:37 1994 by faith@cs.unc.edu # Revised: Sat Mar 23 17:56:18 1996 by micheal@actrix.gen.nz +# ALT Linux adaptations by Dmitry V. Levin # Copyright 1992, 1993, 1994 Rickard E. Faith (faith@cs.unc.edu) # May be freely distributed and modified as long as copyright is retained. # @@ -35,158 +36,128 @@ # # makewhatis aeb 030801 (from %version%) -program=`basename $0` - -# In case both /usr/man and /usr/share/man exist, the former is local -# and should be first. -# It is a bug to add /var/cache/man to DEFCATPATH. -dm= -for d in /usr/man /usr/share/man -do - if [ -d $d ]; then - if [ x$dm = x ]; then dm=$d; else dm=$dm:$d; fi - fi -done -DEFMANPATH=$dm -dc= -for d in /usr/man/preformat /usr/man /usr/share/man/preformat /usr/share/man -do - if [ -d $d ]; then - if [ x$dc = x ]; then dc=$d; else dc=$dc:$d; fi - fi -done -DEFCATPATH=$dc - -# In case /usr is read-only, make /usr/foo/whatis (etc) a symlink to -# something like /var/cache/man/foo-whatis. -# Some distributions make a single big /var/cache/man/whatis file, -# but that leads to problems and bugs. - -# AWK=/usr/bin/gawk -AWK=%awk% - -# Find a place for our temporary files. If security is not a concern, use -# TMPFILE=/tmp/whatis$$; TMPFILEDIR=none -# Of course makewhatis should only have the required permissions -# (for reading and writing directories like /usr/man). -# We try here to be careful (and avoid preconstructed symlinks) -# in case makewhatis is run as root, by creating a subdirectory of /tmp. - -TMPFILEDIR=/tmp/whatis.tmp.dir.$$ -rm -rf TMPFILEDIR -if ! mkdir -m 0700 $TMPFILEDIR; then - echo Could not create $TMPFILEDIR - exit 1; -fi -TMPFILE=$TMPFILEDIR/w - -# make sure TMPFILEDIR is deleted if program is killed or terminates -# (just delete this line if your shell doesnt know about trap) -trap "rm -rf $TMPFILEDIR" 0 1 2 3 15 - -# default find arg: no directories, no empty files -findarg0="-type f -size +0" - -topath=manpath - -defmanpath=$DEFMANPATH -defcatpath= - -sections="1 2 3 4 5 6 7 8 9 n l" - -for name in "$@" -do -if [ -n "$setsections" ]; then - setsections= - sections=$name - continue -fi -case $name in - --version|-V) - echo "$program from %version%" - exit 0;; - -c) topath=catpath - defmanpath= - defcatpath=$DEFCATPATH - continue;; - -s) setsections=1 - continue;; - -u) findarg="-ctime 0" - update=1 - continue;; - -v) verbose=1 - continue;; - -w) manpath=`man --path` - catpath=$manpath - continue;; - -*) echo "Usage: makewhatis [-u] [-v] [-w] [manpath] [-c [catpath]]" - echo " This will build the whatis database for the man pages" - echo " found in manpath and the cat pages found in catpath." - echo " -u: update database with new pages" - echo " -v: verbose" - echo " -w: use manpath obtained from \`man --path\`" - echo " [manpath]: man directories (default: $DEFMANPATH)" - echo " [catpath]: cat directories (default: the first existing" - echo " directory in $DEFCATPATH)" - exit;; - *) if [ -d $name ] - then - eval $topath="\$$topath":$name - else - echo "No such directory $name" - exit - fi;; +PROG="${0##*/}" +PATH=/bin:/usr/bin +export PATH +umask 022 + +exit_handler() +{ + local rc=$? + trap '' EXIT + [ -z "$TMPFILE" ] || rm -f "$TMPFILE" + exit $rc +} + +: ${TMPDIR:=$HOME/tmp} +[ -d "$TMPDIR" ] || TMPDIR=/tmp +TMPFILE=`/bin/mktemp -t "$PROG.XXXXXXXXXX"` + +trap exit_handler SIGHUP SIGPIPE SIGINT SIGQUIT SIGTERM EXIT + +[ ! -s /etc/profile.d/lang.sh ] || . /etc/profile.d/lang.sh +DEFMANPATH=`man --path` + +SECTIONS="1 8 2 3 4 5 6 7 9 tcl n l p o" + +USAGE() +{ + cat >&2 <&2; exit 1 + ;; esac done -manpath=`echo ${manpath-$defmanpath} | tr : ' '` -if [ x"$catpath" = x ]; then - for d in `echo $defcatpath | tr : ' '` - do - if [ -d $d ]; then catpath=$d; break; fi - done +if [ -n "$*" ]; then + manpath="$*" +else + manpath=`echo "$DEFMANPATH" |tr : \ ` fi -catpath=`echo ${catpath} | tr : ' '` # first truncate all the whatis files that will be created new, # then only update - we might visit the same directory twice -if [ x$update = x ]; then - for pages in man cat - do - eval path="\$$pages"path - for mandir in $path - do - cp /dev/null $mandir/whatis - done +if [ -z "$update" ]; then + for mandir in $manpath; do + [ -d "$mandir" ] || continue + [ "$mandir" != "/usr/man" ] || continue + if [ -z "${mandir##/usr/share/man*}" ]; then + mandir="${mandir/\/usr\/share\/man//var/cache/man}" + elif [ "$mandir" == /usr/X11R6/man ]; then + mandir=/var/cache/man/X11R6 + elif [ "$mandir" == /usr/lib/perl5/man ]; then + mandir=/var/cache/man/perl + elif [ "$mandir" == /usr/local/man ]; then + mandir=/var/cache/man/local + fi + [ -d "$mandir" ] || continue + :>$mandir/whatis done fi -for pages in man cat -do - export pages - eval path="\$$pages"path - for mandir in $path - do - if [ x$verbose != x ]; then - echo "about to enter $mandir" > /dev/stderr - fi - if [ -s ${mandir}/whatis -a $pages = man -a x$update = x ]; then - if [ x$verbose != x ]; then - echo skipping $mandir - we did it already > /dev/stderr +for mandir in $manpath; do + [ -d "$mandir" ] || continue + [ "$mandir" != "/usr/man" ] || continue + if [ -z "${mandir##/usr/share/man*}" ]; then + destdir="${mandir/\/usr\/share\/man//var/cache/man}" + elif [ "$mandir" == /usr/X11R6/man ]; then + destdir=/var/cache/man/X11R6 + elif [ "$mandir" == /usr/lib/perl5/man ]; then + destdir=/var/cache/man/perl + elif [ "$mandir" == /usr/local/man ]; then + destdir=/var/cache/man/local + else + destdir="$mandir" + fi + [ -d "$destdir" ] || continue + + if [ -n "$verbose" ]; then + echo "about to enter $mandir" >&2 fi - else - here=`pwd` - cd $mandir - for i in $sections - do - if [ -d ${pages}$i ] - then - cd ${pages}$i - section=$i - curdir=$mandir/${pages}$i - export section verbose curdir - find $mandir/${pages}$i/. -name '*' $findarg0 $findarg -print | $AWK ' + if [ -z "$update" -a -s "$destdir/whatis" ]; then + if [ -n "$verbose" ]; then + echo "skipping $mandir - we did it already" >&2 + fi + else + here=$PWD + cd "$mandir" + for i in $SECTIONS; do + if [ -d "man$i" ]; then + cd "man$i" + export section=$i + export curdir="$mandir/man$i" + find -type f -name '*.*' $findarg $deffindarg -print | gawk ' function readline() { if (use_zcat || use_bzcat) { result = (pipe_cmd | getline); @@ -218,11 +189,10 @@ print "adding " filename > "/dev/stderr" } + use_bzcat = (filename ~ /\.bz2$/); use_zcat = match(filename,"\\.Z$") || match(filename,"\\.z$") || match(filename,"\\.gz$"); - if (!use_zcat) - use_bzcat = match(filename,"\\.bz2"); - if (use_zcat || use_bzcat) { + if(use_zcat) { filename_no_gz = substr(filename, 0, RSTART - 1); } else { filename_no_gz = filename; @@ -235,29 +205,31 @@ actual_section = section; } sub(/\..*/, "", progname); - if (use_zcat || use_bzcat) { - if (use_zcat) { - pipe_cmd = "zcat \"" filename "\""; - } else { - pipe_cmd = "bzcat \"" filename "\""; - } - # try to avoid suspicious stuff - if (filename ~ /[;&|`$(]/) { - print "ignored strange file name " filename " in " curdir > "/dev/stderr"; - return; - } + # try to avoid suspicious stuff + if (filename ~ /[;&|`$(]/) { + print "ignored strange file name " filename " in " curdir > "/dev/stderr"; + return; + } + pattern="[\\&;()<>!|{}$?*`\"'\'' ]" + if (use_zcat) { + pipe_cmd = filename; + gsub(pattern, "\\\\&", pipe_cmd); + pipe_cmd = "zcat " pipe_cmd; + } else if (use_bzcat) { + pipe_cmd = filename; + gsub(pattern, "\\\\&", pipe_cmd); + pipe_cmd = "bzcat " pipe_cmd; } while (!done && readline() > 0) { gsub(/.\b/, ""); if (($1 ~ /^\.[Ss][Hh]/ && ($2 ~ /[Nn][Aa][Mm][Ee]/ || - $2 ~ /^JMÉNO/ || $2 ~ /^NAVN/ || $2 ~ /^NUME/ || + $2 ~ /[éÉ][íÍ][ñÑ]/ || $2 ~ /[îÎ][áÁ][úÚ][÷×][áÁ][îÎ][éÉ][åÅ]/ || + $2 ~ /^JMÉNO/ || $2 ~ /^NAVN/ || $2 ~ /^BEZEICHNUNG/ || $2 ~ /^NOMBRE/ || $2 ~ /^NIMI/ || $2 ~ /^NOM/ || $2 ~ /^IME/ || - $2 ~ /^N[ÉE]V/ || $2 ~ /^NAMA/ || $2 ~ /^̾Á°/ || - $2 ~ /^̾¾Î/ || $2 ~ /^À̸§/ || $2 ~ /^NAZWA/ || - $2 ~ /^îáú÷áîéå/ || $2 ~ /^Ãû³Æ/ || $2 ~ /^¦WºÙ/ || + $2 ~ /^N[ÉE]V/ || $2 ~ /^NAMA/ || $2 ~ /^NOME/ || $2 ~ /^NAAM/)) || (pages == "cat" && $1 ~ /^NAME/)) { if (!insh) { @@ -389,30 +361,11 @@ ' pages=$pages section=$section verbose=$verbose curdir=$curdir cd .. fi - done > $TMPFILE - - cd $here + done > "$TMPFILE" - # kludge for Slackware's /usr/man/preformat - if [ $mandir = /usr/man/preformat ] - then - mandir1=/usr/man - else - mandir1=$mandir - fi - - if [ -f ${mandir1}/whatis ] - then - cat ${mandir1}/whatis >> $TMPFILE - fi - sed '/^$/d' < $TMPFILE | sort | uniq > ${mandir1}/whatis + cd "$here" - chmod 644 ${mandir1}/whatis - rm $TMPFILE + [ ! -s "$destdir/whatis" ] || cat "$destdir/whatis" >> "$TMPFILE" + sed '/^$/d' < "$TMPFILE" | LC_COLLATE=C sort -u > "$destdir/whatis" fi done -done - -# remove tempdir -rm -rf $TMPFILEDIR -