home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2097 / psroff.S
Encoding:
Text File  |  1990-12-28  |  4.6 KB  |  242 lines

  1. %%STARTSHELL%%
  2. #    Copyright 1985, 1986, 1987, 1988 Chris Lewis
  3. #        All Rights Reserved
  4. #
  5. #    Permission to copy and further distribute is freely given provided
  6. #    this copyright notice remains intact and that this software is not
  7. #    sold for profit.
  8. #
  9. #    Project:    Generic Troff drivers
  10. #    Module:        psroff.sh
  11. #    Author:     Chris Lewis
  12. #    Specs:        troff driver
  13. #
  14. #ident  "@(#)psroff.sh: 2.2 Copyright 90/10/01 14:41:16 Chris Lewis"
  15.  
  16. LIBDIR="%%LIBDIR%%"
  17. FONTDIR="%%FONTDIR%%"
  18.  
  19. term=false
  20. fail=false
  21. type=`basename $0 | sed -n -e 's;^\([^/]*\)roff$;\1;p'`
  22. if [ -z "$type" ]
  23. then
  24.     echo "psroff: Can't intuit psroff type from $0" >&2
  25.     exit 1
  26. fi
  27. copies=1
  28. for i in $*
  29. do
  30.     case $i in
  31.     -F)
  32.         fail=true
  33.         ;;
  34.     -X)
  35.         set -x
  36.         debug=1
  37.         ;;
  38.     -t)
  39.         term=true
  40.         ;;
  41.     -T*)
  42.         type=`echo $i | sed -e 's/-T//'`
  43.         ;;
  44.     -d*)
  45.         sptr=`echo $i | sed -e 's/-d//'`
  46.         ;;
  47.     -n*)
  48.         copies=`echo $i | sed -e 's/-n//'`
  49.         ;;
  50.     -D* | -M | -R* | -O* | -P* | -Z)
  51.         extraargs="$extraargs $i"
  52.         ;;
  53.     -m* | -c*)
  54.         mac=`echo $i | sed -e 's/-[cm]//'`
  55.         file="$LIBDIR/adapters/mac.$type/tmac.$mac"
  56.         if [ ! -r $file ]
  57.         then
  58.         file="$LIBDIR/adapters/tmac.$mac"
  59.         fi
  60.         if [ ! -r $file ]
  61.         then
  62.         file="%%RTMACDIR%%/tmac.$mac"
  63.         fi
  64.         if [ ! -r $file ]
  65.         then
  66.         echo "$0: Couldn't find tmac.$mac anywhere!" >&2
  67.         exit 1
  68.         fi
  69.         files="$files $file"
  70.         ;;
  71.     -)
  72.         files="$files $i"
  73.         seenfiles=1
  74.         ;;
  75.     -rL*)
  76.         eval `echo $i | sed -e 's/-rL\(..*\)\(.\)$/length=\1 prec=\2/'`
  77.         if [ -z "$length" -o -z "$prec" ]
  78.         then
  79.         echo "$0: Bad length definition ($i) - must have value and scale" \
  80.             >&2
  81.         exit 1
  82.         fi
  83.         extraargs="$extraargs -l$length$prec"
  84.         args="$args $i"
  85.         ;;
  86.     -*)
  87.         args="$args $i"
  88.         ;;
  89.     *)
  90.         files="$files $i"
  91.         seenfiles=1
  92.         if [ ! -r $i ]
  93.         then
  94.         echo "$0: cannot open $i" >&2
  95.         exit 1
  96.         fi
  97.         ;;
  98.     esac
  99. done
  100.  
  101. if [ -z "$seenfiles" ]
  102. then
  103.     files="$files -"
  104. fi
  105.  
  106. if [ -f troff2ps ]
  107. then
  108.     t2=./troff2ps
  109. else
  110.     t2=$LIBDIR/troff2ps
  111. fi
  112.  
  113. if [ -r psrofflib ]
  114. then
  115.     psrofflib=psrofflib
  116. elif [ -r lib/psrofflib ]
  117. then
  118.     psrofflib=lib/psrofflib
  119. else
  120.     if [ -r $LIBDIR/lib/psrofflib ]
  121.     then
  122.     psrofflib=$LIBDIR/lib/psrofflib
  123.     fi
  124. fi
  125.  
  126. if [ -z "$psrofflib" ]
  127. then
  128.     echo "$0: Can't find psrofflib in . or $LIBDIR" >&2
  129.     exit 1
  130. fi
  131.  
  132. F=''
  133. #    If your system has no awk (or a busted one), you may have to
  134. #    comment out the "line=`awk ... $psrofflib" lines, and uncomment
  135. #    the sed script.  If you do, you won't be able to continue
  136. #    psrofflib lines, so you'll have to "join" the entries in psrofflib
  137. #    (remembering to delete the name fields in the continuation lines).
  138. line=`awk '
  139.     $1 ~ /^#/ {next}
  140.     $0 ~ /^troff/ { print $0 }
  141.     $1 == "'$type'" {
  142.     seen=1
  143.     print "F='T'" substr($0, length($1) + 1)
  144.     next
  145.     }
  146.     { if (seen) exit(0) }
  147. ' $psrofflib`
  148. #line=`sed -n -e '/^troff/p' \
  149. #         -e "/^$type[     ]/{
  150. #         s/^$type[     ]*\(.*\)$/F='T' \1/p
  151. #         q
  152. #        }" $psrofflib`
  153.  
  154. if [ -z "$line" ]
  155. then
  156.     echo "$0: Can't find a line for '$type' in $psrofflib" >&2
  157.     exit 1
  158. else
  159.     eval "$line"
  160.     if [ -z "$F" ]
  161.     then
  162.     echo "$0: Can't find a line for '$type' in $psrofflib" >&2
  163.     exit 1
  164.     fi
  165. fi
  166.  
  167. if [ -z "$troff" ]
  168. then
  169.     #    Use path instead
  170.     troff=troff
  171. else
  172.     if [ ! -f $troff ]
  173.     then
  174.     echo "$0: $troff: not executable" >&2
  175.     exit 1
  176.     fi
  177. fi
  178.  
  179. if [ -z "$trofftype" ]
  180. then
  181.     widtharg=''
  182. else
  183.     if [ ! -d $FONTDIR/$width ]
  184.     then
  185. cat >&2 <<!
  186. CAT Troff width tables have not been installed in $FONTDIR/$width/ft\*.
  187. Either you've not installed psroff yet, or your 'width' setting in psrofflib
  188. is incorrect.  Continuing anyways, using the default CAT troff widths found
  189. in $FONTDIR/ft\*, but the character spacing may be somewhat strange.
  190. You should investigate your configuration (see the README and TROUBLE files).
  191. !
  192.     widtharg=''
  193.     else
  194.     widtharg=`eval echo $trofftype`
  195.     fi
  196. fi
  197.  
  198. if [ -z "$t2arg" ]
  199. then
  200.     echo "$0: t2arg isn't set for $type" >&2
  201.     exit 1
  202. fi
  203.  
  204. t2arg="$t2arg $extraargs"
  205.  
  206. if [ -n "$sptr" ]
  207. then
  208.     ptr=$sptr
  209. fi
  210.  
  211. if [ -n "$debug" ]
  212. then
  213.     (
  214.     echo "troff=$troff"
  215.     echo "trofftype=$trofftype"
  216.     echo "width=$width"
  217.     echo "t2arg=$t2arg"
  218.     echo "lparg=$lparg"
  219.     echo "widtharg=$widtharg"
  220.     echo "ptr=$ptr"
  221.     ) >&2
  222. fi
  223.  
  224. if [ -n "$widtharg" -a ! -d %%FONTDIR%%/$width ]
  225. then
  226.     echo "$0: troff doesn't have width tables ($width) for $type printer" >&2
  227.     echo "Please see the README and gfnttab for creating them" >&2
  228.     exit 1
  229. fi
  230.  
  231. if $fail
  232. then
  233.     $troff -t $widtharg $args $files > /dev/null
  234. elif $term
  235. then
  236.     ( $troff -t $widtharg $args $files 2>&1 ) | $t2 $t2arg
  237.     exit $?
  238. else
  239.     eval "( $troff -t $widtharg $args $files 2>&1 ) | $t2 $t2arg $lparg"
  240.     exit $?
  241. fi
  242.