"use" shell script [was Re: Small introspective program]

Liam R. E. Quin lee at sq.sq.com
Thu Mar 21 05:20:29 AEST 1991


ok at goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
>[About the hack for including a command to compile itself in a C program.]
> Many years ago Tom Duff wrote a nifty little program called "com"; [...]

I still use a shell-script called "use" for troff files, and sometimes for
complex shell scripts.

It understands a number of comment conventions, and looks for
	<any-sort-of-comment> use <command>
A % sign is turned into the filename.

For example,
	.\" Use pic % | troff -

Options other than -n are passed along....and appear immediately before the
first option in the Use line, so
	use -Timpr file
in the above file would be turned into
	pic file | troff -Timpr -

The Use comment must be in the 1st 5 lines.

Personally I prefer make, but that's another story...


Here it is.  Edit the "sed" line to change "^G" into a control G before
extracting.

Lee


sed 's/ControlG/^Gg' << 'boy' > use
:
if [ x"$1" = x"-n" ]
then	NOACTION=yes; shift
fi

while [ $# -gt 0 ]
do
    case "$1" in
    -*)
	TSOPTS="$TSOPTS '$1'"
	shift
	;;
    *)
	break
	;;
    esac
done

FILE=${1-:"You must give a filename"}

CMD=`sed -n '/^[ 	]*[#%*;][#%!*;]*\([ 	]*[uU]se \)/s//.\\\\" \1/
	    /^\.[ 	]*\\\\"[ 	]*[uU]se /p
	    5q' "${FILE}"`

if [ x"$CMD" = x"" ]
then
	echo "No Use comment in the file... do it yourself"
	exit 1
fi

pipeline=`echo "$CMD" | sed -e '
	s/^\.[ 	]*\\\\"[ 	]*[uU]se[ 	]*//
	sControlG%'"ControlG${FILE}"'ControlGg
	sControlG -ControlG'"${TSOPTS}"'&ControlG
	' `

echo $pipeline

if [ x"$NOACTION" = x"yes" ]
then	echo "[no action taken]"
else	eval $pipeline
fi
use
echo extracted use.
exit 0

-- 
Liam R. E. Quin,  lee at sq.com, SoftQuad Inc., Toronto, +1 (416) 963-8337
    `A wrong that cannot be repaired must be transcended'
						Ursula K. Le Guin, in _Tehanu_



More information about the Alt.sources mailing list