[mod.recipes] Mod.Recipes software contribution

reid@glacier.UUCP (02/09/86)

This is a shell script I modified for use here which people seem to
at least be amused by. It basically treats the recipes directory
just like a UNIX 'man' command, paginating off a recipe on-line
either to the screen or printer.

There's a very primitive file name completion in there also. Maybe
send to list if you find it worthy. It requires a very small change
to the setup of the recipe macros, see the notes.

	-Barry Shein, Boston University

WHAT'S FOR DINNER!

---------------
#!/bin/sh
#
#	Run off a page of the cookbook. Very similar to a man command.
#
#	Author, Author: Barry Shein, Boston University (C) 1986
#	I hereby allow anyone to use this as long as they do not
#	remove the (C) and do not charge for distribution beyond
#	copying costs. blah blah.
#
#	This script tries to complete names by using wildcards (*)
#	so you can give it any unambiguous prefix, or match a few
#	recipes all beginning with the same string. The annoying
#	thing is that there is no way to ask for ONLY something like
#	eggnog if there exists files like 'eggnog2, eggnog3' as all
#	will be printed. Suggestions welcome.
#
#	Usage is:
#		recipe			list all recipe names on-line
#		recipe foo bar...	format specified recipes to screen
#		recipe -t foo bar...	format to a printer
#
#	Read the comments, you will almost certainly have to change
#	the strings marked SITE SPECIFIC but it should be trivial.

#	Note that users can override most assumptions in this file
#	by setting the same variables in their environment as I always
#	check to make sure they are non-null. Thus, if they did a
#	% RECIPEDIR=$HOME/myrecipes
#	% export RECIPEDIR
#	this script would work relative to their directory

#
#	Hackers note: A few trivial changes and this makes a fine
#	on-line help command to supplement the manual (which is where
#	this came from, an old on-line help I wrote a long time ago.)

if [ "$RECIPEDIR" = "" ]
then
	RECIPEDIR=/usr/doc/Recipes	# SITE SPECIFIC!
fi

#
#	Note: I have modified -mrecip (/usr/lib/tmac/tmac.recip) so
#	that the last line of it is '.so /usr/lib/tmac/tmac.an' as it
#	requires inclusion of that package. You could just create another
#	file called, say, /usr/lib/tmac/tmac.rec, with the two '.so'
#	commands to pull in the two packages and change the below to
#	just '-mrec' or something like that.
#

if [ "$MRECIP" = "" ]
then
	MRECIP=-mrecip			# SITE SPECIFIC see note
fi

if [ "$NROFF" = "" ]
then
	NROFF="nroff $MRECIP"
fi

#
#	Note that obviously this can be any command that produces
#	nice hard-copy, like the correct nroff incantations to send
#	to your daisy-wheel printer.
#
if [ "$TROFF" = "" ]
then
	TROFF="qtroff $MRECIP"		# SITE SPECIFIC
fi


if [ "$PAGER" = "" ]
then
	PAGER='more -s'			# SOMEWHAT SITE SPECIFIC
fi

# make it default directory

cd $RECIPEDIR

# if no args just list recipes

if [ $# -lt 1 ]
then
	echo Recipes on line:
	echo
	ls
	echo
	exit 0
fi

#
#	recipe -t ...
#	means use troff rather than nroff and send to printer
#
if [ $1 = "-t" ]
then
	TFLAG=$1
	shift
else
	TFLAG=""
fi

#
#	Loop through args matching prefix and building a list of
#	valid ones.
#
RECIPES=""
for recipe in $*
do
	if [ ! -f $recipe* ]
	then
		echo $recipe: 'no such recipe?'
	else
		RECIPES="$RECIPES $recipe*"
	fi
done

#
#	if it's NULL just give up
#
if [ "$RECIPES" = "" ]
then
	echo Sorry.
	exit 1
fi

#
#	Send the final list to the screen or printer as appropriate
#
for recipe in $RECIPES
do
	if [ "$TFLAG" = "-t" ]
	then
		$TROFF $recipe
	else
		$NROFF $recipe | $PAGER
	fi
done
exit 0