home *** CD-ROM | disk | FTP | other *** search
- %%STARTSHELL%%
- # Copyright 1985, 1986, 1987, 1988, 1989, 1990, 1991 Chris Lewis
- # All Rights Reserved
- #
- # See the LICENSE file for a full description of the restrictions
- # under which this software is provided.
- #
- # Specs: troff2ps driver
- #
- #ident "@(#)psroff.sh: 2.15 Copyright 91/03/26 00:13:16 Chris Lewis"
-
- LIBDIR="%%LIBDIR%%"
- FONTDIR="%%FONTDIR%%"
-
- term=false
- fail=false
- if [ -n "$PSROFF" ]
- then
- type=$PSROFF
- else
- type=`basename $0 | sed -n -e 's;^\([^/]*\)roff$;\1;p'`
- if [ -z "$type" ]
- then
- echo "psroff: Can't intuit psroff type from $0" >&2
- echo "or set PSROFF environment variable" >&2
- exit 1
- fi
- fi
- copies=1
- for i in $*
- do
- case $i in
- -F)
- fail=true
- ;;
- -X)
- set -x
- debug=1
- ;;
- -V)
- version=1
- ;;
- -t)
- term=true
- ;;
- -T*)
- type=`echo $i | sed -e 's/-T//'`
- ;;
- -d*)
- sptr=`echo $i | sed -e 's/-d//'`
- ;;
- -n*)
- copies=`echo $i | sed -e 's/-n//'`
- ;;
- -D* | -M | -R* | -O* | -P* | -Z)
- extraargs="$extraargs $i"
- ;;
- -m* | -c*)
- macros="$macros `echo $i | sed -e 's/-[cm]//'`"
- ;;
- -)
- files="$files $i"
- ;;
- -rL*)
- eval `echo $i | sed -e 's/-rL\(..*\)\(.\)$/length=\1 prec=\2/'`
- if [ -z "$length" -o -z "$prec" ]
- then
- echo "$0: Bad length definition ($i) - must have value and scale" \
- >&2
- exit 1
- fi
- extraargs="$extraargs -l$length$prec"
- args="$args $i"
- ;;
- -*)
- args="$args $i"
- ;;
- *)
- files="$files $i"
- if [ ! -r $i ]
- then
- echo "$0: cannot open $i" >&2
- exit 1
- fi
- ;;
- esac
- done
-
- if [ -z "$files" ]
- then
- files="-"
- fi
-
- # Find some pieces:
- if [ -f troff2ps ]
- then
- t2=./troff2ps
- else
- t2=$LIBDIR/troff2ps
- fi
- if [ -n "$version" ]
- then
- exec $t2 -V
- fi
-
- if [ -r psrofflib ]
- then
- psrofflib=psrofflib
- elif [ -r lib/psrofflib ]
- then
- psrofflib=lib/psrofflib
- else
- if [ -r $LIBDIR/lib/psrofflib ]
- then
- psrofflib=$LIBDIR/lib/psrofflib
- fi
- fi
-
- if [ -z "$psrofflib" ]
- then
- echo "$0: Can't find psrofflib in ., lib, or $LIBDIR/lib" >&2
- exit 1
- fi
-
- F=''
- # If your system has no awk (or a busted one), you may have to
- # comment out the "line=`awk ... $psrofflib" lines, and uncomment
- # the sed script. If you do, you won't be able to continue
- # psrofflib lines, so you'll have to "join" the entries in psrofflib
- # (remembering to delete the name fields in the continuation lines).
- line=`awk '
- $1 ~ /^#/ {next}
- $0 ~ /^troff/ { print $0 }
- $1 == "'$type'" {
- seen=1
- print "F='T'" substr($0, length($1) + 1)
- next
- }
- { if (seen) exit(0) }
- ' $psrofflib`
- #line=`sed -n -e '/^troff/p' \
- # -e "/^$type[ ]/{
- # s/^$type[ ]*\(.*\)$/F='T' \1/p
- # q
- # }" $psrofflib`
-
- if [ -z "$line" ]
- then
- echo "$0: Can't find a line for '$type' in $psrofflib" >&2
- exit 1
- else
- eval "$line"
- if [ -z "$F" ]
- then
- echo "$0: Can't find a line for '$type' in $psrofflib" >&2
- exit 1
- fi
- fi
-
- # If -N in t2arg, then this is ditroff.
- if [ -n "`echo "$t2arg" | sed -n -e '/-N/p'`" ]
- then
- otroff=
- widtharg="-T$width"
- else
- otroff=-t
- fi
-
- # Try to find troff
- if [ -z "$troff" ]
- then
- # Use path instead
- troff=troff
- else
- if [ ! -f $troff ]
- then
- echo "$0: $troff: not executable" >&2
- exit 1
- fi
- fi
-
- # Sanity checking for width tables
- if [ -n "$otroff" ]
- then
- if [ -z "$trofftype" ]
- then
- widtharg=''
- else
- if [ ! -d $FONTDIR/$width ]
- then
- echo "$0: Warning: widths not installed" >&2
- cat >&2 <<!
- CAT Troff width tables have not been installed in $FONTDIR/$width/ft\*.
- Either you've not installed psroff yet, or your 'width' setting in psrofflib
- is incorrect. Continuing anyways, using the default CAT troff widths found
- in $FONTDIR/ft\*, but the character spacing may be somewhat strange.
- You should investigate your configuration (see the README and TROUBLE files).
- !
- widtharg=''
- else
- widtharg=`eval echo $trofftype`
- fi
- fi
- else
- if [ ! -d $FONTDIR/dev$width ]
- then
- echo "$0: Ditroff widths not installed! Aborting" >&2
- exit 1
- fi
- fi
-
- if [ -z "$t2arg" ]
- then
- echo "$0: t2arg isn't set for $type" >&2
- exit 1
- fi
-
- t2arg="$t2arg $extraargs"
-
- # command line -d option overrides ptr in psrofflib.
- if [ -n "$sptr" ]
- then
- ptr=$sptr
- fi
-
- if [ -n "$debug" ]
- then
- (
- echo "troff=$troff"
- echo "trofftype=$trofftype"
- echo "width=$width"
- echo "t2arg=$t2arg"
- echo "lparg=$lparg"
- echo "widtharg=$widtharg"
- echo "ptr=$ptr"
- echo "files=$files"
- echo "args=$args"
- echo "otroff=$otroff"
- echo "$troff $otroff $widtharg $args $files"
- ) >&2
- fi
-
- # Handle macro business
- ml=''
- for i in $macros
- do
- if [ -z "$otroff" ]
- then
- ml="$ml -m$i"
- else
- mac="$LIBDIR/adapters/mac.$type/tmac.$i"
- if [ ! -r $mac ]
- then
- mac="$LIBDIR/adapters/tmac.$i"
- fi
- if [ ! -r $mac ]
- then
- mac="%%T2DIR%%/tmac.$i"
- fi
- if [ ! -r $mac ]
- then
- mac="%%RTMACDIR%%/tmac.$i"
- fi
- if [ ! -r $mac ]
- then
- echo "$0: Couldn't find tmac.$i anywhere!" >&2
- exit 1
- fi
- ml="$ml $mac"
- fi
- done
-
- if [ -z "$ml" -a -n "$otroff" -a -r $LIBDIR/adapters/cmn.pre ]
- then
- ml=$LIBDIR/adapters/cmn.pre
- fi
-
- if [ -z "$otroff" -a -r $LIBDIR/adapters/cmn.dit ]
- then
- ml="$ml $LIBDIR/adapters/cmn.dit"
- fi
-
- # Okay, let's DO it!
-
- if $fail
- then
- $troff $otroff $widtharg $args $ml $files > /dev/null
- rc=$?
- elif $term
- then
- if [ -n "$otroff" ]
- then
- ( $troff $otroff $widtharg $args $ml $files 2>&1 ) | $t2 $t2arg
- rc=$?
- else
- $troff $widtharg $args $ml $files | $t2 $t2arg
- rc=$?
- fi
- else
- if [ -n "$otroff" ]
- then
- if [ -n "$v" ]
- then
- eval "( cat $files | %%LIBDIR%%/catconv |
- $troff $otroff $widtharg $args $ml - 2>&1 ) | $t2 $t2arg $lparg"
- rc=$?
- else
- eval "( $troff $otroff $widtharg $args $ml $files 2>&1 ) |
- $t2 $t2arg $lparg"
- fi
- rc=$?
- else
- eval "$troff $widtharg $args $ml $files 2>&1 | $t2 $t2arg $lparg"
- rc=$?
- fi
- fi
- exit $rc
-