Xref: utzoo comp.lang.c:37349 alt.sources:3517 Newsgroups: comp.lang.c,alt.sources Path: utzoo!sq!lee From: lee@sq.sq.com (Liam R. E. Quin) Subject: "use" shell script [was Re: Small introspective program] Message-ID: <1991Mar20.192029.20210@sq.sq.com> Organization: SoftQuad Inc., Toronto, Canada References: <1991Mar10.231230.1301@casbah.acns.nwu.edu> <4967@goanna.cs.rmit.oz.au> Date: Wed, 20 Mar 91 19:20:29 GMT Lines: 82 ok@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 use 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@sq.com, SoftQuad Inc., Toronto, +1 (416) 963-8337 `A wrong that cannot be repaired must be transcended' Ursula K. Le Guin, in _Tehanu_