apropos for the 4D (not an official product of SGI)

Dave Ciemiewicz ciemo at bananapc.SGI.COM
Thu Mar 9 06:33:54 AEST 1989


WHAT IT IS
==========
Attached is a shell archive (shar file) containing two scripts which mimic
the functionality of BSD "apropos" on an IRIS 4D (Sorry, no man pages).
These scripts are not designed to be run on a 2/3000 series IRIS.

CAVEAT EMPTOR, DISCLAIMERS, ET CETERA
=====================================
The implementation of these scripts has been my own personal undertaking and
they do not constitute an "official" SGI product.  These apropos scripts may
or may not be shipped with future SGI products.  If apropos is supported in
future IRIS 4D software releases, it may or may not be in the form of these
two scripts.  Future products may be incompatible with these scripts.

These scripts are being released "AS IS".  DO NOT CALL THE GEOMETRY HOTLINE
IF YOU HAVE PROBLEMS.  The scripts are completely unsupported.  To quote
Robin Williams from his "Reality, What a Concept" album, "You're on your own.
Goodbye!"

I will consider comments but I make no promises to support these scripts
in the future.

INSTRUCTIONS
============
1)  Using your favorite editor (vi, emacs, et cetera), cut out the shell
    archive (shar) indicated by "CUT HERE" and write it to the file
    "apropos.shar" in your personal bin directory or /usr/local/bin.

2)  Unpack the archive to create "apropos" and "mkwhatis".

	sh apropos.shar		# I always think of this as "just add water"

    I have not included any manual pages but the scripts document themselves.
    Really.

3)  Run "mkwhatis" to create /usr/catman/whatis.  You must do this as root.

	su
	mkwhatis
	
    NOTE: mkwhatis takes 10-15 minutes to "do it's thang".  Grab some coffee
    or do work in one of your other 4Sight windows.  You will need to rerun
    mkwhatis if you install any new options on your system.

4)  "apropos" to your heart's content.  For example, "apropos nfs" yields:

	exportfs (1M)           - export and unexport directories to NFS clients
	exports (4)             - list of NFS filesystems being exported
	mountd (1M)             - NFS mount request server
	nfsd, biod (1M)         - NFS daemons
	nfsmount (2)            - mount an NFS file system
	nfsstat (1M)            - display Network File System statistics
	nfssvc, async_daemon (2) - NFS daemons

Have fun.

					--- Ciemo

----- CUT HERE ----------------------------------------------------------------
# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by ciemo on Wed Mar  8 12:13:58 PST 1989
# Contents:  apropos mkwhatis
 
echo x - apropos
sed 's/^@//' > "apropos" <<'@//E*O*F apropos//'
#! /bin/sh

#
#  NAME
#	apropos - find the apropriate manual pages for a give keyword
#
#  SYNOPSIS
#	apropos keyword [...]
#
#  DESCRIPTION
#	apropos searches its database of manual page descriptions
#	for those which match the specified keywords.  The search
#	provided is an implied "or" of the keywords.
#
#	apropos uses a database called whatis located in the manual
#	page tree.  This database is created using the tool mkwhatis(1).
#
#	This functionality of this version is based on William Joy's
#	version from UC Berkeley.
#
#  SEE ALSO
#	mkwhatis(1)
#  
#  FILES
#	/usr/catman/whatis
#
#  CAVEATS
#	Since apropos gets its information from a "static" database, it
#	is possible for apropos to report the existence of manual pages
#	which are not on the system.
#
#  AUTHOR
#	Dave Ciemiewicz (ciemo)
#
#  COPYRIGHT (C) 1989, Silicon Graphics, Inc., All rights reserved.
#	This file is not a product of Silicon Graphics, Inc. and is
#	provided for unrestricted use provided that this legend is
#	included on all tape media and as a part of the software
#	program in whole or part.  Users may copy or modify this file
#	without charge, but are not authorized to license or distribute
#	it to anyone else except as part of a product or program
#	developed by the user.
#
#	THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND
#	INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
#	FOR A PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING,
#	USAGE OR TRADE PRACTICE.
#
#	This file is provided with no support and without any
#	obligation on the part of Silicon Graphics, Inc. to assist in
#	its use, correction, modification or enhancement.
#
#	SILICON GRAPHICS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO
#	THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
#	THIS FILE OR ANY PART THEREOF.
#
#	In no event will Silicon Graphics, Inc. be liable for any lost
#	revenue or profits or other special, indirect and consequential
#	damages, even if Silicon Graphics has been advised of the
#	possibility of such damages.
#

USAGE="Usage: apropos keyword [...]"
WHATIS=/usr/catman/whatis

if test $# -eq 0; then
    echo $USAGE 1>&2
    exit 2
fi

if test ! -r $WHATIS; then
    echo $0": can't open "$WHATIS 1>&2
    exit 1
fi

for keyword in $*
do
    grep -i '^'$keyword $WHATIS			# At the beginning of a line
    grep -i '[^a-zA-Z0-9_]'$keyword $WHATIS	# Anywhere else in line
done | sort -u
@//E*O*F apropos//
chmod u=rwx,g=rx,o=rx apropos
 
echo x - mkwhatis
sed 's/^@//' > "mkwhatis" <<'@//E*O*F mkwhatis//'
#! /bin/sh

#
#  NAME
#	mkwhatis - make manual page "whatis" database for use with apropos
#
#  SYNOPSIS
#	mkwhatis [filename]
#
#  DESCRIPTION
#	mkwhatis scans the preformatted manual page trees (/usr/catman),
#	parses the manual pages, and strips out the NAME section information
#	to create the "whatis" database used by apropos(1).
#
#	By default, mkwhatis creates the file, /usr/catman/whatis.  Another
#	file may be created as the database by specifying its filename on
#	the command line.  You must run mkwhatis as root to create the
#	whatis file.  See su(1M).
#
#	The format of the whatis file created is based on that used by
#	William Joy's UC Berkeley version of apropos.
#
#  SEE ALSO
#	apropos(1)
#  
#  FILES
#	/usr/catman/whatis
#
#  CAVEATS
#	This program is S...L...O...W.  Expect execution times of about
#	10-15 minutes.  The reason is that EVERY manual page on the system
#	is read.
#
#	You must run mkwhatis as root.
#
#  AUTHOR
#	Dave Ciemiewicz (ciemo)
#
#  COPYRIGHT (C) 1989, Silicon Graphics, Inc., All rights reserved.
#	This file is a not product of Silicon Graphics, Inc. and is
#	provided for unrestricted use provided that this legend is
#	included on all tape media and as a part of the software
#	program in whole or part.  Users may copy or modify this file
#	without charge, but are not authorized to license or distribute
#	it to anyone else except as part of a product or program
#	developed by the user.
#
#	THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND
#	INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
#	FOR A PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING,
#	USAGE OR TRADE PRACTICE.
#
#	This file is provided with no support and without any
#	obligation on the part of Silicon Graphics, Inc. to assist in
#	its use, correction, modification or enhancement.
#
#	SILICON GRAPHICS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO
#	THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
#	THIS FILE OR ANY PART THEREOF.
#
#	In no event will Silicon Graphics, Inc. be liable for any lost
#	revenue or profits or other special, indirect and consequential
#	damages, even if Silicon Graphics has been advised of the
#	possibility of such damages.
#

USAGE="Usage: mkwhatis [filename]"
WHATIS=/usr/catman/whatis

case $# in
    0)	;;
    1)	WHATIS=$1;;
    *)  echo $USAGE 1>&2
	exit 2
	;;
esac

cd /usr/catman
find * -type "f" -print | while read f
do
	pcat $f | col -b |
	sed -e 's/	/ /g' -e 's/  */ /g' -e 's/^ *//' |
	nawk '
		BEGIN		{name=0; count=0}

		$1 ~ /[0-9a-zA-Z_]+\([1-8][a-zA-Z]*\)/ {
			match($1, /\([1-8][a-zA-Z]*\)/)
			section = substr($1, RSTART, RLENGTH)
			next
		}

		$1 ~ /NAME/		{name=1; next}

		$1 ~ /SYNOPSIS|SY.*SIS/	{finish()}
						# SYNOPSIS is a common typo
		$2 ~ /SYNOPSIS|SY.*SIS/	{finish()}
						# SYNOPSIS is a common typo
		$1 ~ /DESCRIPTION/	{finish()}
		$2 ~ /SPECIFICATION/	{finish()}

		/^[ \t]*$/	{next}

		{
			if (name==1) nametext = nametext " " $0
			next
		}

		function finish() {
		    if (filenm ~ /g_man/) section="(3G)"
						# No section on GL man pages

		    partscount = split(nametext, parts, " -")
		    printf "%-24s", parts[1] " " section
		    for (i=2; i<=partscount; i++) {
			printf " -%s", parts[i]
		    }
		    printf "\n"
		    exit
		}
	' filenm=$f
done | sed -e 's/\([A-Za-z]\)- \([A-Za-z]\)/\1\2/g' -e 's/^ *//' |
sort -u > $WHATIS
@//E*O*F mkwhatis//
chmod u=rwx,g=rx,o=rx mkwhatis
 
exit 0
----- CUT HERE ----------------------------------------------------------------
--

Dave	   (commonplace)		"Boldly going where no one cares to go."
Ciemiewicz (incomprehensible)
ciemo 	   (infamous)



More information about the Comp.sys.sgi mailing list