home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume24 / psroff3.0 / part14 / psroff.S < prev   
Encoding:
Text File  |  1991-10-09  |  5.8 KB  |  318 lines

  1. %%STARTSHELL%%
  2. #    Copyright 1985, 1986, 1987, 1988, 1989, 1990, 1991 Chris Lewis
  3. #        All Rights Reserved
  4. #
  5. #    See the LICENSE file for a full description of the restrictions
  6. #    under which this software is provided.
  7. #
  8. #    Specs:        troff2ps driver
  9. #
  10. #ident  "@(#)psroff.sh: 2.15 Copyright 91/03/26 00:13:16 Chris Lewis"
  11.  
  12. LIBDIR="%%LIBDIR%%"
  13. FONTDIR="%%FONTDIR%%"
  14.  
  15. term=false
  16. fail=false
  17. if [ -n "$PSROFF" ]
  18. then
  19.     type=$PSROFF
  20. else
  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.     echo "or set PSROFF environment variable" >&2
  26.     exit 1
  27.     fi
  28. fi
  29. copies=1
  30. for i in $*
  31. do
  32.     case $i in
  33.     -F)
  34.         fail=true
  35.         ;;
  36.     -X)
  37.         set -x
  38.         debug=1
  39.         ;;
  40.     -V)
  41.         version=1
  42.         ;;
  43.     -t)
  44.         term=true
  45.         ;;
  46.     -T*)
  47.         type=`echo $i | sed -e 's/-T//'`
  48.         ;;
  49.     -d*)
  50.         sptr=`echo $i | sed -e 's/-d//'`
  51.         ;;
  52.     -n*)
  53.         copies=`echo $i | sed -e 's/-n//'`
  54.         ;;
  55.     -D* | -M | -R* | -O* | -P* | -Z)
  56.         extraargs="$extraargs $i"
  57.         ;;
  58.     -m* | -c*)
  59.         macros="$macros `echo $i | sed -e 's/-[cm]//'`"
  60.         ;;
  61.     -)
  62.         files="$files $i"
  63.         ;;
  64.     -rL*)
  65.         eval `echo $i | sed -e 's/-rL\(..*\)\(.\)$/length=\1 prec=\2/'`
  66.         if [ -z "$length" -o -z "$prec" ]
  67.         then
  68.         echo "$0: Bad length definition ($i) - must have value and scale" \
  69.             >&2
  70.         exit 1
  71.         fi
  72.         extraargs="$extraargs -l$length$prec"
  73.         args="$args $i"
  74.         ;;
  75.     -*)
  76.         args="$args $i"
  77.         ;;
  78.     *)
  79.         files="$files $i"
  80.         if [ ! -r $i ]
  81.         then
  82.         echo "$0: cannot open $i" >&2
  83.         exit 1
  84.         fi
  85.         ;;
  86.     esac
  87. done
  88.  
  89. if [ -z "$files" ]
  90. then
  91.     files="-"
  92. fi
  93.  
  94. #    Find some pieces:
  95. if [ -f troff2ps ]
  96. then
  97.     t2=./troff2ps
  98. else
  99.     t2=$LIBDIR/troff2ps
  100. fi
  101. if [ -n "$version" ]
  102. then
  103.     exec $t2 -V
  104. fi
  105.  
  106. if [ -r psrofflib ]
  107. then
  108.     psrofflib=psrofflib
  109. elif [ -r lib/psrofflib ]
  110. then
  111.     psrofflib=lib/psrofflib
  112. else
  113.     if [ -r $LIBDIR/lib/psrofflib ]
  114.     then
  115.     psrofflib=$LIBDIR/lib/psrofflib
  116.     fi
  117. fi
  118.  
  119. if [ -z "$psrofflib" ]
  120. then
  121.     echo "$0: Can't find psrofflib in ., lib, or $LIBDIR/lib" >&2
  122.     exit 1
  123. fi
  124.  
  125. F=''
  126. #    If your system has no awk (or a busted one), you may have to
  127. #    comment out the "line=`awk ... $psrofflib" lines, and uncomment
  128. #    the sed script.  If you do, you won't be able to continue
  129. #    psrofflib lines, so you'll have to "join" the entries in psrofflib
  130. #    (remembering to delete the name fields in the continuation lines).
  131. line=`awk '
  132.     $1 ~ /^#/ {next}
  133.     $0 ~ /^troff/ { print $0 }
  134.     $1 == "'$type'" {
  135.     seen=1
  136.     print "F='T'" substr($0, length($1) + 1)
  137.     next
  138.     }
  139.     { if (seen) exit(0) }
  140. ' $psrofflib`
  141. #line=`sed -n -e '/^troff/p' \
  142. #         -e "/^$type[     ]/{
  143. #         s/^$type[     ]*\(.*\)$/F='T' \1/p
  144. #         q
  145. #        }" $psrofflib`
  146.  
  147. if [ -z "$line" ]
  148. then
  149.     echo "$0: Can't find a line for '$type' in $psrofflib" >&2
  150.     exit 1
  151. else
  152.     eval "$line"
  153.     if [ -z "$F" ]
  154.     then
  155.     echo "$0: Can't find a line for '$type' in $psrofflib" >&2
  156.     exit 1
  157.     fi
  158. fi
  159.  
  160. #    If -N in t2arg, then this is ditroff.
  161. if [ -n "`echo "$t2arg" | sed -n -e '/-N/p'`" ]
  162. then
  163.     otroff=
  164.     widtharg="-T$width"
  165. else
  166.     otroff=-t
  167. fi
  168.  
  169. #    Try to find troff
  170. if [ -z "$troff" ]
  171. then
  172.     #    Use path instead
  173.     troff=troff
  174. else
  175.     if [ ! -f $troff ]
  176.     then
  177.     echo "$0: $troff: not executable" >&2
  178.     exit 1
  179.     fi
  180. fi
  181.  
  182. #    Sanity checking for width tables
  183. if [ -n "$otroff" ]
  184. then
  185.     if [ -z "$trofftype" ]
  186.     then
  187.     widtharg=''
  188.     else
  189.     if [ ! -d $FONTDIR/$width ]
  190.     then
  191.         echo "$0: Warning: widths not installed" >&2
  192. cat >&2 <<!
  193. CAT Troff width tables have not been installed in $FONTDIR/$width/ft\*.
  194. Either you've not installed psroff yet, or your 'width' setting in psrofflib
  195. is incorrect.  Continuing anyways, using the default CAT troff widths found
  196. in $FONTDIR/ft\*, but the character spacing may be somewhat strange.
  197. You should investigate your configuration (see the README and TROUBLE files).
  198. !
  199.         widtharg=''
  200.     else
  201.         widtharg=`eval echo $trofftype`
  202.     fi
  203.     fi
  204. else
  205.     if [ ! -d $FONTDIR/dev$width ]
  206.     then
  207.     echo "$0: Ditroff widths not installed!  Aborting" >&2
  208.     exit 1
  209.     fi
  210. fi
  211.  
  212. if [ -z "$t2arg" ]
  213. then
  214.     echo "$0: t2arg isn't set for $type" >&2
  215.     exit 1
  216. fi
  217.  
  218. t2arg="$t2arg $extraargs"
  219.  
  220. #    command line -d option overrides ptr in psrofflib.
  221. if [ -n "$sptr" ]
  222. then
  223.     ptr=$sptr
  224. fi
  225.  
  226. if [ -n "$debug" ]
  227. then
  228.     (
  229.     echo "troff=$troff"
  230.     echo "trofftype=$trofftype"
  231.     echo "width=$width"
  232.     echo "t2arg=$t2arg"
  233.     echo "lparg=$lparg"
  234.     echo "widtharg=$widtharg"
  235.     echo "ptr=$ptr"
  236.     echo "files=$files"
  237.     echo "args=$args"
  238.     echo "otroff=$otroff"
  239.     echo "$troff $otroff $widtharg $args $files"
  240.     ) >&2
  241. fi
  242.  
  243. #    Handle macro business
  244. ml=''
  245. for i in $macros
  246. do
  247.     if [ -z "$otroff" ]
  248.     then
  249.     ml="$ml -m$i"
  250.     else
  251.     mac="$LIBDIR/adapters/mac.$type/tmac.$i"
  252.     if [ ! -r $mac ]
  253.     then
  254.         mac="$LIBDIR/adapters/tmac.$i"
  255.     fi
  256.     if [ ! -r $mac ]
  257.     then
  258.         mac="%%T2DIR%%/tmac.$i"
  259.     fi
  260.     if [ ! -r $mac ]
  261.     then
  262.         mac="%%RTMACDIR%%/tmac.$i"
  263.     fi
  264.     if [ ! -r $mac ]
  265.     then
  266.         echo "$0: Couldn't find tmac.$i anywhere!" >&2
  267.         exit 1
  268.     fi
  269.     ml="$ml $mac"
  270.     fi
  271. done
  272.  
  273. if [ -z "$ml" -a -n "$otroff" -a -r $LIBDIR/adapters/cmn.pre ]
  274. then
  275.     ml=$LIBDIR/adapters/cmn.pre
  276. fi
  277.  
  278. if [ -z "$otroff" -a -r $LIBDIR/adapters/cmn.dit ]
  279. then
  280.     ml="$ml $LIBDIR/adapters/cmn.dit"
  281. fi
  282.  
  283. #    Okay, let's DO it!
  284.  
  285. if $fail
  286. then
  287.     $troff $otroff $widtharg $args $ml $files > /dev/null
  288.     rc=$?
  289. elif $term
  290. then
  291.     if [ -n "$otroff" ]
  292.     then
  293.     ( $troff $otroff $widtharg $args $ml $files 2>&1 ) | $t2 $t2arg
  294.     rc=$?
  295.     else
  296.     $troff $widtharg $args $ml $files | $t2 $t2arg
  297.     rc=$?
  298.     fi
  299. else
  300.     if [ -n "$otroff" ]
  301.     then
  302.     if [ -n "$v" ]
  303.     then
  304.         eval "( cat $files | %%LIBDIR%%/catconv |
  305.         $troff $otroff $widtharg $args $ml - 2>&1 ) | $t2 $t2arg $lparg"
  306.         rc=$?
  307.     else
  308.         eval "( $troff $otroff $widtharg $args $ml $files 2>&1 ) |
  309.         $t2 $t2arg $lparg"
  310.     fi
  311.     rc=$?
  312.     else
  313.     eval "$troff $widtharg $args $ml $files 2>&1 | $t2 $t2arg $lparg"
  314.     rc=$?
  315.     fi
  316. fi
  317. exit $rc
  318.