xref: /plan9/sys/lib/lp/process/generic (revision d40255d87ccd1acd15b87823a96efd7b6296fadd)
1#!/bin/rc
2# Tries to determine what type of file you are printing and do the correct
3# thing with it.
4# It currently knows about images, troff intermediate, and ascii files.
5rfork e
6temp=/tmp/lp$pid
7fn sigexit { rm -f $temp }
8proc=$LPLIB/process
9
10if (! ~ $DEBUG '')
11	flag x +
12cat >$temp
13
14type=`{file $temp}
15switch ($type(2)) {
16case troff
17	switch ($LPCLASS) {
18	case *Latin1* *post* *opost*
19		switch ($type(5)) {
20		# Latin1 is for compatibility with old research UNIX systems,
21		# doesn't work on Plan 9
22		case Latin1 post
23			tcs -s -f utf -t latin1 <$temp | $proc/dpost
24		case UTF
25			$proc/tr2post <$temp
26		}
27	case *gs!* *gsijs!*
28		switch ($type(5)) {
29		# Latin1 is for compatibility with old research UNIX systems,
30		# doesn't work on Plan 9
31		case Latin1 post
32			tcs -s -f utf -t latin1 <$temp | $proc/dpost |
33				$proc/gspipe
34		case UTF
35			$proc/tr2post <$temp | $proc/gspipe
36		}
37	case *
38		echo $type(2) -T$type(5) output is improper for $LPDEST >[1=2]
39	}
40case special
41	switch ($type(4)) {
42	case '#b'
43		switch ($LPCLASS) {
44		case *post*
45			$proc/p9bitpost <$temp
46		case *gs!*
47			$proc/p9bitpost <$temp | $proc/gspipe
48		case *gsijs!*
49			$proc/p9bitpost <$temp | $proc/gspipeijs
50		}
51	case *
52		echo $type file is improper for $LPDEST >[1=2]
53	}
54case Compressed plan old subfont
55	# type is really 'Compressed image' or 'plan 9 image' or
56	# 'old plan 9 image'
57	# 'subfont' is to cope with a bug in png (writing wrong length),
58	# 6 may 2008
59	switch ($LPCLASS) {
60	case *post*
61		$proc/p9bitpost <$temp
62	case *gs!*
63		$proc/p9bitpost <$temp | $proc/gspipe
64	case *gsijs!*
65		$proc/p9bitpost <$temp | $proc/gspipeijs
66	}
67case jpeg
68	switch ($LPCLASS) {
69	case *post*
70		$proc/jpgpost <$temp
71	case *gs!*
72		$proc/jpgpost <$temp | $proc/gspipe
73	case *gsijs!*
74		$proc/jpgpost <$temp | $proc/gspipeijs
75	}
76case GIF
77	switch ($LPCLASS) {
78	case *post*
79		$proc/gifpost <$temp
80	case *gs!*
81		$proc/gifpost <$temp | $proc/gspipe
82	case *gsijs!*
83		$proc/gifpost <$temp | $proc/gspipeijs
84	}
85case PNG
86	switch ($LPCLASS) {
87	case *post*
88		$proc/pngpost <$temp
89	case *gs!*
90		$proc/pngpost <$temp | $proc/gspipe
91	case *gsijs!*
92		$proc/pngpost <$temp | $proc/gspipeijs
93	}
94case ccitt-g31
95	switch ($LPCLASS) {
96	case *post*
97		$proc/g3post <$temp
98	case *gs!*
99		$proc/g3post <$temp | $proc/gspipe
100	case *gsijs!*
101		$proc/g3post <$temp | $proc/gspipeijs
102	}
103case bitmap
104	# bitmap for research UNIX compatibility, does not work on Plan 9.
105	switch ($LPCLASS) {
106	case *post*
107		$proc/bpost <$temp
108	case *mhcc*
109		$proc/bpost <$temp | $proc/mhcc
110	case *
111		echo $type(2) file is improper for $LPDEST >[1=2]
112	}
113case tex
114	mv $temp $temp.dvi
115	temp=$temp.dvi
116	switch ($LPCLASS) {
117	case *post*
118		$proc/dvipost $temp
119	case *gs!*
120		$proc/dvipost $temp | $proc/gspipe
121	case *gsijs!*
122		$proc/dvipost $temp | $proc/gspipeijs
123	case *
124		echo $type(2) file is improper for $LPDEST >[1=2]
125	}
126case postscript
127	switch ($LPCLASS) {
128	case *post*
129		$proc/post <$temp
130	case *gs!*
131		$proc/post <$temp | $proc/gspipe
132	case *gsijs!*
133		$proc/post <$temp | $proc/gspipeijs
134	case *
135		echo $type(2) file is improper for $LPDEST >[1=2]
136	}
137case HPJCL HP
138	switch ($LPCLASS) {
139	case *HPJCL*
140		$proc/noproc <$temp
141	case *
142		echo $type(2) file is improper for $LPDEST >[1=2]
143	}
144case daisy
145	switch ($LPDEST) {
146	case *
147		echo $type(2) file is improper for $LPDEST >[1=2]
148	}
149case tiff
150	switch ($LPCLASS) {
151	case *post*
152		$proc/tiffpost $temp
153	case *gs!*
154		$proc/tiffpost $temp | $proc/gspipe
155	case *gsijs!*
156		$proc/tiffpost $temp | $proc/gspipeijs
157	case *
158		echo Unrecognized class of line printer for $LPDEST >[1=2]
159	}
160case PDF
161	switch ($LPCLASS) {
162	case *pdf*
163#		if (~ $LPCLASS *duplex* && ~ $LPCLASS *HPJCL*)
164#			echo -n '&l1S'		# HP JCL: duplex on
165		if (~ $LPCLASS *duplex* && ~ $LPCLASS *HPJCL*) {
166			echo '%-12345X@PJL DEFAULT DUPLEX=ON'	# HP PJL
167			echo '%-12345X'
168			echo '%-12345X@PJL DEFAULT PS:MBT=ON'	# `memory boost'
169			echo '%-12345X'
170		}
171		cat $temp		# pass pdf unaltered to pdf printer
172	case *post*
173		$proc/pdfpost $temp
174	case *gs!*
175		$proc/pdfgs $temp
176	case *gsijs!*
177		$proc/pdfgsijs $temp
178	case *
179		echo Unrecognized class of line printer for $LPDEST >[1=2]
180	}
181case microsoft				# office document
182	switch ($LPCLASS) {
183	case *post*
184		doc2ps $temp | $proc/post
185	case *gs!*
186		doc2ps $temp | $proc/post  | $proc/gspipe
187	case *gsijs!*
188		doc2ps $temp | $proc/post | $proc/gspipeijs
189	case *
190		echo $type(2) file is improper for $LPDEST >[1=2]
191	}
192case empty
193	echo file is empty >[1=2]
194case cannot
195	echo cannot open file >[1=2]
196case English Cyrillic short extended alef limbo [Aa]scii assembler c latin rc sh \
197    as mail email message/rfc822 manual HTML
198	switch ($LPCLASS) {
199	case *post*
200		$proc/ppost <$temp
201	case *gs!*
202		$proc/ppost <$temp | $proc/gspipe
203	case *gsijs!*
204		$proc/ppost <$temp | $proc/gspipeijs
205	case *canon*
206		$proc/can $* <$temp
207	case *
208		echo Unrecognized class of line printer for $LPDEST >[1=2]
209	}
210case *
211	echo $type(2) file is improper for $LPDEST >[1=2]
212}
213
214wait
215rv=$status
216rm -f $temp
217# exit $rv
218exit
219