Apropos changes for 3130

Jim Diamond zsd at PIG.DREA.DND.CA
Sat Mar 11 05:38:10 AEST 1989


Recently G. Murdock Helms distributed an "apropos" program for 3000's.
Since awk (at least on my 3130) doesn't seem to act as desired by GMH
(specifically, split($0, s, "\\-") splits the line on every occurance
of "\", not just on "\-"), any lines which had other "\"s were treated
incorrectly.  I've modified his script to take care of this problem,
and to remove other nroff constructions not of interest to the "apropos" user.

It seems to work fine on my man pages (I didn't closely check them all!),
but I would appreciate being told about any problems with this version.

			Jim Diamond
			zsd at pig.drea.dnd.ca
--------------------------------------------------------------------

#!/bin/sh
#  -i is used only by cron once a week in the middle of the night
#  to build the index.  Other flags are incorrect.  Apropos
#  will only take one argument at a time.
#
# Modified by Jim Diamond (zsd at pig.drea.dnd.ca) 89/03/10 10:54:00 as follows:
# 1) Fixed bugs related to the fact that awk uses only the first character
#    of the "sep" text for "split"; thus in the old version any lines
#    containing more than one backslash were handled incorrectly.
# 2) Added sed to remove various nroff constructs.
# 3) Fixed handling of multiple (physical) line title lines.
#
# $Header: /usr/u/ssmith/RCS/apropos,v 1.3 88/06/13 12:32:15 ssmith Exp $
#
# $Log:	apropos,v $
# Revision 1.3  88/06/13  12:32:15  ssmith
# Exit with message if no arguments (used to hang grep).
# 'Unknown flag' message ( from "Usage....").
# Handle multiple args. ( 'for' loop ).
# Use of grep's exit codes--message if nothing found.
# 	grep flag from '-w' to '-i' (doug).
# Eliminated pipe to 'more' ( screwed up $?). If desired, run grep in
# 	a subshell then filter output, e.g., '| fold | more'.
# Awk properly eliminates .B's from SGI graphics manual pages.
# 
# Revision 1.2  88/06/13  12:27:37  ssmith
# test for su added 11/9/87
# 
# Revision 1.1  88/06/13  12:21:05  ssmith
# Initial revision
# 
#	
# Database:
index=/usr/local/lib/index


if [ 0 -eq $# ]
then
	echo $0 What?;
	exit; # echo "Usage: $0 [-i] [word]";
fi


for i
do
	case "$i" in 
  	-i) if [ ! -w /bin/su ] 
	    then 
			echo $USER: You must be root to build index.
			exit 1 
   	    else build=1
   	    fi
   	    break ;;
   	-*) echo Unknown flag $i;
    	exit ;;
     *) if  grep -i $i $index 
	    then
			: ok;
	   	else
		  	echo "\nNothing appropriate: $i \n";
	 	fi 
	esac
done


#  The following was written solely for the purpose of
#  getting the one line of info for apropos to use and
#  dumping it to a file an a reasonably aesthetic format.  
#  This is achieved primarily with awk, and it does not hunt
#  through the whole file and waste time.


if [ $build ]
then 
	for x in /usr/man/local/man?/*  /usr/man/?_man/man?/*
	do 
	awk '
		{name="'`expr $x : '.*/\(.*\)\..*' \| $x`'";}
	 	/^\.TH/ {ver=$3;printf("%-15s",sprintf("%s(%s)",name,ver))}
		/^\.SH NAME/ {
         	getline;
       		while ($1 !~/^.SH/)
		{
			if ($1 ~ /\.B/)
				printf("%s ", $2);
			else
				printf("%s ", $0);
			getline;
		}
		printf("\n");
		exit;
		} ' $x  

   done | sed -e "s/\\\\-/-/g" -e "s/\\\\s[+-]*[0-9]**//g" \
	-e "s/\\\\f[0-9P]//g" -e "s/\\\\(em/-/" -e "s/\\\\^//g" \
	-e "s/\\\\|//g" -e "s/  *\$//" > $index
else
	exit;
fi 

#
#  Acknowledgements:  The APROPOS clone was developed by
#  G. "Murdock" Helms, with major revisions and bug fixes
#  written by Steve Smith.   Thanks to Doug Kerr, Khanh Nguyen, 
#  and Steve Philipson for their help and suggestions. (Thanks guys!)



More information about the Comp.sys.sgi mailing list