1 | /* |
---|
2 | * Copyright Milan Technology Inc. 1991, 1992 |
---|
3 | */ |
---|
4 | |
---|
5 | /* @(#)options.c 2.1 10/15/92 */ |
---|
6 | |
---|
7 | #include "std.h" |
---|
8 | #include "dp.h" |
---|
9 | #include "errors.h" |
---|
10 | |
---|
11 | |
---|
12 | extern char *g_filter_name; /* The name by which this program was invoked */ |
---|
13 | extern char *VERSION; |
---|
14 | |
---|
15 | #ifdef ANSI |
---|
16 | void setDefaults(s_options* opt) |
---|
17 | #else |
---|
18 | void setDefaults(opt) |
---|
19 | s_options* opt; |
---|
20 | #endif |
---|
21 | { |
---|
22 | memset(opt, (char)0, sizeof(s_options)); |
---|
23 | |
---|
24 | opt->dataport = 2000; |
---|
25 | opt->adobe.banner_first = 1; |
---|
26 | } |
---|
27 | |
---|
28 | /* ADOBE: checks for those environment variables used by transcript |
---|
29 | * and sets the relevant option in the global option struct. |
---|
30 | */ |
---|
31 | |
---|
32 | /* envget is a getenv |
---|
33 | * if the variable is not present in the environment or |
---|
34 | * it has the null string as value envget returns NULL |
---|
35 | * otherwise it returns the value from the environment |
---|
36 | */ |
---|
37 | |
---|
38 | #ifdef ANSI |
---|
39 | char *envget(char *var) |
---|
40 | #else |
---|
41 | char *envget(var) |
---|
42 | char *var; |
---|
43 | #endif |
---|
44 | { |
---|
45 | char *val; |
---|
46 | if (!((val = (char*)getenv(var))) || (*val == 0)) |
---|
47 | return((char *) 0); |
---|
48 | else |
---|
49 | return(val); |
---|
50 | } |
---|
51 | |
---|
52 | void parseAdobeEnvironment() |
---|
53 | { |
---|
54 | char *test = 0; |
---|
55 | |
---|
56 | test = envget("BANNERFIRST"); |
---|
57 | if (test) { |
---|
58 | g_opt.adobe.banner_first = atoi(test); |
---|
59 | g_opt.dobanner = 1; |
---|
60 | } |
---|
61 | |
---|
62 | test = envget("BANNERLAST"); |
---|
63 | if (test) { |
---|
64 | g_opt.adobe.banner_last = atoi(test); |
---|
65 | g_opt.dobanner = 1; |
---|
66 | } |
---|
67 | |
---|
68 | test = envget("VERBOSELOG"); |
---|
69 | if (test) |
---|
70 | g_opt.adobe.verbose_log = atoi(test); |
---|
71 | } |
---|
72 | |
---|
73 | #ifdef ANSI |
---|
74 | void handleAdobeArgs(int argc, char **argv) |
---|
75 | #else |
---|
76 | void handleAdobeArgs(argc, argv) |
---|
77 | int argc; |
---|
78 | char **argv; |
---|
79 | #endif |
---|
80 | { |
---|
81 | /* In Transcript we are called like this: |
---|
82 | * |
---|
83 | * $PSCOMM -P $pname -p $prog -n $user -h $host $afile |
---|
84 | * |
---|
85 | * pscomm gets called with: |
---|
86 | * stdin == the file to print (may be a pipe!) |
---|
87 | * stdout == the printer |
---|
88 | * stderr == the printer log file |
---|
89 | * cwd == the spool directory |
---|
90 | * argv == set up by interface shell script: |
---|
91 | * filtername -P printer -p filtername [-r] (don't ever reverse) |
---|
92 | * -n login -h host [accntfile] |
---|
93 | * |
---|
94 | */ |
---|
95 | |
---|
96 | /* parse command-line arguments |
---|
97 | * the argv (see header comments) comes from the spooler daemon |
---|
98 | * itself, so it should be canonical, but at least one 4.2-based |
---|
99 | * system uses -nlogin -hhost (insead of -n login -h host) so I |
---|
100 | * check for both |
---|
101 | */ |
---|
102 | |
---|
103 | register char *cp; |
---|
104 | char **av = argv; |
---|
105 | g_opt.adobe.prog = *av; |
---|
106 | |
---|
107 | while (--argc) { |
---|
108 | if (*(cp = *++av) == '-') { |
---|
109 | switch (*(cp + 1)) { |
---|
110 | case 'P': /* printer name */ |
---|
111 | argc--; |
---|
112 | g_opt.adobe.pname = *(++av); |
---|
113 | break; |
---|
114 | |
---|
115 | case 'n': /* user name */ |
---|
116 | argc--; |
---|
117 | g_opt.adobe.name = *(++av); |
---|
118 | break; |
---|
119 | |
---|
120 | case 'h': /* host */ |
---|
121 | argc--; |
---|
122 | g_opt.adobe.host = *(++av); |
---|
123 | break; |
---|
124 | |
---|
125 | case 'p': /* prog */ |
---|
126 | argc--; |
---|
127 | g_opt.adobe.prog = *(++av); |
---|
128 | break; |
---|
129 | |
---|
130 | default: /* unknown */ |
---|
131 | fprintf(stderr, "%s: unknown option: %s\n", g_opt.adobe.prog, cp); |
---|
132 | break; |
---|
133 | } |
---|
134 | } |
---|
135 | else |
---|
136 | g_opt.adobe.accountingfile = cp; |
---|
137 | } |
---|
138 | |
---|
139 | /* ADOBE: |
---|
140 | * If g_opt.adobe.pname is set then we want to add this |
---|
141 | * printer to the list of printers. But we want this to be |
---|
142 | * the lowest priority printer (ask Dan why) and put it last |
---|
143 | * after those found in .fpconfig. |
---|
144 | * So this routine better be called after the .fpconfig |
---|
145 | * file is parsed. |
---|
146 | */ |
---|
147 | if (g_opt.adobe.pname) |
---|
148 | g_opt.prt_list = |
---|
149 | form_printer_list(g_opt.adobe.pname, g_opt.prt_list, PARALLEL, APPEND); |
---|
150 | } |
---|
151 | |
---|
152 | /* sets g_opt.current_dir if specified on command line (-D) */ |
---|
153 | #ifdef ANSI |
---|
154 | void checkForCurrentDir(int argc, char **argv) |
---|
155 | #else |
---|
156 | void checkForCurrentDir(argc, argv) |
---|
157 | int argc; |
---|
158 | char **argv; |
---|
159 | #endif |
---|
160 | { |
---|
161 | int i = 1; |
---|
162 | while (i < argc) { |
---|
163 | if (argv[i][0] != '-') { |
---|
164 | i++; |
---|
165 | continue; |
---|
166 | } |
---|
167 | if (argv[i][1] == 'D') { |
---|
168 | g_opt.current_dir = argv[i+1]; |
---|
169 | break; |
---|
170 | } |
---|
171 | i++; |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | /* parses the command line args and returns "output_dest" flag */ |
---|
177 | |
---|
178 | /* We first look into command line option. If a host has been |
---|
179 | * specified, then we add the host to the printer list first. Then we look |
---|
180 | * at host specified in the '.fpconfig' file. We add that host to the list. |
---|
181 | * Finally we look at S_CLASS and P_CLASS options and add the hosts |
---|
182 | * accordingly. |
---|
183 | */ |
---|
184 | |
---|
185 | #ifdef ANSI |
---|
186 | int parseCommandLineArgs(int argc, char **argv) |
---|
187 | #else |
---|
188 | int parseCommandLineArgs(argc, argv) |
---|
189 | int argc; |
---|
190 | char **argv; |
---|
191 | #endif |
---|
192 | { |
---|
193 | int iflag=0, wflag = 0, nflag = 0, lflag = 0, i; |
---|
194 | char *host = 0; |
---|
195 | |
---|
196 | if ((g_filter_name = (char *)rindex(argv[0], '/'))) |
---|
197 | g_filter_name++; |
---|
198 | else |
---|
199 | g_filter_name = argv[0]; |
---|
200 | |
---|
201 | if ( ! (strcmp(g_filter_name, "fpcomm"))) { |
---|
202 | /* If this is called from Adobe Transcript then we skip the |
---|
203 | * rest of the command line handling and just handle the |
---|
204 | * regular options that goto pscomm: |
---|
205 | */ |
---|
206 | parseAdobeEnvironment(); |
---|
207 | handleAdobeArgs(argc, argv); |
---|
208 | /* return 2 for stderr so that any output back from the |
---|
209 | * socket goes to transcript log file. |
---|
210 | */ |
---|
211 | return 2; |
---|
212 | } |
---|
213 | |
---|
214 | if ( ! (strcmp(g_filter_name, "fpcomm_s"))) { |
---|
215 | /* If this is called from Adobe Transcript then we skip the |
---|
216 | * rest of the command line handling and just handle the |
---|
217 | * regular options that goto pscomm: |
---|
218 | */ |
---|
219 | g_opt.dataport = SERIAL ; |
---|
220 | parseAdobeEnvironment(); |
---|
221 | handleAdobeArgs(argc, argv); |
---|
222 | /* Make sure that the printer type is set to serial */ |
---|
223 | if (g_opt.prt_list) { |
---|
224 | g_opt.prt_list->ptype = SERIAL; |
---|
225 | } |
---|
226 | return 2; |
---|
227 | } |
---|
228 | |
---|
229 | if ( ! (strcmp(g_filter_name, "parfilter"))) { |
---|
230 | g_opt.dataport = PARALLEL; |
---|
231 | g_opt.use_control_d = 0; |
---|
232 | g_opt.real_filter = 1; |
---|
233 | } |
---|
234 | else if ( ! (strcmp(g_filter_name, "pardfilter"))) { |
---|
235 | g_opt.dataport = PARALLEL; |
---|
236 | g_opt.use_control_d = 1; |
---|
237 | g_opt.real_filter = 1; |
---|
238 | } |
---|
239 | else if ( ! (strcmp(g_filter_name, "serfilter"))) { |
---|
240 | g_opt.dataport = SERIAL; |
---|
241 | g_opt.use_control_d = 0; |
---|
242 | g_opt.real_filter = 1; |
---|
243 | } |
---|
244 | else if ( ! (strcmp(g_filter_name, "serdfilter"))) { |
---|
245 | g_opt.dataport = SERIAL; |
---|
246 | g_opt.use_control_d = 1; |
---|
247 | g_opt.real_filter = 1; |
---|
248 | } |
---|
249 | else if ( ! (strcmp(g_filter_name, "psparfilter"))) { |
---|
250 | g_opt.dataport = PARALLEL; |
---|
251 | g_opt.real_filter = 1; |
---|
252 | g_opt.check_postscript = 1; |
---|
253 | } |
---|
254 | else if ( ! (strcmp(g_filter_name, "pspardfilter"))) { |
---|
255 | g_opt.dataport = PARALLEL; |
---|
256 | g_opt.use_control_d = 1; |
---|
257 | g_opt.real_filter = 1; |
---|
258 | g_opt.check_postscript = 1; |
---|
259 | } |
---|
260 | else if ( ! (strcmp(g_filter_name, "psserfilter"))) { |
---|
261 | g_opt.dataport = SERIAL; |
---|
262 | g_opt.real_filter = 1; |
---|
263 | g_opt.check_postscript = 1; |
---|
264 | } |
---|
265 | else if ( ! (strcmp(g_filter_name, "psserdfilter"))) { |
---|
266 | /* code folded from here */ |
---|
267 | g_opt.dataport = SERIAL; |
---|
268 | g_opt.use_control_d = 1; |
---|
269 | g_opt.real_filter = 1; |
---|
270 | g_opt.check_postscript = 1; |
---|
271 | /* unfolding */ |
---|
272 | } |
---|
273 | |
---|
274 | i = 1; |
---|
275 | while ((i < argc) && (argv[i][0] == '-')) { |
---|
276 | switch (argv[i][1]) { |
---|
277 | case 'P': |
---|
278 | if (! strcasecmp(argv[i], "-P_CLASS")) |
---|
279 | g_opt.prt_list = |
---|
280 | form_printer_list(argv[i+1], g_opt.prt_list, PARALLEL, APPEND); |
---|
281 | else |
---|
282 | host = argv[i + 1]; |
---|
283 | i++; |
---|
284 | break; |
---|
285 | |
---|
286 | case 'S': |
---|
287 | if (! strcasecmp(argv[i], "-S_CLASS")) |
---|
288 | g_opt.prt_list = |
---|
289 | form_printer_list(argv[i+1], g_opt.prt_list, SERIAL, APPEND); |
---|
290 | i++; |
---|
291 | break; |
---|
292 | case 'c': |
---|
293 | if (! strcasecmp(argv[i], "-closewait")) |
---|
294 | g_opt.closewait = 1; |
---|
295 | break; |
---|
296 | |
---|
297 | case 'D': |
---|
298 | g_opt.current_dir = argv[i+1]; |
---|
299 | i++; |
---|
300 | break; |
---|
301 | |
---|
302 | case 'A': |
---|
303 | g_opt.asciifilter = argv[i + 1]; |
---|
304 | g_opt.check_postscript = 1; |
---|
305 | i++; |
---|
306 | break; |
---|
307 | |
---|
308 | case 'i': |
---|
309 | iflag++; |
---|
310 | break; |
---|
311 | case 'w': |
---|
312 | wflag++; |
---|
313 | break; |
---|
314 | case 'l': |
---|
315 | lflag++; |
---|
316 | break; |
---|
317 | case 'd': |
---|
318 | #ifdef DATAGEN |
---|
319 | if (!strcmp(argv[i], "-dataport")) { |
---|
320 | g_opt.dataport = atoi(argv[i + 1]); |
---|
321 | i++; |
---|
322 | break; |
---|
323 | } |
---|
324 | #endif |
---|
325 | g_opt.use_control_d = 1; |
---|
326 | break; |
---|
327 | case 'b': |
---|
328 | g_opt.dobanner = 1; |
---|
329 | break; |
---|
330 | case 's': |
---|
331 | if (!strcmp(argv[i], "-startstring")) { |
---|
332 | g_opt.start_string = parse_string(argv[i + 1]); |
---|
333 | i++; |
---|
334 | } |
---|
335 | else if (! strcmp(argv[i], "-startfile")) { |
---|
336 | g_opt.send_startfile = 1; |
---|
337 | strcpy(g_opt.start_file, argv[i + 1]); |
---|
338 | i++; |
---|
339 | } |
---|
340 | else if (! strcasecmp(argv[i], "-sys")) |
---|
341 | g_opt.notify_type.syslog = 1; |
---|
342 | else |
---|
343 | g_opt.dataport = SERIAL; |
---|
344 | break; |
---|
345 | case 'e': |
---|
346 | if (!strcmp(argv[i], "-endstring")) { |
---|
347 | g_opt.end_string = parse_string(argv[i + 1]); |
---|
348 | i++; |
---|
349 | } |
---|
350 | else if (! strcmp(argv[i], "-endfile")) { |
---|
351 | g_opt.send_endfile = 1; |
---|
352 | strcpy(g_opt.end_file, argv[i + 1]); |
---|
353 | i++; |
---|
354 | } |
---|
355 | else if (! strcasecmp(argv[i], "-errorfile")) { |
---|
356 | g_opt.notify_type.file = 1; |
---|
357 | strcpy(g_opt.notify_type.filename, argv[i+1]); |
---|
358 | i++; |
---|
359 | } |
---|
360 | break; |
---|
361 | case 'x': |
---|
362 | case 'y': |
---|
363 | break; |
---|
364 | case 'm': |
---|
365 | if (!strcmp(argv[i], "-mail")) { |
---|
366 | g_opt.notify_type.mail = 1; |
---|
367 | strcpy(g_opt.notify_type.user, argv[i+1]); |
---|
368 | i++; |
---|
369 | } |
---|
370 | else |
---|
371 | g_opt.mapflg++; |
---|
372 | break; |
---|
373 | case 'n': |
---|
374 | i++; |
---|
375 | nflag++; |
---|
376 | break; |
---|
377 | case 'h': |
---|
378 | i++; |
---|
379 | break; |
---|
380 | case 'f': |
---|
381 | g_opt.ff_flag = 1; |
---|
382 | break; |
---|
383 | case 'p': |
---|
384 | if (! strcasecmp(argv[i], "-program")) { |
---|
385 | g_opt.notify_type.program = 1; /* Notify thru program */ |
---|
386 | strcpy(g_opt.notify_type.prog_name, argv[i+1]); |
---|
387 | i++; |
---|
388 | } |
---|
389 | else |
---|
390 | g_opt.check_postscript = 1; |
---|
391 | break; |
---|
392 | case 'V': |
---|
393 | fprintf(stderr, "version = %s\n", VERSION); |
---|
394 | break; |
---|
395 | default: |
---|
396 | break; |
---|
397 | } |
---|
398 | i++; |
---|
399 | } |
---|
400 | |
---|
401 | if (! nflag ) { |
---|
402 | for (; i < argc; i++) { |
---|
403 | if (! access(argv[i], R_OK)) |
---|
404 | /* files to read and send across */ |
---|
405 | add_file(&g_opt.file_list, argv[i]); |
---|
406 | else |
---|
407 | error_notify(ERR_ILLFILE,0); |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | /* If a host has been specified on the command line |
---|
412 | * then add this to the FRONT of the list of printers. |
---|
413 | */ |
---|
414 | if (host) |
---|
415 | g_opt.prt_list = |
---|
416 | form_printer_list(host, g_opt.prt_list, g_opt.dataport, PREPEND); |
---|
417 | |
---|
418 | return (iflag || wflag || lflag ) ? 2 : 1; |
---|
419 | } |
---|
420 | |
---|