#!/bin/sh # mkcat 1.30.3 (Sat 20 Jun 1998) # Adam M. Costello # # To be used instead of Solaris 2.[23] catman for five reasons: # # 1) Sometimes catman dumps core. # 2) catman calls nroff with the -u0 option, which makes font 3 # not bold. mkcat uses -u1. (-un causes a character to be # overstruck n times to achieve the bold effect.) # 3) Sometimes catman leaves things out of the windex database. # 4) catman puts the title of the man page in the second field, but # mkcat puts the filename (without the suffix), a more useful piece # of information. (The two are usually the same, but not always.) # 5) catman creates an entry for each name in the NAME section of a man # page, but if a file doesn't exist with that name, man will fail. # mkcat, after creating windex, creates the missing files. # # I don't know which, if any, of these problems still exist in Solaris # 2.6. # # If the CATMANW environment variable is set, mkcat will call catman to # create windex. It's much faster, but less accurate. NROFF="nroff -Tlp -u1" export NROFF cwd=`pwd` usage() { echo "Usage:" echo "mkcat [-nw] -M man_directory" exit } mandir= nroff=nroff windex=windex debug= while getopts nwM:D opt; do case $opt in n) windex= ;; w) nroff= ;; M) mandir=$OPTARG ;; D) debug=debug ;; \?) usage ;; esac done [ -n "$mandir" ] || { echo "$0: missing option -- M" usage } [ -n "$windex$nroff" ] || { echo "$0: incompatible options -- nw" usage } [ -n "${CATMANW+X}" ] && [ -n "$windex" ] && windex=fastwindex cd $mandir [ "$windex" = fastwindex ] && /usr/bin/catman -M . -w [ "$windex" = windex ] && { manfiles=`echo man*/*` [ "$manfiles" != 'man*/*' ] && { nawk ' function printentry() { gsub("\t", " ", namesect) gsub("\\\\([ 0^adprtu|]|[bhlLovwx]`[^'\'']*'\'')", " ", namesect) gsub("\\\\([&!ez{}]|[$k].|f(\\(..|[0-9][0-9]*|[^(0-9])|s[-+0-9]*| *$)", "", namesect) gsub("\\\\([-%]|\\*-)", "-", namesect) gsub("\\\\\\(em", " - ", namesect) gsub("\\\\\\(..", "", namesect) gsub("\\\\[*n]\\(..", "", namesect) gsub("\\\\[*n].", "", namesect) gsub("\\\\", "", namesect) gsub(" *", " ", namesect) gsub("-- ", "- ", namesect) p = index(namesect, "- ") if (p != 0) { names = substr(namesect, 1, p - 1) synop = substr(namesect, p) num = split(names, name, "[, ]+") } else { names = namesect synop = "-" num = 1 } for (i = 1; i <= num; ++i) if (name[i] != "") print name[i] "\t" pagename " (" mansect ")\t" synop print pagename "\t" pagename " (" mansect ")\t" synop } /^\.TH/ { if (sect == "NAME") printentry() sect = "" namesect = "" } /^\.SH/ { if (sect == "NAME") printentry() if (NF == 1) { getline; sect = $0 } else sect = $2 gsub("\"", "", sect) if (sect == "Name") sect = "NAME" namesect = "" if (sect == "NAME") { pagename = FILENAME gsub("^.*/", "", pagename) gsub("\\.[^\\.]*$", "", pagename) mansect = FILENAME gsub("^man", "", mansect) gsub("/.*$", "", mansect) } } sect == "NAME" && ! /^\./ { gsub("\\\".*", "", $0) namesect = namesect " " $0 } END { if (sect == "NAME") printentry() } ' $manfiles | expand -16,32,40,44,48,52,56,60,64,68,72,74,76,80,84,88,92,96,100 | sort -u | unexpand -a > windex set X `nawk ' { gsub("^.", "", $3) gsub(".$", "", $3) gsub(".*/", "", $1) print "man" $3 "/" $1 "." $3, "man" $3 "/" $2 "." $3 } ' windex` shift while [ $# -ge 2 ]; do [ -f $1 ] || { echo "creating $1: .so $2" echo ".so $2" > $1 } shift 2 done } } [ -n "$nroff" ] && { tmpdir=mkcat$$ mkdir $tmpdir cat > $tmpdir/Makefile << endcat BUILD = $tmpdir/build COLON = \: endcat mansubs=`echo man*/.` if [ "$mansubs" != 'man*/.' ]; then for mansub in $mansubs; do ls -a $mansub | nawk -v mansub="$mansub" ' BEGIN { sub("\.$", "", mansub); gsub(":", "$(COLON)", mansub); catsub = mansub; sub("^man", "cat", catsub); sq = "'\''"; sp = " "; } /[ \f\r\t\013'\''$]/ { comment = "The \013 is a workaround for a bug in Solaris nawk." "It does not understand \v in regular expressions."; ++errcount; print "all: error" errcount "\n"; print "error" errcount ":"; print "\t# bad file name:", $0, "\n"; next; } ! /^\.\.?$/ { gsub(":", "$(COLON)"); print "all: " catsub $0 "\n"; print catsub $0 ": " mansub $0; print "\t@-$(BUILD) " sq mansub sq sp sq catsub sq sp sq $0 sq "\n"; } ' done >> $tmpdir/Makefile fi cat > $tmpdir/build << 'endcat' #!/bin/sh mansub=$1 catsub=$2 page=$3 manfile=$mansub$page catfile=$catsub$page echo "$catfile:" [ -d "$catsub" ] || mkdir "$catsub" remove_comments() { sed -e '/^[.'\'']\\"/ d' } extract_so() { sed -e '/^\.so[^/]*man/ !d' -e 's/^[^/]*man//' } if [ `remove_comments < "$manfile" | wc -l` -gt 1 ]; then rm -f "$catfile" echo " cat $manfile | neqn | tbl | $NROFF -man | col -x > $catfile" cat "$manfile" | neqn | tbl | $NROFF -man | col -x > "$catfile" else sopage=`extract_so < "$manfile"` if [ -n "man$sopage" ]; then rm -f "$catfile" echo " ln -s ../cat$sopage $catfile"; \ ln -s "../cat$sopage" "$catfile" else echo " I don't understand $manfile" fi fi endcat chmod +x $tmpdir/build make -f $tmpdir/Makefile && [ "$debug" != debug ] && rm -rf $tmpdir } cd $cwd