[comp.sys.pyramid] Tried of 'man -k' not working on OSx4.4???

hoyt@polyslo.UUCP (Sir Hoyt) (07/28/88)

	All of you out there who have upgraded OSx 4.4 by now know
	that 'man -k' no longer works in the BSD universe.  After
	some bitching at Pyramid, and finding out what they thought of the
	problem ( not much ... ) I decided to fix it.  Included here
	is a shell script and C program that will build the /usr/man/whatis
	file.  

	The shell script is a striped down version of /usr/lib/makewhatis,
	now called 'makewhatitbe'.  The C program, called 'whatitbe', is
	something I whipped up in a few hours.

	Details on how to use them can be found at the beging of whatitbe.c .


		--John
		  hoyt@polyslo.CalPoly.EDU	( We finaly got a Domain! )

-------------- CUT HERE ---------------------- CUT HERE ------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	makewhatitbe
#	whatitbe.c
# This archive created: Wed Jul 27 21:34:56 1988
# By:	Sir Hoyt (WanderLand, San Luis Obispo)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'makewhatitbe'" '(276 characters)'
if test -f 'makewhatitbe'
then
	echo shar: will not over-write existing file "'makewhatitbe'"
else
sed 's/^	X//' << \SHAR_EOF > 'makewhatitbe'
	XPATH=/bin:/usr/bin:/usr/.ucbucb
	Xdirs=${1-12345678lno}
	X
	Xcd /usr/man
	Xfor i in cat[$dirs]; do
	X	(cd $i; /usr/local/src/whatitbe/whatitbe `ls` )
	Xdone |
	Xexpand -24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176 |
	Xsort -u |
	Xunexpand -a |
	Xcol -h > /usr/man/whatis
SHAR_EOF
if test 276 -ne "`wc -c < 'makewhatitbe'`"
then
	echo shar: error transmitting "'makewhatitbe'" '(should have been 276 characters)'
fi
chmod +x 'makewhatitbe'
fi # end of overwriting check
echo shar: extracting "'whatitbe.c'" '(3830 characters)'
if test -f 'whatitbe.c'
then
	echo shar: will not over-write existing file "'whatitbe.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'whatitbe.c'
	X/*
	X * whatitbe
	X *
	X *	Does what /usr/lib/getNAME does to troff source, but only
	X *	to troff output. i.e.  deals with /usr/man/cat* instead of
	X *	/usr/man/man* .
	X *
	X * How to use:
	X *	usage:
	X *		whatitbe file [ file ... ]
	X *
	X * To create whatis data file:
	X *	1) Complile whatitbe: cc -o whatitbe whatitbe.c :-)
	X *	2) Edit the included shell script 'makewhatitbe'
	X *		so that it can find 'whatitbe'.
	X *	3) Run 'makewhatitbe'. Please note: when you run 'makewhatitbe'
	X *		you must be able to write into /usr/man .
	X *	4) Try it out, and see if 'man -k' works.
	X *
	X *
	X *	Author:  John H. Pochmara
	X *	Address: hoyt@polyslo.CalPoly.EDU
	X *
	X */
	X
	X#include <stdio.h>
	X#include <strings.h>
	X
	X#define TRUE		(1)
	X#define FALSE		(0)
	X
	X#define POPEN_FORMAT	"/usr/ucb/zcat %s"
	X
	X#define BUFSIZE		(1024)
	X
	Xextern int errno;
	X
	Xmain( argc, argv)
	Xint argc;
	Xchar *argv[];
	X{
	X	char buf[BUFSIZE];
	X	FILE *fp;
	X	int done = FALSE;
	X	char name[BUFSIZE];
	X	char des[BUFSIZE];
	X	char *pcmd[BUFSIZE];
	X	char *sec;
	X
	X	if( argc < 1 ) {
	X		fprintf(stderr, "usage: whatitbe file [ file ... ]\n");
	X		exit(1);
	X	}
	X
	X	while( argc-- > 1 ) {		/* do all of the files */
	X		
	X		done = FALSE;
	X
	X		/*
	X		 * get read to uncompress the things.
	X		 */
	X		sprintf( pcmd, POPEN_FORMAT, argv[argc] );	
	X		
	X		if((fp = (FILE *)popen( pcmd , "r" )) == NULL ) {
	X			perror("whatitbe: popen fialed");
	X			exit(1);
	X			continue;
	X		}
	X
	X		/*
	X		 * get the section number.
	X		 */
	X		sec = (char *)rindex( argv[argc] , '.' );
	X		*sec = NULL;
	X		sec = (char *)rindex( argv[argc] , '.' );
	X		sec++;
	X
	X		/*
	X		 * Now get the description.
	X		 */
	X		while( ( fgets( buf, BUFSIZE, fp ) != NULL ) && !done ) {
	X
	X			if( strcmp( buf, "NAME\n" ) == 0 ) {
	X				getname( fp, name );
	X				getdes( fp, des );
	X				clean( name );
	X				clean( des );
	X				printf("%s (%s)\t\t- %s\n", name, sec, des );
	X				fflush( stdout );
	X				done = TRUE;
	X			}
	X		}
	X
	X		pclose( fp );
	X	}
	X}
	X
	X/*
	X * clean
	X *	Converts tabs into spaces and removes trailing
	X *	spaces.
	X *
	X */
	Xclean( str )
	Xchar *str;
	X{
	X
	X	/*
	X	 * Do in the tabs...
	X	 */
	X	while( *str != NULL ) {
	X		if( *str == '\t' ) 
	X			*str = ' ';
	X		str++;
	X	}
	X
	X	/*
	X	 * ... Now get the spaces.
	X	 */
	X	while( *--str == ' ' ) {
	X		*str = NULL;
	X	}
	X
	X}
	X
	X/*
	X * getname
	X *	Get the 'name' from fp.
	X *	'name' is consider to be everything up to a '-' or ':' .
	X *
	X */
	Xgetname( fp , d ) 
	XFILE *fp;
	Xchar *d;
	X{
	X	int c = 0;	/* current char */
	X	int lc = 0;	/* last-char */
	X	int i = 0;	/* index into d */
	X
	X	/*
	X	 * Burn off leading white-space.
	X	 */
	X	while( ( ( c = fgetc( fp ) ) == ' ' ) || ( c == '\t' ) ) ;
	X
	X	ungetc( c , fp );
	X
	X	/*
	X	 * Read until '-' or ':'
	X	 */
	X	while( ( c = fgetc( fp ) ) != EOF ) {
	X		if( ( c == '-') || ( c == ':' ) ) {
	X			d[i] = NULL;
	X			return;
	X		}
	X
	X		/*
	X		 * Due away with multiple spaces.
	X		 *   note: '\n' is consider a space.
	X		 */
	X		if( ( ( c ==  '\n' ) || ( c == ' ' ) ) &&
	X		    ( ( lc == ' ' ) || ( lc == '\n' ) ) ) {
	X			continue;
	X		}
	X
	X		/*
	X		 * Build string.
	X		 */
	X		if( c == '\n' )
	X			d[i++] = ' ';
	X		else
	X			d[i++] = c;
	X
	X		lc = c;		/* update last-char */
	X	}
	X
	X	d[i] = NULL;	/* Hit EOF, not good. Give it our best shot */
	X}
	X
	X
	X/*
	X * getdes
	X *	Get the description.
	X *	The description is consider to be everything up
	X *	to 2 consecutive '\n'.
	X *
	X */
	Xgetdes( fp , d ) 
	XFILE *fp;
	Xchar *d;
	X{
	X	int c = 0;	/* current char */
	X	int lc = 0;	/* last-char */
	X	int i = 0;	/* index into d */
	X
	X	/*
	X	 * Read up til 2 consecutive '\n'.
	X	 */
	X	while( ( c = fgetc( fp ) ) != EOF ) {
	X		if( ( c == '\n' ) && ( lc == '\n' ) ) {
	X			d[i] = NULL;
	X			return;
	X		};
	X		
	X		/*
	X		 * Due away with multiple spaces.
	X		 *    note: '\n' is consider a space.
	X		 */
	X		if( ( ( c == '\n' ) || ( c == ' ' ) ) &&
	X		    ( ( lc == ' ' ) || ( lc == '\n' ) ) )
	X			continue;
	X
	X		/*
	X		 * Build string.
	X		 */
	X		if( c == '\n' )
	X			d[i++] = ' ';
	X		else
	X			d[i++] = c;
	X
	X
	X		lc = c;		/* Update last-char */
	X	}
	X
	X	d[i] = NULL;	/* Hit EOF, not good. Give it our best try */
	X}
SHAR_EOF
if test 3830 -ne "`wc -c < 'whatitbe.c'`"
then
	echo shar: error transmitting "'whatitbe.c'" '(should have been 3830 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
-- 
John H. Pochmara				 A career is great, 
UUCP: {csun,voder,trwind}!polyslo!hoyt		 But you can't run your 
Internet: hoyt@polyslo.CalPoly.EDU		 fingers through its hair
							-Graffiti 4/13/83