xref: /plan9/sys/src/cmd/postscript/postio/postio.h (revision 7dd7cddf99dd7472612f1413b4da293630e6b1bc)
1 /*
2  *
3  * POSTBEGIN, if it's not NULL, is some PostScript code that's sent to the printer
4  * before any of the input files. It's not terribly important since the same thing
5  * can be accomplished in other ways, but this approach is convenient. POSTBEGIN
6  * is initialized so as to disable job timeouts. The string can also be set on the
7  * command line using the -P option.
8  *
9  */
10 
11 #define POSTBEGIN	"statusdict /waittimeout 0 put\n"
12 
13 /*
14  *
15  * The following help determine where postio is when it's running - either in the
16  * START, SEND, or DONE states. Primarily controls what's done in getstatus().
17  * RADIAN occasionally had problems with two way conversations. Anyway this stuff
18  * can be used to prevent status queries while we're transmitting a job. Enabled
19  * by the -q option.
20  *
21  */
22 
23 #define NOTCONNECTED	0
24 #define START		1
25 #define SEND		2
26 #define DONE		3
27 
28 /*
29  *
30  * Previous versions of postio only ran as a single process. That was (and still
31  * is) convenient, but meant we could only flow control one direction. Data coming
32  * back from the printer occasionally got lost, but that didn't often hurt (except
33  * for lost error messages). Anyway I've added code that lets you split the program
34  * into separate read and write processes, thereby helping to prevent data loss in
35  * both directions. It should be particularly useful when you're sending a job that
36  * you expect will be returning useful data over the communications line.
37  *
38  * The next three definitions control what's done with data on communications line.
39  * The READ flag means the line can be read, while the WRITE flag means it can be
40  * written. When we're running as a single process both flags are set. I tried to
41  * overlay the separate read/write process code on what was there and working for
42  * one process. The implementation isn't as good as it could be, but should be
43  * safe. The single process version still works, and remains the default.
44  *
45  */
46 
47 #define READ		1
48 #define WRITE		2
49 #define READWRITE	3
50 
51 /*
52  *
53  * Messages generated on the printer and returned over the communications line
54  * look like,
55  *
56  *	%%[ status: idle; source: serial 25 ]%%
57  *	%%[ status: waiting; source: serial 25 ]%%
58  *	%%[ status: initializing; source: serial 25 ]%%
59  *	%%[ status: busy; source: serial 25 ]%%
60  *	%%[ status: printing; source: serial 25 ]%%
61  *	%%[ status: PrinterError: out of paper; source: serial 25 ]%%
62  *	%%[ status: PrinterError: no paper tray; source: serial 25 ]%%
63  *
64  *	%%[ PrinterError: out of paper; source: serial 25 ]%%
65  *	%%[ PrinterError: no paper tray; source: serial 25 ]%%
66  *
67  *	%%[ Error: undefined; OffendingCommand: xxx ]%%
68  *	%%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
69  *
70  * although the list isn't meant to be complete.
71  *
72  * The following constants are used to classify the recognized printer states.
73  * readline() reads complete lines from ttyi and stores them in array mesg[].
74  * getstatus() looks for the "%%[ " and " ]%%" delimiters that bracket printer
75  * messages and if found it tries to parse the enclosed message. After the lookup
76  * one of the following numbers is returned as an indication of the existence or
77  * content of the printer message. The return value is used in start(), send(),
78  * and done() to figure out what's happening and what can be done next.
79  *
80  */
81 
82 #define BUSY		0		/* processing data already sent */
83 #define WAITING		1		/* printer wants more data */
84 #define PRINTING	2		/* printing a page */
85 #define IDLE		3		/* ready to start the next job */
86 #define ENDOFJOB	4		/* readline() builds this up on EOF */
87 #define PRINTERERROR	5		/* PrinterError - eg. out of paper */
88 #define ERROR		6		/* some kind of PostScript error */
89 #define FLUSHING	7		/* throwing out the rest of the job */
90 #define INITIALIZING	8		/* printer is booting */
91 #define DISCONNECT	9		/* from Datakit! */
92 #define UNKNOWN		10		/* in case we missed anything */
93 #define NOSTATUS	11		/* no response from the printer */
94 
95 #define WRITEPROCESS	12		/* dummy states for write process */
96 #define INTERACTIVE	13		/* and interactive mode */
97 
98 /*
99  *
100  * An array of type Status is used, in getstatus(), to figure out the printer's
101  * current state. Just helps convert strings representing the current state into
102  * integer codes that other routines use.
103  *
104  */
105 
106 typedef struct {
107 	char	*state;			/* printer's current status */
108 	int	val;			/* value returned by getstatus() */
109 } Status;
110 
111 /*
112  *
113  * STATUS is used to initialize an array of type Status that translates the ASCII
114  * strings returned by the printer into appropriate codes that can be used later
115  * on in the program. getstatus() converts characters to lower case, so if you
116  * add any entries make them lower case and put them in before the UNKNOWN entry.
117  * The lookup terminates when we get a match or when an entry with a NULL state
118  * is found.
119  *
120  */
121 
122 #define STATUS								\
123 									\
124 	{								\
125 	    "busy", BUSY,						\
126 	    "waiting", WAITING,						\
127 	    "printing", PRINTING,					\
128 	    "idle", IDLE,						\
129 	    "endofjob", ENDOFJOB,					\
130 	    "printererror", PRINTERERROR,				\
131 	    "error", ERROR,						\
132 	    "flushing", FLUSHING,					\
133 	    "initializing", INITIALIZING,				\
134 	    NULL, UNKNOWN						\
135 	}
136 
137 /*
138  *
139  * The baud rate can be set on the command line using the -b option. If you omit
140  * it BAUDRATE will be used.
141  *
142  */
143 
144 #define BAUDRATE	B9600
145 
146 /*
147  *
148  * An array of type Baud is used, in routine getbaud(), to translate ASCII strings
149  * into termio values that represent the requested baud rate.
150  *
151  */
152 
153 typedef struct {
154 	char	*rate;			/* string identifying the baud rate */
155 	short	val;			/* and its termio.h value */
156 } Baud;
157 
158 /*
159  *
160  * BAUDTABLE initializes the array that's used to translate baud rate requests
161  * into termio values. It needs to end with an entry that has NULL assigned to
162  * the rate field.
163  *
164  */
165 
166 #define BAUDTABLE							\
167 									\
168 	{								\
169 	    "9600", B9600,						\
170 	    "B9600", B9600,						\
171 	    "19200", EXTA,						\
172 	    "19.2", EXTA,						\
173 	    "B19200", EXTA,						\
174 	    "EXTA", EXTA,						\
175 	    "1200", B1200,						\
176 	    "B1200", B1200,						\
177 	    "2400", B2400,						\
178 	    "B2400", B2400,						\
179 	    "B4800", B4800,						\
180 	    "4800", B4800,						\
181 	    "38400", EXTB,						\
182 	    "38.4", EXTB,						\
183 	    "B38400", EXTB,						\
184 	    "EXTB", EXTB,						\
185 	    NULL, B9600							\
186 	}
187 
188 /*
189  *
190  * A few miscellaneous definitions. BLOCKSIZE is the default size of the buffer
191  * used for reading the input files (changed with the -B option). MESGSIZE is the
192  * size of the character array used to store printer status lines - don't make it
193  * too small!
194  *
195  */
196 
197 #define BLOCKSIZE	2048
198 #define MESGSIZE	512
199 
200 /*
201  *
202  * Some of the non-integer valued functions used in postio.c.
203  *
204  */
205 
206 char	*find();
207 
208 char	*malloc();
209 char	*strtok();
210