summaryrefslogtreecommitdiff
path: root/groff.sh
blob: 5c7add2fba6069c53eb441058d5781dc28b4f6fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/bin/sh
#Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
#     Written by James Clark (jjc@jclark.uucp)
#
#This file is part of groff.
#
#groff is free software; you can redistribute it and/or modify it under
#the terms of the GNU General Public License as published by the Free
#Software Foundation; either version 1, or (at your option) any later
#version.
#
#groff is distributed in the hope that it will be useful, but WITHOUT ANY
#WARRANTY; without even the implied warranty of MERCHANTABILITY or
#FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
#for more details.
#
#You should have received a copy of the GNU General Public License along
#with groff; see the file LICENSE.  If not, write to the Free Software
#Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

# Add new devices below, where it says `Add local devices here.'

prog=`basename $0`
optF=
optP=
optL=
trflags=
tflag=
pflag=
eflag=
sflag=
lflag=
zflag=
vflag=
iflag=
Cflag=
Nflag=
Rflag=
Vflag=
dev=${GROFF_TYPESETTER:-@DEVICE@}

synopsis="\
usage: $prog [-abehilpstvzCENRVZ] [-Hfile] [-Fdir] [-mname] [-Tdev] [-ffam]
       [-wname] [-Wname] [ -Mdir] [-dcs] [-rcn] [-nnum] [-olist] [-Parg]
       [-Larg] [files...]"

devices="Available devices are:
X100	X11 previewer at 100dpi
X75	X11 previewer at 75dpi
X100-12	X11 previewer at 100dpi (optimized for 12 point text)
X75-12	X11 previewer at 75dpi (optimized for 12 point text)
ps	PostScript
Xps	X11 previewer with PostScript metrics
dvi	TeX dvi format
latin1	ISO Latin-1
ascii	ASCII"

help="$synopsis
-h	print this message
-t	preprocess with tbl
-p	preprocess with pic
-e	preprocess with eqn
-s	preprocess with soelim
-R	preprocess with refer
-Tdev	use device dev
-mname	read macros tmac.name
-dcs	define a string c as s
-rcn	define a number register c as n
-nnum	number first page n
-olist	output only pages in list
-ffam	use fam as the default font family
-Fdir	search directory dir for device directories
-Mdir	search dir for macro files
-Hfile	read hyphenation patterns from file
-v	print version number
-z	suppress formatted output
-Z	don't postprocess
-a	produce ASCII description of output
-i	read standard input after named input files
-wname	enable warning name
-Wname	inhibit warning name
-E	inhibit all errors
-b	print backtraces with errors or warnings
-l	spool the output (@PSPRINT@ or @DVIPRINT@)
-C	enable compatibility mode
-V	print the pipeline on stdout instead of executing it
-Parg	pass arg to the postprocessor	
-Larg	pass arg to the spooler	
-N	don't allow newlines within eqn delimiters

$devices"

usage="$synopsis
$prog -h gives more help"

while test $# -gt 0
do
	case $1 in
	-h*)
		echo "$help" >&2
		exit 0
		;;
	-[az])
		trflags="$trflags $1"
		zflag=1
		;;
	-Z)
		zflag=1
		;;
	-i)
		iflag=1
		;;
	-V)
		Vflag=1
		;;
	-t)
		tflag=1
		;;
	-p)
		pflag=1
		;;
	-e)
		eflag=1
		;;
	-s)
		sflag=1
		;;
	-R)
		Rflag=1
		;;
	-l)
		lflag=1
		;;
	-v)
		vflag=-v
		;;
	-C)
		Cflag=-C
		;;
	-N)
		Nflag=-N
		;;
	-[bE])
		trflags="$trflags $1"
		;;
	-[aiztpeslvbECNRVZ]*)
		first=`expr "$1" : '\(-.\)'`
		rest=`expr "$1" : '-.\(.*\)$'`
		shift
		set "" "$first" "-$rest" "$@"
		;;
	-F)
		if test $# -lt 2
		then
			echo "$prog: option -F requires an argument" >&2
			exit 1
		else
			optF="$optF -F$2"
			shift
		fi
		;;
	-F*)
		optF="$optF $1"
		;;
	-T)
		if test $# -lt 2
		then
			echo "$prog: option -T requires an argument" >&2
			exit 1
		else
			dev="$2"
			shift
		fi
		;;

	-T*)
		dev=`expr "$1" : '-T\(.*\)$'`
		;;
	-[fomrMHdnwW])
		if test $# -lt 2
		then
			echo "$prog: option $1 requires an argument" >&2
			exit 1
		else
			trflags="$trflags $1$2"
			shift
		fi
		;;
	-[fomrMHdnwW]*)
		trflags="$trflags $1"
		;;
	-P)
		if test $# -lt 2
		then
			echo "$prog: option -P requires an argument" >&2
			exit 1
		else
			optP="$optP $2"
			shift
		fi
		;;
	-P*)
		optP="$optP `expr "$1" : '-.\(.*\)$'`"
		;;
	-L)
		if test $# -lt 2
		then
			echo "$prog: option -L requires an argument" >&2
			exit 1
		else
			optL="$optL $2"
			shift
		fi
		;;
	-L*)
		optL="$optL `expr "$1" : '-.\(.*\)$'`"
		;;
	--)
		shift
		break
		;;
	-)
		break
		;;
	-*)
		echo "$prog: unrecognized option $1" >&2
		echo "$usage" >&2
		exit 1
		;;
	*)
		break
		;;
	esac
	shift
done

if test $# -gt 0
then
	files="$@"
	if test "$iflag"
	then
		files="$files -"
	fi
else
	files=-
fi

eqnchar=
eqnflag=
picflag=
postpro=

case $dev in
ps)
	trflags="-mps $trflags"
	eqnchar=@FONTDIR@/devps/eqnchar
	postpro="| grops $vflag $optF $optP"
	picflag="-x -p"
	eqnflag=-D
	if test "$lflag"
	then
		postpro="$postpro | @PSPRINT@ $optL"
	fi
	;;

X100|X75|X100-12|X75-12)
	trflags="-mX $trflags"
	picflag=-x
	eqnflag=-D
	postpro="| gxditview $optP -"
	eqnchar=@FONTDIR@/dev$dev/eqnchar
	;;

Xps)
	trflags="-mXps $trflags"
	eqnchar=@FONTDIR@/devps/eqnchar
	postpro="| gxditview $optP -printCommand 'grops | @PSPRINT@' -"
	picflag="-x -p"
	eqnflag=-D
	dev="ps"
	;;
	
ascii|latin1)
	trflags="-mtty $trflags"
	postpro="| grotty $vflag $optF $optP"
	;;

dvi)
	trflags="-mdvi $trflags"
	eqnchar=@FONTDIR@/devdvi/eqnchar
	picflag=-x
	postpro="| grodvi $vflag $optF $optP"
	if test "$lflag"
	then
		postpro="$postpro | @DVIPRINT@ $optL"
	fi
	;;
	

# Add local devices here.

*)
	echo "$prog: unknown device \`$dev'" >&2
	echo "$devices" >&2
	exit 1
	;;
esac

prepro=

if test "$sflag"
then
	prepro="$prepro gsoelim $vflag $Cflag $files |"
	files=-
fi

if test "$Rflag"
then
	prepro="$prepro grefer $vflag $files |"
	files=-
fi

if test "$pflag"
then
	prepro="$prepro gpic $vflag $Cflag $picflag $files |"
	files=-
fi

if test "$tflag"
then
	prepro="$prepro gtbl $vflag $Cflag $files |"
	files=-
fi

if test "$eflag"
then
	prepro="$prepro geqn $eqnflag $vflag $Cflag $Nflag -T$dev -- $eqnchar $files |"
	files=-
fi

if test "$zflag"
then
	postpro=
fi

pipe="$prepro gtroff -T$dev $vflag $Cflag $trflags $optF -- $files $postpro"

if test "$Vflag"
then
	echo $pipe
else
	eval $pipe
fi
exit 0