| 1 |
diff -up man-1.6f/src/makewhatis.sh.i18n_makewhatis man-1.6f/src/makewhatis.sh
|
| 2 |
--- man-1.6f/src/makewhatis.sh.i18n_makewhatis 2007-09-17 20:35:14.000000000 +0200
|
| 3 |
+++ man-1.6f/src/makewhatis.sh 2008-09-01 16:06:05.000000000 +0200
|
| 4 |
@@ -1,4 +1,4 @@
|
| 5 |
-#!/bin/sh
|
| 6 |
+#!/bin/bash
|
| 7 |
# makewhatis: create the whatis database
|
| 8 |
# Created: Sun Jun 14 10:49:37 1992
|
| 9 |
# Revised: Sat Jan 8 14:12:37 1994 by faith@cs.unc.edu
|
| 10 |
@@ -61,32 +61,19 @@ do
|
| 11 |
done
|
| 12 |
DEFCATPATH=$dc
|
| 13 |
|
| 14 |
-# In case /usr is read-only, make /usr/foo/whatis (etc) a symlink to
|
| 15 |
-# something like /var/cache/man/foo-whatis.
|
| 16 |
-# Some distributions make a single big /var/cache/man/whatis file,
|
| 17 |
-# but that leads to problems and bugs.
|
| 18 |
+# make a single big /var/cache/man/whatis file,
|
| 19 |
+DEFWHATIS=/var/cache/man/whatis
|
| 20 |
|
| 21 |
-# AWK=/usr/bin/gawk
|
| 22 |
AWK=@awk@
|
| 23 |
|
| 24 |
-# Find a place for our temporary files. If security is not a concern, use
|
| 25 |
-# TMPFILE=/tmp/whatis$$; TMPFILEDIR=none
|
| 26 |
-# Of course makewhatis should only have the required permissions
|
| 27 |
-# (for reading and writing directories like /usr/man).
|
| 28 |
-# We try here to be careful (and avoid preconstructed symlinks)
|
| 29 |
-# in case makewhatis is run as root, by creating a subdirectory of /tmp.
|
| 30 |
-
|
| 31 |
-TMPFILEDIR=/tmp/whatis.tmp.dir.$$
|
| 32 |
-rm -rf $TMPFILEDIR
|
| 33 |
-if ! mkdir -m 0700 $TMPFILEDIR; then
|
| 34 |
- echo Could not create $TMPFILEDIR
|
| 35 |
- exit 1;
|
| 36 |
-fi
|
| 37 |
-TMPFILE=$TMPFILEDIR/w
|
| 38 |
+# Find a place for our temporary files.
|
| 39 |
+
|
| 40 |
+if TMPFILE=$(mktemp /tmp/whatis.XXXXXX)
|
| 41 |
+then
|
| 42 |
|
| 43 |
-# make sure TMPFILEDIR is deleted if program is killed or terminates
|
| 44 |
+# make sure TMPFILE is deleted if program is killed or terminates
|
| 45 |
# (just delete this line if your shell doesnt know about trap)
|
| 46 |
-trap "rm -rf $TMPFILEDIR" 0
|
| 47 |
+trap "rm -rf $TMPFILE" 0
|
| 48 |
trap "rm -rf $TMPFILEDIR; exit 255" 1 2 3 15
|
| 49 |
|
| 50 |
# default find arg: no directories, no empty files
|
| 51 |
@@ -98,15 +85,17 @@ defmanpath=$DEFMANPATH
|
| 52 |
defcatpath=
|
| 53 |
|
| 54 |
if [ -n "$MANSECT" ]; then
|
| 55 |
- sections=$MANSECT
|
| 56 |
+ sections=$MANSECT
|
| 57 |
else
|
| 58 |
- sections=`$AWK '($1 == "MANSECT") { print $2 }' @man_config_file@`
|
| 59 |
- if [ x"$sections" = x ]; then
|
| 60 |
- sections="@sections@"
|
| 61 |
- fi
|
| 62 |
+ sections=`$AWK '($1 == "MANSECT") { print $2 }' @man_config_file@`
|
| 63 |
+ if [ x"$sections" = x ]; then
|
| 64 |
+ sections="@sections@"
|
| 65 |
+ fi
|
| 66 |
fi
|
| 67 |
sections=`echo $sections | sed -e 's/:/ /g'`
|
| 68 |
|
| 69 |
+whatisdb=$DEFWHATIS
|
| 70 |
+
|
| 71 |
for name in "$@"
|
| 72 |
do
|
| 73 |
if [ -n "$setsections" ]; then
|
| 74 |
@@ -114,6 +103,11 @@ if [ -n "$setsections" ]; then
|
| 75 |
sections=$name
|
| 76 |
continue
|
| 77 |
fi
|
| 78 |
+if [ -n "$setwhatis" ]; then
|
| 79 |
+ setwhatis=
|
| 80 |
+ whatisdb=$name
|
| 81 |
+ continue
|
| 82 |
+fi
|
| 83 |
case $name in
|
| 84 |
--version|-V)
|
| 85 |
echo "$program from @version@"
|
| 86 |
@@ -124,6 +118,8 @@ case $name in
|
| 87 |
continue;;
|
| 88 |
-s) setsections=1
|
| 89 |
continue;;
|
| 90 |
+ -o) setwhatis=1
|
| 91 |
+ continue;;
|
| 92 |
-u) findarg="-ctime 0"
|
| 93 |
update=1
|
| 94 |
continue;;
|
| 95 |
@@ -132,12 +128,13 @@ case $name in
|
| 96 |
-w) manpath=`man --path`
|
| 97 |
catpath=$manpath
|
| 98 |
continue;;
|
| 99 |
- -*) echo "Usage: makewhatis [-s sections] [-u] [-v] [-w] [manpath] [-c [catpath]]"
|
| 100 |
+ -*) echo "Usage: makewhatis [-s sections] [-u] [-v] [-w] [manpath] [-c [catpath]] [-o whatisdb]"
|
| 101 |
echo " This will build the whatis database for the man pages"
|
| 102 |
echo " found in manpath and the cat pages found in catpath."
|
| 103 |
echo " -s: sections (default: $sections)"
|
| 104 |
echo " -u: update database with new pages"
|
| 105 |
echo " -v: verbose"
|
| 106 |
+ echo " -o: location of whatis database (default: $DEFWHATIS)"
|
| 107 |
echo " -w: use manpath obtained from \`man --path\`"
|
| 108 |
echo " [manpath]: man directories (default: $DEFMANPATH)"
|
| 109 |
echo " [catpath]: cat directories (default: the first existing"
|
| 110 |
@@ -165,14 +162,7 @@ catpath=`echo ${catpath} | tr : ' '`
|
| 111 |
# first truncate all the whatis files that will be created new,
|
| 112 |
# then only update - we might visit the same directory twice
|
| 113 |
if [ x$update = x ]; then
|
| 114 |
- for pages in man cat
|
| 115 |
- do
|
| 116 |
- eval path="\$$pages"path
|
| 117 |
- for mandir in $path
|
| 118 |
- do
|
| 119 |
- cp /dev/null $mandir/whatis
|
| 120 |
- done
|
| 121 |
- done
|
| 122 |
+ cp /dev/null $whatisdb
|
| 123 |
fi
|
| 124 |
|
| 125 |
for pages in man cat
|
| 126 |
@@ -212,11 +202,6 @@ do
|
| 127 |
fi
|
| 128 |
fi
|
| 129 |
|
| 130 |
- if [ -s ${mandir}/whatis -a $pages = man -a x$update = x ]; then
|
| 131 |
- if [ x$verbose != x ]; then
|
| 132 |
- echo skipping $mandir - we did it already > /dev/stderr
|
| 133 |
- fi
|
| 134 |
- else
|
| 135 |
here=`pwd`
|
| 136 |
cd $mandir
|
| 137 |
for i in $sections
|
| 138 |
@@ -227,7 +212,23 @@ do
|
| 139 |
section=$i
|
| 140 |
curdir=$mandir/${pages}$i
|
| 141 |
export section verbose curdir
|
| 142 |
- find $mandir/${pages}$i/. -name '*' $findarg0 $findarg -print | $AWK '
|
| 143 |
+
|
| 144 |
+ utf8=
|
| 145 |
+ for x in $(find $mandir/${pages}$i -name '*' $findarg0 $findarg)
|
| 146 |
+ do
|
| 147 |
+ if [ ${x%.gz} != ${x} ]
|
| 148 |
+ then
|
| 149 |
+ cat=zcat
|
| 150 |
+ elif [ ${x%.bz2} != ${x} ]
|
| 151 |
+ then
|
| 152 |
+ cat=bzcat
|
| 153 |
+ else
|
| 154 |
+ cat=cat
|
| 155 |
+ fi
|
| 156 |
+
|
| 157 |
+ if ${cat} ${x} | iconv -f utf-8 -t utf-8 -o /dev/null 2>/dev/null
|
| 158 |
+ then
|
| 159 |
+ echo ${x} | $AWK '
|
| 160 |
|
| 161 |
function readline() {
|
| 162 |
if (use_zcat || use_bzcat || use_lzcat) {
|
| 163 |
@@ -439,18 +440,19 @@ do
|
| 164 |
|
| 165 |
cd "$here"
|
| 166 |
|
| 167 |
- if [ -f ${mandir1}/whatis ]
|
| 168 |
+ if [ -f ${whatisdb} ]
|
| 169 |
then
|
| 170 |
- cat ${mandir1}/whatis >> $TMPFILE
|
| 171 |
+ cat ${whatisdb} >> $TMPFILE
|
| 172 |
fi
|
| 173 |
- tr -s '\n' < $TMPFILE | sort -u > ${mandir1}/whatis
|
| 174 |
+ tr -s '\n' < $TMPFILE | sort -u > ${whatisdb}
|
| 175 |
|
| 176 |
- chmod 644 ${mandir1}/whatis
|
| 177 |
- rm $TMPFILE
|
| 178 |
- fi
|
| 179 |
+ chmod 644 ${whatisdb}
|
| 180 |
done
|
| 181 |
done
|
| 182 |
|
| 183 |
# remove tempdir
|
| 184 |
-rm -rf $TMPFILEDIR
|
| 185 |
+rm -rf $TMPFILE
|
| 186 |
|
| 187 |
+else # we're here if TMPFILE creation failed
|
| 188 |
+ exit 1
|
| 189 |
+fi
|