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 /* 23 * Copyright 1995 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 31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */ 32 /* 33 * 34 * Definitions used by the program that sends jobs to PostScript printers. 35 * 36 * POSTBEGIN, if it's not NULL, is some PostScript code that's sent to the printer 37 * before any of the input files. It's not terribly important since the same thing 38 * can be accomplished in other ways, but this approach is convenient. POSTBEGIN 39 * is initialized so as to disable job timeouts. The string can also be set on the 40 * command line using the -P option. 41 * 42 */ 43 44 #define POSTBEGIN "%!PS\nstatusdict /waittimeout 0 put\n" 45 46 /* 47 * 48 * The following help determine where postio is when it's running - either in the 49 * START, SEND, or DONE states. Primarily controls what's done in getstatus(). 50 * RADIAN occasionally had problems with two way conversations. Anyway this stuff 51 * can be used to prevent status queries while we're transmitting a job. Enabled 52 * by the -q option. 53 * 54 */ 55 56 #define NOTCONNECTED 0 57 #define START 1 58 #define SEND 2 59 #define DONE 3 60 61 /* 62 * 63 * Previous versions of postio only ran as a single process. That was (and still 64 * is) convenient, but meant we could only flow control one direction. Data coming 65 * back from the printer occasionally got lost, but that didn't often hurt (except 66 * for lost error messages). Anyway I've added code that lets you split the program 67 * into separate read and write processes, thereby helping to prevent data loss in 68 * both directions. It should be particularly useful when you're sending a job that 69 * you expect will be returning useful data over the communications line. 70 * 71 * The next three definitions control what's done with data on communications line. 72 * The READ flag means the line can be read, while the WRITE flag means it can be 73 * written. When we're running as a single process both flags are set. I tried to 74 * overlay the separate read/write process code on what was there and working for 75 * one process. The implementation isn't as good as it could be, but should be 76 * safe. The single process version still works, and remains the default. 77 * 78 */ 79 80 #define READ 1 81 #define WRITE 2 82 #define READWRITE 3 83 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 lookup 109 * one of the following numbers is returned as an indication of the existence or 110 * content of the printer message. The return value is used in start(), send(), 111 * and done() to figure out what's happening and what can be done next. 112 * 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 * 133 * An array of type Status is used, in getstatus(), to figure out the printer's 134 * current state. Just helps convert strings representing the current state into 135 * integer codes that other routines use. 136 * 137 */ 138 139 typedef struct { 140 141 char *state; /* printer's current status */ 142 int val; /* value returned by getstatus() */ 143 144 } Status; 145 146 /* 147 * 148 * STATUS is used to initialize an array of type Status that translates the ASCII 149 * strings returned by the printer into appropriate codes that can be used later 150 * on in the program. getstatus() converts characters to lower case, so if you 151 * add any entries make them lower case and put them in before the UNKNOWN entry. 152 * The lookup terminates when we get a match or when an entry with a NULL state 153 * is found. 154 * 155 */ 156 157 #define STATUS \ 158 \ 159 { \ 160 "busy", BUSY, \ 161 "waiting", WAITING, \ 162 "printing", PRINTING, \ 163 "idle", IDLE, \ 164 "endofjob", ENDOFJOB, \ 165 "printererror", PRINTERERROR, \ 166 "error", ERROR, \ 167 "flushing", FLUSHING, \ 168 "initializing", INITIALIZING, \ 169 NULL, UNKNOWN \ 170 } 171 172 /* 173 * 174 * The baud rate can be set on the command line using the -b option. If you omit 175 * it BAUDRATE will be used. 176 * 177 */ 178 179 #define BAUDRATE B9600 180 181 /* 182 * 183 * An array of type Baud is used, in routine getbaud(), to translate ASCII strings 184 * into termio values that represent the requested baud rate. 185 * 186 */ 187 188 typedef struct { 189 190 char *rate; /* string identifying the baud rate */ 191 short val; /* and its termio.h value */ 192 193 } Baud; 194 195 /* 196 * 197 * BAUDTABLE initializes the array that's used to translate baud rate requests 198 * into termio values. It needs to end with an entry that has NULL assigned to 199 * the rate field. 200 * 201 */ 202 203 #define BAUDTABLE \ 204 \ 205 { \ 206 "9600", B9600, \ 207 "B9600", B9600, \ 208 "19200", EXTA, \ 209 "19.2", EXTA, \ 210 "B19200", EXTA, \ 211 "EXTA", EXTA, \ 212 "1200", B1200, \ 213 "B1200", B1200, \ 214 "2400", B2400, \ 215 "B2400", B2400, \ 216 "B4800", B4800, \ 217 "4800", B4800, \ 218 "38400", EXTB, \ 219 "38.4", EXTB, \ 220 "B38400", EXTB, \ 221 "EXTB", EXTB, \ 222 "57600", B57600, \ 223 "57.6", B57600, \ 224 "76800", B76800, \ 225 "76.8", B76800, \ 226 "115200", B115200, \ 227 "115.2", B115200, \ 228 "153600", B153600, \ 229 "153.6", B153600, \ 230 "230400", B230400, \ 231 "230.4", B230400, \ 232 "307200", B307200, \ 233 "307.2", B307200, \ 234 "460800", B460800, \ 235 "460.8", B460800, \ 236 NULL, B9600 \ 237 } 238 239 /* 240 * 241 * A few miscellaneous definitions. BLOCKSIZE is the default size of the buffer 242 * used for reading the input files (changed with the -B option). MESGSIZE is the 243 * size of the character array used to store printer status lines - don't make it 244 * too small! 245 * 246 */ 247 248 #define BLOCKSIZE 2048 249 #define MESGSIZE 512 250