4 # Copyright (c) 1999-2000 by Sun Microsystems, Inc.
7 # ident "%Z%%M% %I% %E% SMI"
9 # Copyright (c) 1980 Regents of the University of California.
10 # All rights reserved. The Berkeley software License Agreement
11 # specifies the terms and conditions for redistribution.
13 # This is a rewrite in ksh of the command originally written in
14 # csh whose last incarnation was:
15 # vgrind.csh 1.16 96/10/14 SMI; from UCB 5.3 (Berkeley) 11/13/85
19 # Definitions the user can override
21 troff
=${TROFF:-/usr/bin/troff}
22 vfontedpr
=${VFONTEDPR:-/usr/lib/vfontedpr}
23 macros
=${TMAC_VGRIND:-/usr/share/lib/tmac/tmac.vgrind}
26 # Internal processing of options
28 dpost
=/usr
/lib
/lp
/postscript
/dpost
51 # Process command line options
53 while getopts ":2d:fh:l:no:P:s:tT:wWx" opt
; do
56 /usr
/bin
/printf "`/usr/bin/gettext TEXT_DOMAIN 'vgrind: bad option %s'`\n" "+$opt" >&2
60 /usr
/bin
/printf "`/usr/bin/gettext TEXT_DOMAIN 'vgrind: bad option %s'`\n" "-$OPTARG" >&2
64 dpostopts
="$dpostopts -p l"
70 args
="$args -d $OPTARG"
71 if ! [ -r $OPTARG ] ; then
72 /usr
/bin
/printf "`/usr/bin/gettext TEXT_DOMAIN 'vgrind: -%s %s: file not readable'`\n" "$opt" "$OPTARG" >&2
81 args
="$args -h '$OPTARG'"
84 args
="$args -l$OPTARG"
90 troffopts
="$troffopts -o$OPTARG"
99 args
="$args -s$OPTARG"
102 troffopts
="$troffopts -T$OPTARG"
110 # Do nothing with this switch
119 troffopts
="$troffopts -$opt"
123 if [ "$opt" = ":" ] ; then
124 /usr
/bin
/printf "`/usr/bin/gettext TEXT_DOMAIN 'vgrind: missing argument to option %s'` \n" "-$OPTARG" >&2
129 shift $
((OPTIND
- 1))
138 if [ $filter -eq 1 -a \
( $twospec -eq 1 -o $pspec -eq 1 \
) ] ; then
139 /usr
/bin
/printf "`/usr/bin/gettext TEXT_DOMAIN 'vgrind: option -f is incompatible with -2 and -P'`\n" >&2
143 if [ $filter -eq 1 -a $tspec -eq 1 ] ; then
144 /usr
/bin
/printf "`/usr/bin/gettext TEXT_DOMAIN 'vgrind: option -f is incompatible with -t'`\n" >&2
148 if [ $tspec -eq 1 -a \
( $twospec -eq 1 -o $pspec -eq 1 \
) ] ; then
149 /usr
/bin
/printf "`/usr/bin/gettext TEXT_DOMAIN 'vgrind: option -t is incompatible with -2 and -P'`\n" >&2
153 # Do some reasoning about whether to print
155 if [ $uselp -eq 1 ] ; then
156 # If we want to print
158 if [ -z "$printer" ] ; then
159 # If "-P" was not specified
161 defaultprinter
=`LC_ALL=C /usr/bin/lpstat -d | /usr/bin/sed -e "s/no system default destination//" 2>/dev/null`
163 if [ -n "$defaultprinter" ] ; then
164 defaultprinter
=`echo $defaultprinter | \
165 /usr/bin/sed -e "s/system default destination: //" 2>/dev/null`
168 if [ $stdoutisatty -eq 1 ] ; then
169 # If stdout is not re-directed
171 if [ -z "$defaultprinter" ] ; then
174 printer
=$defaultprinter
177 # stdout is redirected - assume it is for further processing of
185 if [ $uselp -eq 1 ] ; then
186 case $
(/usr
/bin
/basename $lp) in
188 lpopts
="$lpopts -d$printer"
191 lpopts
="$lpopts -P$printer"
194 /usr
/bin
/printf "`/usr/bin/gettext TEXT_DOMAIN 'vgrind: unknown print program %s'`\n" $lp >&2
200 # Implementation note: In the following, we use "eval" to execute the
201 # command in order to preserve spaces which may appear in the -h option
202 # argument (and possibly in file names).
204 if [ $filter -eq 1 ] ; then
205 eval "$vfontedpr $args | /usr/bin/cat $macros -"
207 cmd
="$vfontedpr $args"
209 if [ -r index
] ; then
210 # Removes any entries from the index that come from the files we are
215 for i
in "$files" ; do
216 echo "? $i ?d" |
/usr
/bin
/sed -e "s:/:\\\/:g" -e "s:?:/:g" >> nindex
219 /usr
/bin
/sed -f nindex index
> xindex
221 # Now process the input.
222 # (! [$filter -eq 1])
224 trap "rm -f xindex nindex; exit 1" INT QUIT
226 cmd
="$cmd | $troff -rx1 $troffopts -i $macros - 2>> xindex"
228 if [ $usedpost -eq 1 ] ; then
229 cmd
="$cmd | $dpost $dpostopts"
232 if [ $uselp -eq 1 ] ; then
233 cmd
="$cmd | $lp $lpopts"
238 /usr
/bin
/sort -dfu +0 -2 xindex
> index
239 /usr
/bin
/rm nindex xindex
243 cmd
="$cmd | $troff -i $troffopts $macros -"
245 if [ $usedpost -eq 1 ] ; then
246 cmd
="$cmd | $dpost $dpostopts"
249 if [ $uselp -eq 1 ] ; then
250 cmd
="$cmd | $lp $lpopts"