home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3101 < prev    next >
Encoding:
Internet Message Format  |  1991-03-21  |  1.9 KB

  1. From: lee@sq.sq.com (Liam R. E. Quin)
  2. Newsgroups: comp.lang.c,alt.sources
  3. Subject: "use" shell script [was Re: Small introspective program]
  4. Message-ID: <1991Mar20.192029.20210@sq.sq.com>
  5. Date: 20 Mar 91 19:20:29 GMT
  6.  
  7. ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
  8. >[About the hack for including a command to compile itself in a C program.]
  9. > Many years ago Tom Duff wrote a nifty little program called "com"; [...]
  10.  
  11. I still use a shell-script called "use" for troff files, and sometimes for
  12. complex shell scripts.
  13.  
  14. It understands a number of comment conventions, and looks for
  15.     <any-sort-of-comment> use <command>
  16. A % sign is turned into the filename.
  17.  
  18. For example,
  19.     .\" Use pic % | troff -
  20.  
  21. Options other than -n are passed along....and appear immediately before the
  22. first option in the Use line, so
  23.     use -Timpr file
  24. in the above file would be turned into
  25.     pic file | troff -Timpr -
  26.  
  27. The Use comment must be in the 1st 5 lines.
  28.  
  29. Personally I prefer make, but that's another story...
  30.  
  31.  
  32. Here it is.  Edit the "sed" line to change "^G" into a control G before
  33. extracting.
  34.  
  35. Lee
  36.  
  37.  
  38. sed 's/ControlG/^Gg' << 'boy' > use
  39. :
  40. if [ x"$1" = x"-n" ]
  41. then    NOACTION=yes; shift
  42. fi
  43.  
  44. while [ $# -gt 0 ]
  45. do
  46.     case "$1" in
  47.     -*)
  48.     TSOPTS="$TSOPTS '$1'"
  49.     shift
  50.     ;;
  51.     *)
  52.     break
  53.     ;;
  54.     esac
  55. done
  56.  
  57. FILE=${1-:"You must give a filename"}
  58.  
  59. CMD=`sed -n '/^[     ]*[#%*;][#%!*;]*\([     ]*[uU]se \)/s//.\\\\" \1/
  60.         /^\.[     ]*\\\\"[     ]*[uU]se /p
  61.         5q' "${FILE}"`
  62.  
  63. if [ x"$CMD" = x"" ]
  64. then
  65.     echo "No Use comment in the file... do it yourself"
  66.     exit 1
  67. fi
  68.  
  69. pipeline=`echo "$CMD" | sed -e '
  70.     s/^\.[     ]*\\\\"[     ]*[uU]se[     ]*//
  71.     sControlG%'"ControlG${FILE}"'ControlGg
  72.     sControlG -ControlG'"${TSOPTS}"'&ControlG
  73.     ' `
  74.  
  75. echo $pipeline
  76.  
  77. if [ x"$NOACTION" = x"yes" ]
  78. then    echo "[no action taken]"
  79. else    eval $pipeline
  80. fi
  81. use
  82. echo extracted use.
  83. exit 0
  84.  
  85. -- 
  86. Liam R. E. Quin,  lee@sq.com, SoftQuad Inc., Toronto, +1 (416) 963-8337
  87.     `A wrong that cannot be repaired must be transcended'
  88.                         Ursula K. Le Guin, in _Tehanu_
  89.