17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5de81e71eSTim Marsland  * Common Development and Distribution License (the "License").
6de81e71eSTim Marsland  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21de81e71eSTim Marsland 
227c478bd9Sstevel@tonic-gate /*
23de81e71eSTim Marsland  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
30de81e71eSTim Marsland #ifndef	_POSTIO_POSTIO_H
31de81e71eSTim Marsland #define	_POSTIO_POSTIO_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * Definitions used by the program that sends jobs to PostScript printers.
367c478bd9Sstevel@tonic-gate  *
37de81e71eSTim Marsland  * POSTBEGIN, if it's not NULL, is some PostScript code that's sent to the
38de81e71eSTim Marsland  * printer before any of the input files. It's not terribly important since
39de81e71eSTim Marsland  * the same thing can be accomplished in other ways, but this approach is
40de81e71eSTim Marsland  * convenient. POSTBEGIN is initialized so as to disable job timeouts. The
41de81e71eSTim Marsland  * string can also be set on the command line using the -P option.
427c478bd9Sstevel@tonic-gate  *
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate 
45de81e71eSTim Marsland #define	POSTBEGIN	"%!PS\nstatusdict /waittimeout 0 put\n"
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
48de81e71eSTim Marsland  * The following help determine where postio is when it's running - either
49de81e71eSTim Marsland  * in the START, SEND, or DONE states. Primarily controls what's done in
50de81e71eSTim Marsland  * getstatus().
51de81e71eSTim Marsland  * RADIAN occasionally had problems with two way conversations. Anyway this
52de81e71eSTim Marsland  * stuff can be used to prevent status queries while we're transmitting a
53de81e71eSTim Marsland  * job. Enabled by the -q option.
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate 
57de81e71eSTim Marsland #define	NOTCONNECTED	0
58de81e71eSTim Marsland #define	START		1
59de81e71eSTim Marsland #define	SEND		2
60de81e71eSTim Marsland #define	DONE		3
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
63de81e71eSTim Marsland  * Previous versions of postio only ran as a single process. That was (and
64de81e71eSTim Marsland  * still * is) convenient, but meant we could only flow control one direction.
65de81e71eSTim Marsland  * Data coming back from the printer occasionally got lost, but that didn't
66de81e71eSTim Marsland  * often hurt (except for lost error messages). Anyway I've added code that
67de81e71eSTim Marsland  * lets you split the program into separate read and write processes, thereby
68de81e71eSTim Marsland  * helping to prevent data loss in both directions. It should be particularly
69de81e71eSTim Marsland  * useful when you're sending a job that you expect will be returning useful
70de81e71eSTim Marsland  * data over the communications line.
71de81e71eSTim Marsland  *
72de81e71eSTim Marsland  * The next three definitions control what's done with data on communications
73de81e71eSTim Marsland  * line.  The READ flag means the line can be read, while the WRITE flag means
74de81e71eSTim Marsland  * it can be written. When we're running as a single process both flags are
75de81e71eSTim Marsland  * set. I tried to overlay the separate read/write process code on what was
76de81e71eSTim Marsland  * there and working for one process. The implementation isn't as good as it
77de81e71eSTim Marsland  * could be, but should be safe. The single process version still works,
78de81e71eSTim Marsland  * and remains the default.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate 
81de81e71eSTim Marsland #define	READ		1
82de81e71eSTim Marsland #define	WRITE		2
83de81e71eSTim Marsland #define	READWRITE	3
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * Messages generated on the printer and returned over the communications line
877c478bd9Sstevel@tonic-gate  * look like,
887c478bd9Sstevel@tonic-gate  *
897c478bd9Sstevel@tonic-gate  *	%%[ status: idle; source: serial 25 ]%%
907c478bd9Sstevel@tonic-gate  *	%%[ status: waiting; source: serial 25 ]%%
917c478bd9Sstevel@tonic-gate  *	%%[ status: initializing; source: serial 25 ]%%
927c478bd9Sstevel@tonic-gate  *	%%[ status: busy; source: serial 25 ]%%
937c478bd9Sstevel@tonic-gate  *	%%[ status: printing; source: serial 25 ]%%
947c478bd9Sstevel@tonic-gate  *	%%[ status: PrinterError: out of paper; source: serial 25 ]%%
957c478bd9Sstevel@tonic-gate  *	%%[ status: PrinterError: no paper tray; source: serial 25 ]%%
967c478bd9Sstevel@tonic-gate  *
977c478bd9Sstevel@tonic-gate  *	%%[ PrinterError: out of paper; source: serial 25 ]%%
987c478bd9Sstevel@tonic-gate  *	%%[ PrinterError: no paper tray; source: serial 25 ]%%
997c478bd9Sstevel@tonic-gate  *
1007c478bd9Sstevel@tonic-gate  *	%%[ Error: undefined; OffendingCommand: xxx ]%%
1017c478bd9Sstevel@tonic-gate  *	%%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
1027c478bd9Sstevel@tonic-gate  *
1037c478bd9Sstevel@tonic-gate  * although the list isn't meant to be complete.
1047c478bd9Sstevel@tonic-gate  *
1057c478bd9Sstevel@tonic-gate  * The following constants are used to classify the recognized printer states.
1067c478bd9Sstevel@tonic-gate  * readline() reads complete lines from ttyi and stores them in array mesg[].
1077c478bd9Sstevel@tonic-gate  * getstatus() looks for the "%%[ " and " ]%%" delimiters that bracket printer
108de81e71eSTim Marsland  * messages and if found it tries to parse the enclosed message. After the
109de81e71eSTim Marsland  * lookup one of the following numbers is returned as an indication of the
110de81e71eSTim Marsland  * existence or content of the printer message. The return value is used in
111de81e71eSTim Marsland  * start(), send(), and done() to figure out what's happening and what can
112de81e71eSTim Marsland  * be done next.
1137c478bd9Sstevel@tonic-gate  */
1147c478bd9Sstevel@tonic-gate 
115de81e71eSTim Marsland #define	BUSY		0		/* processing data already sent */
116de81e71eSTim Marsland #define	WAITING		1		/* printer wants more data */
117de81e71eSTim Marsland #define	PRINTING	2		/* printing a page */
118de81e71eSTim Marsland #define	IDLE		3		/* ready to start the next job */
119de81e71eSTim Marsland #define	ENDOFJOB	4		/* readline() builds this up on EOF */
120de81e71eSTim Marsland #define	PRINTERERROR	5		/* PrinterError - eg. out of paper */
121de81e71eSTim Marsland #define	ERROR		6		/* some kind of PostScript error */
122de81e71eSTim Marsland #define	FLUSHING	7		/* throwing out the rest of the job */
123de81e71eSTim Marsland #define	INITIALIZING	8		/* printer is booting */
124de81e71eSTim Marsland #define	DISCONNECT	9		/* from Datakit! */
125de81e71eSTim Marsland #define	UNKNOWN		10		/* in case we missed anything */
126de81e71eSTim Marsland #define	NOSTATUS	11		/* no response from the printer */
127de81e71eSTim Marsland 
128de81e71eSTim Marsland #define	WRITEPROCESS	12		/* dummy states for write process */
129de81e71eSTim Marsland #define	INTERACTIVE	13		/* and interactive mode */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * An array of type Status is used, in getstatus(), to figure out the printer's
1337c478bd9Sstevel@tonic-gate  * current state. Just helps convert strings representing the current state into
1347c478bd9Sstevel@tonic-gate  * integer codes that other routines use.
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate typedef struct {
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	char	*state;			/* printer's current status */
1407c478bd9Sstevel@tonic-gate 	int	val;			/* value returned by getstatus() */
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate } Status;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /*
145de81e71eSTim Marsland  * STATUS is used to initialize an array of type Status that translates the
146de81e71eSTim Marsland  * ASCII strings returned by the printer into appropriate codes that can be
147de81e71eSTim Marsland  * used later on in the program. getstatus() converts characters to lower
148de81e71eSTim Marsland  * case, so if you add any entries make them lower case and put them in
149de81e71eSTim Marsland  * before the UNKNOWN entry.
1507c478bd9Sstevel@tonic-gate  * The lookup terminates when we get a match or when an entry with a NULL state
1517c478bd9Sstevel@tonic-gate  * is found.
1527c478bd9Sstevel@tonic-gate  *
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate 
155de81e71eSTim Marsland #define	STATUS								\
1567c478bd9Sstevel@tonic-gate 									\
1577c478bd9Sstevel@tonic-gate 	{								\
1587c478bd9Sstevel@tonic-gate 	    "busy", BUSY,						\
1597c478bd9Sstevel@tonic-gate 	    "waiting", WAITING,						\
1607c478bd9Sstevel@tonic-gate 	    "printing", PRINTING,					\
1617c478bd9Sstevel@tonic-gate 	    "idle", IDLE,						\
1627c478bd9Sstevel@tonic-gate 	    "endofjob", ENDOFJOB,					\
1637c478bd9Sstevel@tonic-gate 	    "printererror", PRINTERERROR,				\
1647c478bd9Sstevel@tonic-gate 	    "error", ERROR,						\
1657c478bd9Sstevel@tonic-gate 	    "flushing", FLUSHING,					\
1667c478bd9Sstevel@tonic-gate 	    "initializing", INITIALIZING,				\
1677c478bd9Sstevel@tonic-gate 	    NULL, UNKNOWN						\
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  *
1727c478bd9Sstevel@tonic-gate  * The baud rate can be set on the command line using the -b option. If you omit
1737c478bd9Sstevel@tonic-gate  * it BAUDRATE will be used.
1747c478bd9Sstevel@tonic-gate  *
1757c478bd9Sstevel@tonic-gate  */
1767c478bd9Sstevel@tonic-gate 
177de81e71eSTim Marsland #define	BAUDRATE	B9600
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  *
181de81e71eSTim Marsland  * An array of type Baud is used, in routine getbaud(), to translate ASCII
182de81e71eSTim Marsland  * strings into termio values that represent the requested baud rate.
1837c478bd9Sstevel@tonic-gate  *
1847c478bd9Sstevel@tonic-gate  */
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate typedef struct {
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	char	*rate;			/* string identifying the baud rate */
1897c478bd9Sstevel@tonic-gate 	short	val;			/* and its termio.h value */
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate } Baud;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate  *
1957c478bd9Sstevel@tonic-gate  * BAUDTABLE initializes the array that's used to translate baud rate requests
1967c478bd9Sstevel@tonic-gate  * into termio values. It needs to end with an entry that has NULL assigned to
1977c478bd9Sstevel@tonic-gate  * the rate field.
1987c478bd9Sstevel@tonic-gate  *
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate 
201de81e71eSTim Marsland #define	BAUDTABLE							\
2027c478bd9Sstevel@tonic-gate 									\
2037c478bd9Sstevel@tonic-gate 	{								\
2047c478bd9Sstevel@tonic-gate 	    "9600", B9600,						\
2057c478bd9Sstevel@tonic-gate 	    "B9600", B9600,						\
2067c478bd9Sstevel@tonic-gate 	    "19200", EXTA,						\
2077c478bd9Sstevel@tonic-gate 	    "19.2", EXTA,						\
2087c478bd9Sstevel@tonic-gate 	    "B19200", EXTA,						\
2097c478bd9Sstevel@tonic-gate 	    "EXTA", EXTA,						\
2107c478bd9Sstevel@tonic-gate 	    "1200", B1200,						\
2117c478bd9Sstevel@tonic-gate 	    "B1200", B1200,						\
2127c478bd9Sstevel@tonic-gate 	    "2400", B2400,						\
2137c478bd9Sstevel@tonic-gate 	    "B2400", B2400,						\
2147c478bd9Sstevel@tonic-gate 	    "B4800", B4800,						\
2157c478bd9Sstevel@tonic-gate 	    "4800", B4800,						\
2167c478bd9Sstevel@tonic-gate 	    "38400", EXTB,						\
2177c478bd9Sstevel@tonic-gate 	    "38.4", EXTB,						\
2187c478bd9Sstevel@tonic-gate 	    "B38400", EXTB,						\
2197c478bd9Sstevel@tonic-gate 	    "EXTB", EXTB,						\
2207c478bd9Sstevel@tonic-gate 	    "57600", B57600,						\
2217c478bd9Sstevel@tonic-gate 	    "57.6", B57600,						\
2227c478bd9Sstevel@tonic-gate 	    "76800", B76800,						\
2237c478bd9Sstevel@tonic-gate 	    "76.8", B76800,						\
2247c478bd9Sstevel@tonic-gate 	    "115200", B115200,						\
2257c478bd9Sstevel@tonic-gate 	    "115.2", B115200,						\
2267c478bd9Sstevel@tonic-gate 	    "153600", B153600,						\
2277c478bd9Sstevel@tonic-gate 	    "153.6", B153600,						\
2287c478bd9Sstevel@tonic-gate 	    "230400", B230400,						\
2297c478bd9Sstevel@tonic-gate 	    "230.4", B230400,						\
2307c478bd9Sstevel@tonic-gate 	    "307200", B307200,						\
2317c478bd9Sstevel@tonic-gate 	    "307.2", B307200,						\
2327c478bd9Sstevel@tonic-gate 	    "460800", B460800,						\
2337c478bd9Sstevel@tonic-gate 	    "460.8", B460800,						\
234de81e71eSTim Marsland 	    "921600", B921600,						\
235de81e71eSTim Marsland 	    "921.6", B921600,						\
236*d9c3e05cSJoshua M. Clulow 	    "1000000", B1000000,					\
237*d9c3e05cSJoshua M. Clulow 	    "1152000", B1152000,					\
238*d9c3e05cSJoshua M. Clulow 	    "1500000", B1500000,					\
239*d9c3e05cSJoshua M. Clulow 	    "2000000", B2000000,					\
240*d9c3e05cSJoshua M. Clulow 	    "2500000", B2500000,					\
241*d9c3e05cSJoshua M. Clulow 	    "3000000", B3000000,					\
242*d9c3e05cSJoshua M. Clulow 	    "3500000", B3500000,					\
243*d9c3e05cSJoshua M. Clulow 	    "4000000", B4000000,					\
2447c478bd9Sstevel@tonic-gate 	    NULL, B9600							\
2457c478bd9Sstevel@tonic-gate 	}
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate /*
2487c478bd9Sstevel@tonic-gate  *
2497c478bd9Sstevel@tonic-gate  * A few miscellaneous definitions. BLOCKSIZE is the default size of the buffer
250de81e71eSTim Marsland  * used for reading the input files (changed with the -B option). MESGSIZE is
251de81e71eSTim Marsland  * the size of the character array used to store printer status lines - don't
252de81e71eSTim Marsland  * make it too small!
2537c478bd9Sstevel@tonic-gate  *
2547c478bd9Sstevel@tonic-gate  */
2557c478bd9Sstevel@tonic-gate 
256de81e71eSTim Marsland #define	BLOCKSIZE	2048
257de81e71eSTim Marsland #define	MESGSIZE	512
258de81e71eSTim Marsland 
259de81e71eSTim Marsland #endif	/* _POSTIO_POSTIO_H */
260