home *** CD-ROM | disk | FTP | other *** search
/ The UNIX CD Bookshelf / OREILLY_TUCB_UNIX_CD.iso / upt / examples / LINUX / ARCHIVE / AWF.Z / AWF / sbin / awf
Encoding:
Text File  |  1992-10-14  |  1.1 KB  |  61 lines

  1. #! /bin/sh
  2. PATH=/bin:/usr/bin ; export PATH
  3. # AWFLIB is where the pieces live
  4. AWFLIB=${AWFLIB-///////////////////////////////////////////////////////////////////////////usr/STAGE/slib/awf}
  5.  
  6. tmp=/tmp/awp$$            # tempfile for building pass 2
  7. errs=/tmp/awe$$        # error messages (awk can't send to stderr)
  8.  
  9. case "$1" in
  10. -ms)    mac=ms    ;;
  11. -man)    mac=man    ;;
  12. *)    echo "$0: must specify -ms or -man" >&2
  13.     exit 2
  14.     ;;
  15. esac
  16. shift
  17.  
  18. dev="$AWFLIB/dev.$TERM"
  19. if test ! -r $dev
  20. then
  21.     dev="$AWFLIB/dev.dumb"
  22. fi
  23.  
  24. trap "rm -f $tmp $errs ; exit 0" 0 1 2
  25.  
  26. # build the full, macro-set-dependent, pass-2 awk program
  27. (
  28.     sed -n '1,/^#include/p' $AWFLIB/pass2.base
  29.     cat $AWFLIB/pass2.$mac
  30.     sed -n '/^#include/,$p' $AWFLIB/pass2.base
  31. ) >$tmp
  32.  
  33. # do it
  34. (
  35.     echo ".^x $errs"
  36.     echo ".^b"
  37.     echo ".^# 1 <prolog>"
  38.     cat $dev $AWFLIB/common $AWFLIB/mac.$mac
  39.     if test " $*" = " "
  40.     then
  41.         echo ".^# 1 <stdin>"
  42.         cat
  43.     else
  44.         for f
  45.         do
  46.             echo ".^# 1 $f"
  47.             cat $f
  48.         done
  49.     fi
  50.     echo ".^e"
  51. ) | awk -f $AWFLIB/pass1 | awk -f $tmp | awk -f $AWFLIB/pass3
  52.  
  53. # error messages, if any
  54. if test -s $errs
  55. then
  56.     cat $errs >&2
  57.     exit 1
  58. else
  59.     exit 0
  60. fi
  61.