1 | #ifndef lint |
---|
2 | #define _NOTICE static char |
---|
3 | _NOTICE N1[] = "Copyright (c) 1985,1987,1990,1991,1992 Adobe Systems Incorporated"; |
---|
4 | _NOTICE N2[] = "GOVERNMENT END USERS: See Notice file in TranScript library directory"; |
---|
5 | _NOTICE N3[] = "-- probably /usr/lib/ps/Notice"; |
---|
6 | _NOTICE RCSID[]="$Header: /afs/dev.mit.edu/source/repository/third/transcript/src/psbanner.bsd,v 1.1.1.1 1996-10-07 20:25:50 ghudson Exp $"; |
---|
7 | #endif |
---|
8 | /* psbanner.c |
---|
9 | * |
---|
10 | * Copyright (C) 1985,1987,1990,1991,1992 Adobe Systems Incorporated. All |
---|
11 | * rights reserved. |
---|
12 | * GOVERNMENT END USERS: See Notice file in TranScript library directory |
---|
13 | * -- probably /usr/lib/ps/Notice |
---|
14 | * |
---|
15 | * 4.2BSD lpr/lpd banner break page filter for PostScript printers |
---|
16 | * (formerly "psof" in TranScript release 1.0) |
---|
17 | * |
---|
18 | * psbanner is used ONLY to print the "break page" -- |
---|
19 | * the job seperator/banner page; the "if" filter |
---|
20 | * which invokes (pscomm) MUST be in |
---|
21 | * the printcap database for handling communications. |
---|
22 | * |
---|
23 | * This filter does not actually print anything; it sends |
---|
24 | * nothing to the printer (stdout). Instead, it writes a |
---|
25 | * file in the current working directory (which is the |
---|
26 | * spooling directory) called ".banner" which, depending |
---|
27 | * on the value of printer options BANNERFIRST and |
---|
28 | * BANNERLAST, may get printed by pscomm filter when |
---|
29 | * it is envoked. |
---|
30 | * |
---|
31 | * psbanner parses the standard input (the SHORT banner string) |
---|
32 | * into PostScript format as the argument to a "Banner" |
---|
33 | * PostScript procedure (defined in $BANNERPRO, from the environment) |
---|
34 | * which will set the job name on the printer and print a |
---|
35 | * banner-style job break page. |
---|
36 | * |
---|
37 | * NOTE that quoting characters into PostScript form is |
---|
38 | * necessary. |
---|
39 | * |
---|
40 | * psbanner gets called with: |
---|
41 | * stdin == the short banner string to print (see below) |
---|
42 | * stdout == the printer (not used here) |
---|
43 | * stderr == the printer log file |
---|
44 | * argv == (empty) |
---|
45 | * cwd == the spool directory |
---|
46 | * env == VERBOSELOG, BANNERPRO |
---|
47 | * |
---|
48 | * An example of the "short banner string" input is: |
---|
49 | adobe:shore Job: test.data Date: Tue Sep 18 16:22:33 1984 |
---|
50 | ^Y^A |
---|
51 | * where the ^Y^A are actual control characters signalling |
---|
52 | * the end of the banner input and the time to do SIGSTOP |
---|
53 | * ourselves so that the controlling lpd will |
---|
54 | * invoke the next filter. (N.B. this is, regretably, NOT |
---|
55 | * documented in any of the lpr/printcap/spooler manual pages.) |
---|
56 | * |
---|
57 | * |
---|
58 | * I have decided to let the PostScript side try to parse the |
---|
59 | * string if possible, since it's easier to change the PS code |
---|
60 | * then to do so in C. If you don't like the way the |
---|
61 | * banner page looks, change the BANNERPRO file to |
---|
62 | * do something else. |
---|
63 | * |
---|
64 | * RCSLOG: |
---|
65 | * $Log: not supported by cvs2svn $ |
---|
66 | Revision 3.3 1992/08/21 16:26:32 snichols |
---|
67 | Release 4.0 |
---|
68 | |
---|
69 | Revision 3.2 1992/07/14 22:50:34 snichols |
---|
70 | Updated copyright. |
---|
71 | |
---|
72 | * Revision 3.1 1992/05/26 21:49:26 snichols |
---|
73 | * comments after endif |
---|
74 | * |
---|
75 | * Revision 3.0 1991/06/17 16:50:45 snichols |
---|
76 | * Release 3.0 |
---|
77 | * |
---|
78 | * Revision 2.4 1991/03/25 23:13:19 snichols |
---|
79 | * made forward dec'l for DoBanner. |
---|
80 | * |
---|
81 | * Revision 2.3 1990/12/12 10:04:49 snichols |
---|
82 | * new configuration stuff. |
---|
83 | * |
---|
84 | * Revision 2.2 87/11/17 16:50:39 byron |
---|
85 | * *** empty log message *** |
---|
86 | * |
---|
87 | * Revision 2.2 87/11/17 16:50:39 byron |
---|
88 | * Release 2.1 |
---|
89 | * |
---|
90 | * Revision 2.1.1.5 87/11/12 13:40:38 byron |
---|
91 | * Changed Government user's notice. |
---|
92 | * |
---|
93 | * Revision 2.1.1.4 87/06/18 16:05:00 byron |
---|
94 | * Removed unlink of banner file from interrupt processing. pscomm may |
---|
95 | * need it after the interrupt, and will delete it itself. |
---|
96 | * |
---|
97 | * Revision 2.1.1.3 87/06/09 14:10:46 byron |
---|
98 | * Only do the .banner file if pscomm will use it. |
---|
99 | * Also, fixed a couple of bugs in the previous revision. |
---|
100 | * |
---|
101 | * Revision 2.1.1.2 87/06/04 10:55:37 byron |
---|
102 | * Added error handling for banner buffer overflow. Buffer could overflow |
---|
103 | * before, producing random (bad) problems and psbanner crashes. |
---|
104 | * |
---|
105 | * Revision 2.1.1.1 87/04/23 10:25:48 byron |
---|
106 | * Copyright notice. |
---|
107 | * |
---|
108 | * Revision 2.2 86/11/02 14:19:27 shore |
---|
109 | * Product Update |
---|
110 | * |
---|
111 | * Revision 2.1 85/11/24 11:49:49 shore |
---|
112 | * Product Release 2.0 |
---|
113 | * |
---|
114 | * Revision 1.1 85/11/20 01:02:26 shore |
---|
115 | * Initial revision |
---|
116 | * |
---|
117 | * |
---|
118 | */ |
---|
119 | |
---|
120 | #include <stdio.h> |
---|
121 | #include <signal.h> |
---|
122 | #include <strings.h> |
---|
123 | #include "transcript.h" |
---|
124 | #include "psspool.h" |
---|
125 | #include "config.h" |
---|
126 | |
---|
127 | #ifdef BDEBUG |
---|
128 | #define debugp(x) fprintf x; fflush(stderr); |
---|
129 | #else |
---|
130 | #define debugp(x) |
---|
131 | #endif /* BDEBUG */ |
---|
132 | |
---|
133 | private char *prog; /* invoking program name (i.e., psbanner) */ |
---|
134 | private char *pname; /* intended printer ? */ |
---|
135 | |
---|
136 | #define BANBUFSIZE 500 /* Size of banner string input buffer */ |
---|
137 | private char bannerbuf[BANBUFSIZE]; /* PS'd short banner string */ |
---|
138 | private int bannerfull; /* TRUE when bannerbuf is full */ |
---|
139 | private char *verboselog; /* do log file reporting (from env) */ |
---|
140 | private char *bannerpro; /* prolog file name (from env) */ |
---|
141 | private int VerboseLog; |
---|
142 | private int dobanner; /* True = We are printing banners */ |
---|
143 | |
---|
144 | private VOID on_int(); |
---|
145 | |
---|
146 | static int DoBanner(); |
---|
147 | |
---|
148 | main(argc,argv) |
---|
149 | int argc; |
---|
150 | char *argv[]; |
---|
151 | { |
---|
152 | register int c; |
---|
153 | register char *bp; |
---|
154 | register FILE *in = stdin; |
---|
155 | int done = 0; |
---|
156 | char *p; |
---|
157 | |
---|
158 | VOIDC signal(SIGINT, on_int); |
---|
159 | |
---|
160 | VOIDC fclose(stdout); /* we don't talk to the printer */ |
---|
161 | prog = *argv; /* argv[0] == program name */ |
---|
162 | pname = *(++argv); |
---|
163 | |
---|
164 | VerboseLog = 1; |
---|
165 | if (verboselog = envget("VERBOSELOG")) { |
---|
166 | VerboseLog = atoi(verboselog); |
---|
167 | } |
---|
168 | |
---|
169 | dobanner = 0; /* Assume we will not be doing banners */ |
---|
170 | p = envget("BANNERFIRST"); |
---|
171 | if( p != NULL && atoi(p) != 0 ) dobanner = 1; |
---|
172 | p = envget("BANNERLAST"); |
---|
173 | if( p != NULL && atoi(p) != 0 ) dobanner = 1; |
---|
174 | |
---|
175 | |
---|
176 | bannerpro = envget("BANNERPRO"); |
---|
177 | |
---|
178 | bp = bannerbuf; |
---|
179 | bannerfull = 0; |
---|
180 | while (!done) { |
---|
181 | switch (c = getc (in)) { |
---|
182 | case EOF: /* this doesn't seem to happen */ |
---|
183 | done = 1; |
---|
184 | break; |
---|
185 | case '\n': |
---|
186 | case '\f': |
---|
187 | case '\r': |
---|
188 | break; |
---|
189 | case '\t': |
---|
190 | if (!bannerfull) *bp++ = ' '; |
---|
191 | break; |
---|
192 | case '\\': case '\(': case '\)': /* quote chars for POSTSCRIPT */ |
---|
193 | if (!bannerfull) { |
---|
194 | *bp++ = '\\'; |
---|
195 | *bp++ = c; |
---|
196 | } |
---|
197 | break; |
---|
198 | case '\031': |
---|
199 | if ((c = getc (in)) == '\1') { |
---|
200 | *bp = '\0'; |
---|
201 | /* done, ship the banner line */ |
---|
202 | if (bp != bannerbuf) { |
---|
203 | if(dobanner) DoBanner(); /* Do it if we will use it */ |
---|
204 | if (verboselog) { |
---|
205 | fprintf(stderr, "%s: %s\n", prog, bannerbuf); |
---|
206 | VOIDC fflush(stderr); |
---|
207 | } |
---|
208 | } |
---|
209 | VOIDC kill (getpid (), SIGSTOP); |
---|
210 | /* do we get continued for next job ? */ |
---|
211 | debugp((stderr,"%s: continued %d\n", |
---|
212 | prog,bp == bannerbuf)); |
---|
213 | bp = bannerbuf; |
---|
214 | *bp = '\0'; |
---|
215 | bannerfull = 0; |
---|
216 | break; |
---|
217 | } |
---|
218 | else { |
---|
219 | VOIDC ungetc(c, in); |
---|
220 | if (!bannerfull) *bp++ = ' '; |
---|
221 | break; |
---|
222 | } |
---|
223 | default: /* simple text */ |
---|
224 | if (!bannerfull) *bp++ = c; |
---|
225 | break; |
---|
226 | } |
---|
227 | if (!bannerfull && bp >= &bannerbuf[BANBUFSIZE-3]) { |
---|
228 | *bp++ = '\n'; *bp++ = '\0'; |
---|
229 | fprintf (stderr,"%s: banner buffer overflow\n",prog); |
---|
230 | VOIDC fflush(stderr); |
---|
231 | bannerfull = 1; |
---|
232 | } |
---|
233 | } |
---|
234 | /* didn't expect to get here, just exit */ |
---|
235 | debugp((stderr,"%s: done\n",prog)); |
---|
236 | VOIDC unlink(".banner"); |
---|
237 | exit (0); |
---|
238 | } |
---|
239 | |
---|
240 | static int DoBanner() { |
---|
241 | register FILE *out; |
---|
242 | |
---|
243 | if ((out = fopen(".banner","w")) == NULL) { |
---|
244 | fprintf(stderr,"%s: can't open .banner", prog); |
---|
245 | VOIDC fflush(stderr); |
---|
246 | exit (THROW_AWAY); |
---|
247 | } |
---|
248 | if (copyfile(bannerpro,out)) { |
---|
249 | /* error copying file, don't print a break page */ |
---|
250 | fprintf(stderr,"%s: trouble writing .banner\n",prog); |
---|
251 | VOIDC fflush(stderr); |
---|
252 | VOIDC unlink(".banner"); |
---|
253 | return; |
---|
254 | } |
---|
255 | fprintf(out, "(%s)(%s)Banner\n", pname, bannerbuf); |
---|
256 | VOIDC fclose(out); /* this does a flush */ |
---|
257 | } |
---|
258 | |
---|
259 | private VOID on_int() { |
---|
260 | /* NOTE: Let pscomm unlink banner -- it may want to use it */ |
---|
261 | exit (THROW_AWAY); |
---|
262 | } |
---|