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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #ifndef	_POSTIO_POSTIO_H
31 #define	_POSTIO_POSTIO_H
32 
33 /*
34  *
35  * Definitions used by the program that sends jobs to PostScript printers.
36  *
37  * POSTBEGIN, if it's not NULL, is some PostScript code that's sent to the
38  * printer before any of the input files. It's not terribly important since
39  * the same thing can be accomplished in other ways, but this approach is
40  * convenient. POSTBEGIN is initialized so as to disable job timeouts. The
41  * string can also be set on the command line using the -P option.
42  *
43  */
44 
45 #define	POSTBEGIN	"%!PS\nstatusdict /waittimeout 0 put\n"
46 
47 /*
48  * The following help determine where postio is when it's running - either
49  * in the START, SEND, or DONE states. Primarily controls what's done in
50  * getstatus().
51  * RADIAN occasionally had problems with two way conversations. Anyway this
52  * stuff can be used to prevent status queries while we're transmitting a
53  * job. Enabled by the -q option.
54  *
55  */
56 
57 #define	NOTCONNECTED	0
58 #define	START		1
59 #define	SEND		2
60 #define	DONE		3
61 
62 /*
63  * Previous versions of postio only ran as a single process. That was (and
64  * still * is) convenient, but meant we could only flow control one direction.
65  * Data coming back from the printer occasionally got lost, but that didn't
66  * often hurt (except for lost error messages). Anyway I've added code that
67  * lets you split the program into separate read and write processes, thereby
68  * helping to prevent data loss in both directions. It should be particularly
69  * useful when you're sending a job that you expect will be returning useful
70  * data over the communications line.
71  *
72  * The next three definitions control what's done with data on communications
73  * line.  The READ flag means the line can be read, while the WRITE flag means
74  * it can be written. When we're running as a single process both flags are
75  * set. I tried to overlay the separate read/write process code on what was
76  * there and working for one process. The implementation isn't as good as it
77  * could be, but should be safe. The single process version still works,
78  * and remains the default.
79  */
80 
81 #define	READ		1
82 #define	WRITE		2
83 #define	READWRITE	3
84 
85 /*
86  * Messages generated on the printer and returned over the communications line
87  * look like,
88  *
89  *	%%[ status: idle; source: serial 25 ]%%
90  *	%%[ status: waiting; source: serial 25 ]%%
91  *	%%[ status: initializing; source: serial 25 ]%%
92  *	%%[ status: busy; source: serial 25 ]%%
93  *	%%[ status: printing; source: serial 25 ]%%
94  *	%%[ status: PrinterError: out of paper; source: serial 25 ]%%
95  *	%%[ status: PrinterError: no paper tray; source: serial 25 ]%%
96  *
97  *	%%[ PrinterError: out of paper; source: serial 25 ]%%
98  *	%%[ PrinterError: no paper tray; source: serial 25 ]%%
99  *
100  *	%%[ Error: undefined; OffendingCommand: xxx ]%%
101  *	%%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
102  *
103  * although the list isn't meant to be complete.
104  *
105  * The following constants are used to classify the recognized printer states.
106  * readline() reads complete lines from ttyi and stores them in array mesg[].
107  * getstatus() looks for the "%%[ " and " ]%%" delimiters that bracket printer
108  * messages and if found it tries to parse the enclosed message. After the
109  * lookup one of the following numbers is returned as an indication of the
110  * existence or content of the printer message. The return value is used in
111  * start(), send(), and done() to figure out what's happening and what can
112  * be done next.
113  */
114 
115 #define	BUSY		0		/* processing data already sent */
116 #define	WAITING		1		/* printer wants more data */
117 #define	PRINTING	2		/* printing a page */
118 #define	IDLE		3		/* ready to start the next job */
119 #define	ENDOFJOB	4		/* readline() builds this up on EOF */
120 #define	PRINTERERROR	5		/* PrinterError - eg. out of paper */
121 #define	ERROR		6		/* some kind of PostScript error */
122 #define	FLUSHING	7		/* throwing out the rest of the job */
123 #define	INITIALIZING	8		/* printer is booting */
124 #define	DISCONNECT	9		/* from Datakit! */
125 #define	UNKNOWN		10		/* in case we missed anything */
126 #define	NOSTATUS	11		/* no response from the printer */
127 
128 #define	WRITEPROCESS	12		/* dummy states for write process */
129 #define	INTERACTIVE	13		/* and interactive mode */
130 
131 /*
132  * An array of type Status is used, in getstatus(), to figure out the printer's
133  * current state. Just helps convert strings representing the current state into
134  * integer codes that other routines use.
135  */
136 
137 typedef struct {
138 
139 	char	*state;			/* printer's current status */
140 	int	val;			/* value returned by getstatus() */
141 
142 } Status;
143 
144 /*
145  * STATUS is used to initialize an array of type Status that translates the
146  * ASCII strings returned by the printer into appropriate codes that can be
147  * used later on in the program. getstatus() converts characters to lower
148  * case, so if you add any entries make them lower case and put them in
149  * before the UNKNOWN entry.
150  * The lookup terminates when we get a match or when an entry with a NULL state
151  * is found.
152  *
153  */
154 
155 #define	STATUS								\
156 									\
157 	{								\
158 	    "busy", BUSY,						\
159 	    "waiting", WAITING,						\
160 	    "printing", PRINTING,					\
161 	    "idle", IDLE,						\
162 	    "endofjob", ENDOFJOB,					\
163 	    "printererror", PRINTERERROR,				\
164 	    "error", ERROR,						\
165 	    "flushing", FLUSHING,					\
166 	    "initializing", INITIALIZING,				\
167 	    NULL, UNKNOWN						\
168 	}
169 
170 /*
171  *
172  * The baud rate can be set on the command line using the -b option. If you omit
173  * it BAUDRATE will be used.
174  *
175  */
176 
177 #define	BAUDRATE	B9600
178 
179 /*
180  *
181  * An array of type Baud is used, in routine getbaud(), to translate ASCII
182  * strings into termio values that represent the requested baud rate.
183  *
184  */
185 
186 typedef struct {
187 
188 	char	*rate;			/* string identifying the baud rate */
189 	short	val;			/* and its termio.h value */
190 
191 } Baud;
192 
193 /*
194  *
195  * BAUDTABLE initializes the array that's used to translate baud rate requests
196  * into termio values. It needs to end with an entry that has NULL assigned to
197  * the rate field.
198  *
199  */
200 
201 #define	BAUDTABLE							\
202 									\
203 	{								\
204 	    "9600", B9600,						\
205 	    "B9600", B9600,						\
206 	    "19200", EXTA,						\
207 	    "19.2", EXTA,						\
208 	    "B19200", EXTA,						\
209 	    "EXTA", EXTA,						\
210 	    "1200", B1200,						\
211 	    "B1200", B1200,						\
212 	    "2400", B2400,						\
213 	    "B2400", B2400,						\
214 	    "B4800", B4800,						\
215 	    "4800", B4800,						\
216 	    "38400", EXTB,						\
217 	    "38.4", EXTB,						\
218 	    "B38400", EXTB,						\
219 	    "EXTB", EXTB,						\
220 	    "57600", B57600,						\
221 	    "57.6", B57600,						\
222 	    "76800", B76800,						\
223 	    "76.8", B76800,						\
224 	    "115200", B115200,						\
225 	    "115.2", B115200,						\
226 	    "153600", B153600,						\
227 	    "153.6", B153600,						\
228 	    "230400", B230400,						\
229 	    "230.4", B230400,						\
230 	    "307200", B307200,						\
231 	    "307.2", B307200,						\
232 	    "460800", B460800,						\
233 	    "460.8", B460800,						\
234 	    "921600", B921600,						\
235 	    "921.6", B921600,						\
236 	    "1000000", B1000000,					\
237 	    "1152000", B1152000,					\
238 	    "1500000", B1500000,					\
239 	    "2000000", B2000000,					\
240 	    "2500000", B2500000,					\
241 	    "3000000", B3000000,					\
242 	    "3500000", B3500000,					\
243 	    "4000000", B4000000,					\
244 	    NULL, B9600							\
245 	}
246 
247 /*
248  *
249  * A few miscellaneous definitions. BLOCKSIZE is the default size of the buffer
250  * used for reading the input files (changed with the -B option). MESGSIZE is
251  * the size of the character array used to store printer status lines - don't
252  * make it too small!
253  *
254  */
255 
256 #define	BLOCKSIZE	2048
257 #define	MESGSIZE	512
258 
259 #endif	/* _POSTIO_POSTIO_H */
260