1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate /*
29*7c478bd9Sstevel@tonic-gate  *
30*7c478bd9Sstevel@tonic-gate  * A few special definitions used by the program that sends jobs to PostScript
31*7c478bd9Sstevel@tonic-gate  * printers. Most, if not all the testing, was done on a QMS PS-800 printer.
32*7c478bd9Sstevel@tonic-gate  *
33*7c478bd9Sstevel@tonic-gate  * POSTBEGIN, if it's not NULL, is some PostScript code that's sent to the
34*7c478bd9Sstevel@tonic-gate  * printer before any of the input files. It's not terribly important since the
35*7c478bd9Sstevel@tonic-gate  * same thing can be accomplished in other ways, but it is convenient. POSTBEGIN
36*7c478bd9Sstevel@tonic-gate  * is initialized so as to disable job timeouts. The string can also be set on
37*7c478bd9Sstevel@tonic-gate  * the command line using the -P option.
38*7c478bd9Sstevel@tonic-gate  *
39*7c478bd9Sstevel@tonic-gate  */
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #define POSTBEGIN	"statusdict /waittimeout 0 put\n"
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  *
47*7c478bd9Sstevel@tonic-gate  * Status lines returned by the printer usually look like,
48*7c478bd9Sstevel@tonic-gate  *
49*7c478bd9Sstevel@tonic-gate  *
50*7c478bd9Sstevel@tonic-gate  *	%%[ status: idle; source serial 25 ]%%
51*7c478bd9Sstevel@tonic-gate  *	%%[ status: waiting; source serial 25 ]%%
52*7c478bd9Sstevel@tonic-gate  *	%%[ status: initializing; source serial 25 ]%%
53*7c478bd9Sstevel@tonic-gate  *	%%[ status: busy; source serial 25 ]%%
54*7c478bd9Sstevel@tonic-gate  *	%%[ status: printing; source serial 25 ]%%
55*7c478bd9Sstevel@tonic-gate  *	%%[ status: PrinterError: out of paper; source serial 25 ]%%
56*7c478bd9Sstevel@tonic-gate  *	%%[ status: PrinterError: no paper tray; source serial 25 ]%%
57*7c478bd9Sstevel@tonic-gate  *
58*7c478bd9Sstevel@tonic-gate  *
59*7c478bd9Sstevel@tonic-gate  * although the list isn't meant to be complete.
60*7c478bd9Sstevel@tonic-gate  *
61*7c478bd9Sstevel@tonic-gate  * The following constants are used to classify some of the different printer
62*7c478bd9Sstevel@tonic-gate  * states. readline() reads status lines from ttyi and converts everything to
63*7c478bd9Sstevel@tonic-gate  * lower case. getstatus() interprets the text that readline() stores in sbuf[]
64*7c478bd9Sstevel@tonic-gate  * and returns integer codes that classify the printer status. Those codes are
65*7c478bd9Sstevel@tonic-gate  * used in routines start(), send(), and done() to figure out what's happening
66*7c478bd9Sstevel@tonic-gate  * and what should be done next.
67*7c478bd9Sstevel@tonic-gate  *
68*7c478bd9Sstevel@tonic-gate  */
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate #define WAITING		0		/* printer wants more data */
72*7c478bd9Sstevel@tonic-gate #define BUSY		1		/* processing data already sent */
73*7c478bd9Sstevel@tonic-gate #define PRINTING	2		/* printing a page */
74*7c478bd9Sstevel@tonic-gate #define IDLE		3		/* ready to start the next job */
75*7c478bd9Sstevel@tonic-gate #define ENDOFJOB	4		/* readline() builds this up on EOF */
76*7c478bd9Sstevel@tonic-gate #define PRINTERERROR	5		/* PrinterError - eg. out of paper */
77*7c478bd9Sstevel@tonic-gate #define ERROR		6		/* some kind of PostScript problem */
78*7c478bd9Sstevel@tonic-gate #define FLUSHING	7		/* throwing out the rest of the job */
79*7c478bd9Sstevel@tonic-gate #define INITIALIZING	8		/* printer's booting */
80*7c478bd9Sstevel@tonic-gate #define DISCONNECT	9		/* from Datakit */
81*7c478bd9Sstevel@tonic-gate #define UNKNOWN		10		/* in case we missed anything */
82*7c478bd9Sstevel@tonic-gate #define NOSTATUS	11		/* no response from the printer */
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate /*
86*7c478bd9Sstevel@tonic-gate  *
87*7c478bd9Sstevel@tonic-gate  * An array of type Status is used, in getstatus(), to figure out the printer's
88*7c478bd9Sstevel@tonic-gate  * current state. Just helps convert strings representing the current state into
89*7c478bd9Sstevel@tonic-gate  * integer codes that other routines use.
90*7c478bd9Sstevel@tonic-gate  *
91*7c478bd9Sstevel@tonic-gate  */
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate typedef struct {
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 	char	*state;			/* printer's current status */
97*7c478bd9Sstevel@tonic-gate 	int	val;			/* value returned by getstatus() */
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate } Status;
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate /*
103*7c478bd9Sstevel@tonic-gate  *
104*7c478bd9Sstevel@tonic-gate  * STATUS is used to initialize an array of type Status that translates the
105*7c478bd9Sstevel@tonic-gate  * ASCII strings returned by the printer into appropriate codes that can be used
106*7c478bd9Sstevel@tonic-gate  * later on in the program. State strings should all be entered in lower case.
107*7c478bd9Sstevel@tonic-gate  * readline() converts characters to lower before adding them to sbuf[]. If you
108*7c478bd9Sstevel@tonic-gate  * add any states, do it in lower case only, and be sure to add the new status
109*7c478bd9Sstevel@tonic-gate  * descriptions before the UNKNOWN entry. The lookup in getstatus() terminates
110*7c478bd9Sstevel@tonic-gate  * when it finds the printer state or encounters an entry with NULL in the state
111*7c478bd9Sstevel@tonic-gate  * field.
112*7c478bd9Sstevel@tonic-gate  *
113*7c478bd9Sstevel@tonic-gate  */
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate #define STATUS								\
117*7c478bd9Sstevel@tonic-gate 									\
118*7c478bd9Sstevel@tonic-gate 	{								\
119*7c478bd9Sstevel@tonic-gate 	    "waiting", WAITING,						\
120*7c478bd9Sstevel@tonic-gate 	    "busy", BUSY,						\
121*7c478bd9Sstevel@tonic-gate 	    "printing", PRINTING,					\
122*7c478bd9Sstevel@tonic-gate 	    "idle", IDLE,						\
123*7c478bd9Sstevel@tonic-gate 	    "endofjob", ENDOFJOB,					\
124*7c478bd9Sstevel@tonic-gate 	    "printererror", PRINTERERROR,				\
125*7c478bd9Sstevel@tonic-gate 	    "error", ERROR,						\
126*7c478bd9Sstevel@tonic-gate 	    "flushing", FLUSHING,					\
127*7c478bd9Sstevel@tonic-gate 	    "initializing", INITIALIZING,				\
128*7c478bd9Sstevel@tonic-gate 	    "conversation ended.\n", DISCONNECT,			\
129*7c478bd9Sstevel@tonic-gate 	    NULL, UNKNOWN						\
130*7c478bd9Sstevel@tonic-gate 	}
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate /*
134*7c478bd9Sstevel@tonic-gate  *
135*7c478bd9Sstevel@tonic-gate  * The baud rate can be set on the command line using the -b option. If you omit
136*7c478bd9Sstevel@tonic-gate  * it BAUDRATE will be used.
137*7c478bd9Sstevel@tonic-gate  *
138*7c478bd9Sstevel@tonic-gate  */
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate #define BAUDRATE	B9600
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate /*
145*7c478bd9Sstevel@tonic-gate  *
146*7c478bd9Sstevel@tonic-gate  * An array of type Baud is used, in routine getbaud(), to translate ASCII
147*7c478bd9Sstevel@tonic-gate  * strings into termio values that represent the requested baud rate.
148*7c478bd9Sstevel@tonic-gate  *
149*7c478bd9Sstevel@tonic-gate  */
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate typedef struct {
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate 	char	*rate;			/* string identifying the baud rate */
155*7c478bd9Sstevel@tonic-gate 	short	val;			/* and its termio.h value */
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate } Baud;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate /*
161*7c478bd9Sstevel@tonic-gate  *
162*7c478bd9Sstevel@tonic-gate  * BAUDTABLE initializes the array that's used to translate baud rate requests
163*7c478bd9Sstevel@tonic-gate  * into termio values. It needs to end with an entry that has NULL assigned to
164*7c478bd9Sstevel@tonic-gate  * the rate field.
165*7c478bd9Sstevel@tonic-gate  *
166*7c478bd9Sstevel@tonic-gate  */
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate #define BAUDTABLE							\
170*7c478bd9Sstevel@tonic-gate 									\
171*7c478bd9Sstevel@tonic-gate 	{								\
172*7c478bd9Sstevel@tonic-gate 	    "9600", B9600,						\
173*7c478bd9Sstevel@tonic-gate 	    "B9600", B9600,						\
174*7c478bd9Sstevel@tonic-gate 	    "19200", EXTA,						\
175*7c478bd9Sstevel@tonic-gate 	    "19.2", EXTA,						\
176*7c478bd9Sstevel@tonic-gate 	    "B19200", EXTA,						\
177*7c478bd9Sstevel@tonic-gate 	    "EXTA", EXTA,						\
178*7c478bd9Sstevel@tonic-gate 	    "1200", B1200,						\
179*7c478bd9Sstevel@tonic-gate 	    "B1200", B1200,						\
180*7c478bd9Sstevel@tonic-gate 	    "B4800", B4800,						\
181*7c478bd9Sstevel@tonic-gate 	    "4800", B4800,						\
182*7c478bd9Sstevel@tonic-gate 	    NULL, B9600							\
183*7c478bd9Sstevel@tonic-gate 	}
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate /*
187*7c478bd9Sstevel@tonic-gate  *
188*7c478bd9Sstevel@tonic-gate  * A few miscellaneous definitions. BLOCKSIZE is the default size of the buffer
189*7c478bd9Sstevel@tonic-gate  * used for reading the input files (changed with the -B option). BUFSIZE is
190*7c478bd9Sstevel@tonic-gate  * the size of the character array used to store printer status lines - don't
191*7c478bd9Sstevel@tonic-gate  * make it too small!
192*7c478bd9Sstevel@tonic-gate  *
193*7c478bd9Sstevel@tonic-gate  */
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate #define BLOCKSIZE	1024
197*7c478bd9Sstevel@tonic-gate #define BUFSIZE		512
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate /*
201*7c478bd9Sstevel@tonic-gate  *
202*7c478bd9Sstevel@tonic-gate  * Finally we'll declare a few of the non-integer valued functions used in
203*7c478bd9Sstevel@tonic-gate  * postio.c.
204*7c478bd9Sstevel@tonic-gate  *
205*7c478bd9Sstevel@tonic-gate  */
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate char	*malloc();
209*7c478bd9Sstevel@tonic-gate char	*strtok();
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate 
212