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