[9089] | 1 | /* |
---|
| 2 | * Copyright Milan Technology Inc., 1991, 1992 |
---|
| 3 | */ |
---|
| 4 | |
---|
| 5 | /* @(#)printer.c 2.0 10/9/92 */ |
---|
| 6 | /* |
---|
| 7 | * Host software modified to include printer classes on 6/19/92 Host software |
---|
| 8 | * modified to include notifications on 6/22/92 Mods to use global options |
---|
| 9 | * struct and error enums 7/7/92 |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | #include <stdio.h> |
---|
| 13 | #include <string.h> |
---|
| 14 | #include "std.h" |
---|
| 15 | #include "dp.h" |
---|
| 16 | extern s_options g_opt; |
---|
| 17 | #define ESC 27 |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | /* |
---|
| 21 | * These routines allow you to specify a configuration file to name the |
---|
| 22 | * printer different than the host. To use this create the file |
---|
| 23 | * /usr/local/milan/fastport_config with the lines: |
---|
| 24 | * |
---|
| 25 | * name <printer name used in lpr> hostname <hostname that you wish it to go to> |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #ifdef ANSI |
---|
| 29 | int |
---|
| 30 | hsw_Getprinterconfig(void) |
---|
| 31 | #else |
---|
| 32 | int |
---|
| 33 | hsw_Getprinterconfig() |
---|
| 34 | #endif |
---|
| 35 | { |
---|
| 36 | char *config_file; |
---|
| 37 | char *env_config; |
---|
| 38 | FILE *c_file; |
---|
| 39 | char e_mssg[MAXSTRNGLEN], data_buffer[MAX_BUFFER]; |
---|
| 40 | i32 num_args; |
---|
| 41 | char arg1[MAXSTRNGLEN]; |
---|
| 42 | char tempstring[MAXSTRNGLEN]; |
---|
| 43 | char *tempstring2; |
---|
| 44 | struct stat stat_buff; |
---|
| 45 | char fpconfig_file[MAXFILELEN]; |
---|
| 46 | |
---|
| 47 | if (g_opt.current_dir) |
---|
| 48 | sprintf(fpconfig_file, "%s/.fpconfig", g_opt.current_dir); |
---|
| 49 | else |
---|
| 50 | strcpy(fpconfig_file, "./.fpconfig"); |
---|
| 51 | |
---|
| 52 | if (!stat(fpconfig_file, &stat_buff)) |
---|
| 53 | config_file = fpconfig_file; |
---|
| 54 | else if ((env_config = (char *) getenv("PRINTER_CONFIG"))) |
---|
| 55 | config_file = env_config; |
---|
| 56 | else |
---|
| 57 | config_file = "/usr/local/milan/fastport_config"; |
---|
| 58 | |
---|
| 59 | /* |
---|
| 60 | * open it and get the parameters |
---|
| 61 | */ |
---|
| 62 | |
---|
| 63 | if (!(c_file = fopen(config_file, "r"))) |
---|
| 64 | return (-1); /* NO ONE LOOKS AT THIS RETURN VALUE */ |
---|
| 65 | |
---|
| 66 | arg1[0] = (char) 0; |
---|
| 67 | while ((num_args = fscanf(c_file, "%s", arg1)) != EOF) { |
---|
| 68 | if (!strcasecmp(arg1, "hostname")) { |
---|
| 69 | fscanf(c_file, "%s", tempstring); |
---|
| 70 | /* |
---|
| 71 | * Include this hostname also into the printer list |
---|
| 72 | */ |
---|
| 73 | g_opt.prt_list = |
---|
| 74 | form_printer_list(tempstring, g_opt.prt_list, g_opt.dataport, APPEND); |
---|
| 75 | continue; |
---|
| 76 | } |
---|
| 77 | if (!strcasecmp(arg1, "serial")) { |
---|
| 78 | g_opt.dataport = SERIAL; |
---|
| 79 | continue; |
---|
| 80 | } |
---|
| 81 | if (!strcasecmp(arg1, "parallel")) { |
---|
| 82 | g_opt.dataport = PARALLEL; |
---|
| 83 | continue; |
---|
| 84 | } |
---|
| 85 | if (!strcasecmp(arg1, "ctrld")) { |
---|
| 86 | g_opt.use_control_d = 1; |
---|
| 87 | continue; |
---|
| 88 | } |
---|
| 89 | if (!strcasecmp(arg1, "formfeed")) { |
---|
| 90 | g_opt.ff_flag = 1; |
---|
| 91 | continue; |
---|
| 92 | } |
---|
| 93 | if (!strcasecmp(arg1, "mapcrlf")) { |
---|
| 94 | g_opt.mapflg = 1; |
---|
| 95 | continue; |
---|
| 96 | } |
---|
| 97 | if (!strcasecmp(arg1, "asciifilter")) { |
---|
| 98 | g_opt.check_postscript = 1; |
---|
| 99 | fscanf(c_file, "%s", g_opt.asciiname); |
---|
| 100 | g_opt.asciifilter = g_opt.asciiname; |
---|
| 101 | continue; |
---|
| 102 | } |
---|
| 103 | #ifdef DATAGEN |
---|
| 104 | if (!strcasecmp(arg1, "dataport")) { |
---|
| 105 | char temp_port[20]; |
---|
| 106 | fscanf(c_file, "%s",temp_port ); |
---|
| 107 | g_opt.dataport = atoi(temp_port); |
---|
| 108 | continue; |
---|
| 109 | } |
---|
| 110 | #endif |
---|
| 111 | if (!strcasecmp(arg1, "checkpostscript")) { |
---|
| 112 | g_opt.check_postscript = 1; |
---|
| 113 | continue; |
---|
| 114 | } |
---|
| 115 | if (!strcasecmp(arg1, "dobanner")) { |
---|
| 116 | g_opt.dobanner = 1; |
---|
| 117 | continue; |
---|
| 118 | } |
---|
| 119 | if (!strcasecmp(arg1, "startfile")) { |
---|
| 120 | g_opt.send_startfile = 1; |
---|
| 121 | fscanf(c_file, "%s", g_opt.start_file); |
---|
| 122 | continue; |
---|
| 123 | } |
---|
| 124 | if (!strcasecmp(arg1, "endfile")) { |
---|
| 125 | g_opt.send_endfile = 1; |
---|
| 126 | fscanf(c_file, "%s", g_opt.end_file); |
---|
| 127 | continue; |
---|
| 128 | } |
---|
| 129 | if (!strcasecmp(arg1, "startstring")) { |
---|
| 130 | fgets(tempstring, sizeof(tempstring), c_file); |
---|
| 131 | if (strlen(tempstring)) |
---|
| 132 | g_opt.start_string = parse_string(tempstring); |
---|
| 133 | continue; |
---|
| 134 | } |
---|
| 135 | if (!strcasecmp(arg1, "endstring")) { |
---|
| 136 | fgets(tempstring, sizeof(tempstring), c_file); |
---|
| 137 | if (strlen(tempstring)) |
---|
| 138 | g_opt.end_string = parse_string(tempstring); |
---|
| 139 | continue; |
---|
| 140 | } |
---|
| 141 | /* Form a linked list of printers. */ |
---|
| 142 | if (!strcasecmp(arg1, "P_CLASS")) { |
---|
| 143 | fgets(tempstring, sizeof(tempstring), c_file); |
---|
| 144 | if (strlen(tempstring)) { |
---|
| 145 | /* If the line is not null/blank then */ |
---|
| 146 | tempstring2 = parse_string(tempstring); |
---|
| 147 | /* |
---|
| 148 | * Form a linked list of printer names and |
---|
| 149 | * return a pointer to the begining of the |
---|
| 150 | * list |
---|
| 151 | */ |
---|
| 152 | g_opt.use_printer_classes = 1; |
---|
| 153 | g_opt.prt_list = |
---|
| 154 | form_printer_list(tempstring2, g_opt.prt_list, PARALLEL, APPEND); |
---|
| 155 | } |
---|
| 156 | continue; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | if (!strcasecmp(arg1,"acctg")) { |
---|
| 160 | g_opt.acctg = 1; |
---|
| 161 | continue; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | if (!strcasecmp(arg1, "S_CLASS")) { |
---|
| 165 | fgets(tempstring, sizeof(tempstring), c_file); |
---|
| 166 | if (strlen(tempstring)) { |
---|
| 167 | /* If the line is not null/blank then */ |
---|
| 168 | tempstring2 = parse_string(tempstring); |
---|
| 169 | /* |
---|
| 170 | * Continue forming a list and put these |
---|
| 171 | * printers together |
---|
| 172 | */ |
---|
| 173 | g_opt.use_printer_classes = 1; |
---|
| 174 | g_opt.prt_list = |
---|
| 175 | form_printer_list(tempstring2, g_opt.prt_list, SERIAL, APPEND); |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | if (!strcasecmp(arg1, "errorfile")) { |
---|
| 179 | g_opt.notify_type.file = TRUE; |
---|
| 180 | fscanf(c_file, "%s", g_opt.notify_type.filename); |
---|
| 181 | continue; |
---|
| 182 | } |
---|
| 183 | if (!strcasecmp(arg1, "bannerfirst")) { |
---|
| 184 | g_opt.adobe.banner_first = 1; |
---|
| 185 | g_opt.dobanner = 1; |
---|
| 186 | continue; |
---|
| 187 | } |
---|
| 188 | if (!strcasecmp(arg1, "bannerlast")) { |
---|
| 189 | g_opt.adobe.banner_last = 1; |
---|
| 190 | g_opt.dobanner = 1; |
---|
| 191 | continue; |
---|
| 192 | } |
---|
| 193 | if (!strcasecmp(arg1, "program")) { |
---|
| 194 | g_opt.notify_type.program = TRUE; |
---|
| 195 | fscanf(c_file, "%s", g_opt.notify_type.prog_name); |
---|
| 196 | continue; |
---|
| 197 | } |
---|
| 198 | if (!strcasecmp(arg1, "syslog")) { |
---|
| 199 | g_opt.notify_type.syslog = TRUE; |
---|
| 200 | continue; |
---|
| 201 | } |
---|
| 202 | /* Notify by mail to the user */ |
---|
| 203 | if (!strcasecmp(arg1, "mail")) { |
---|
| 204 | /* Notify thru mail */ |
---|
| 205 | g_opt.notify_type.mail = TRUE; |
---|
| 206 | fscanf(c_file, "%s", g_opt.notify_type.user); |
---|
| 207 | } |
---|
| 208 | arg1[0] = (char) 0; |
---|
| 209 | } |
---|
| 210 | return (g_opt.prt_list ? 1 : 0); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | #ifdef ANSI |
---|
| 214 | void |
---|
| 215 | get_printername(char *printer) |
---|
| 216 | #else |
---|
| 217 | void |
---|
| 218 | get_printername(printer) |
---|
| 219 | char *printer; |
---|
| 220 | #endif |
---|
| 221 | { |
---|
| 222 | char buff[MAXFILELEN]; |
---|
| 223 | char *tprinter; |
---|
| 224 | |
---|
| 225 | #ifdef MIPS |
---|
| 226 | tprinter = (char *) getwd(buff); |
---|
| 227 | #else |
---|
| 228 | tprinter = (char *) getcwd(buff, 40); |
---|
| 229 | #endif |
---|
| 230 | |
---|
| 231 | tprinter = (char *) rindex(buff, '/'); |
---|
| 232 | strcpy(printer, tprinter + 1); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | #ifdef ANSI |
---|
| 236 | char * |
---|
| 237 | parse_string(char *src_string) |
---|
| 238 | #else |
---|
| 239 | char * |
---|
| 240 | parse_string(src_string) |
---|
| 241 | char *src_string; |
---|
| 242 | #endif |
---|
| 243 | { |
---|
| 244 | char *temp_string; |
---|
| 245 | char *c_ptr; |
---|
| 246 | char *temp_ptr; |
---|
| 247 | |
---|
| 248 | while (*src_string == ' ') |
---|
| 249 | src_string++; |
---|
| 250 | |
---|
| 251 | if (*src_string == '"') |
---|
| 252 | src_string++; |
---|
| 253 | |
---|
| 254 | temp_ptr = &src_string[strlen(src_string) - 1]; |
---|
| 255 | while (temp_ptr != src_string) { |
---|
| 256 | if (*temp_ptr == '"') { |
---|
| 257 | *temp_ptr = 0; |
---|
| 258 | break; |
---|
| 259 | } |
---|
| 260 | temp_ptr--; |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | temp_ptr = temp_string = (char *) malloc(strlen(src_string) + 1); |
---|
| 264 | c_ptr = src_string; |
---|
| 265 | while (*c_ptr) |
---|
| 266 | expand_char(&c_ptr, &temp_ptr); |
---|
| 267 | |
---|
| 268 | return (temp_string); |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | #ifdef ANSI |
---|
| 272 | void |
---|
| 273 | expand_char(char **src, char **dest) |
---|
| 274 | #else |
---|
| 275 | void |
---|
| 276 | expand_char(src, dest) |
---|
| 277 | char **src; |
---|
| 278 | char **dest; |
---|
| 279 | #endif |
---|
| 280 | { |
---|
| 281 | char *t_src; |
---|
| 282 | char *t_dest; |
---|
| 283 | t_src = *src; |
---|
| 284 | t_dest = *dest; |
---|
| 285 | |
---|
| 286 | if ((*t_src == 'M') && (*(t_src + 1) == '-')) { |
---|
| 287 | *t_dest++ = ESC; |
---|
| 288 | (*dest)++; |
---|
| 289 | *src += 2; |
---|
| 290 | return; |
---|
| 291 | } |
---|
| 292 | if ((*t_src == 'C') && (*(t_src + 1) == '^')) { |
---|
| 293 | *t_dest++ = *(t_src + 2) - ('a' - 1); |
---|
| 294 | *src += 2; |
---|
| 295 | (*dest)++; |
---|
| 296 | return; |
---|
| 297 | } |
---|
| 298 | *t_dest = *t_src; |
---|
| 299 | (*src)++; |
---|
| 300 | (*dest)++; |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | |
---|
| 304 | /* |
---|
| 305 | * This routine forms a linked list of printers. The string containing |
---|
| 306 | * printers is specified in the '.fpconfig' file. The printer names are |
---|
| 307 | * separated by commas. We look for these separators, collect them one by |
---|
| 308 | * one, form a linked list and return the pointer to the begining of such a |
---|
| 309 | * list to the calling program. |
---|
| 310 | */ |
---|
| 311 | |
---|
| 312 | #ifdef ANSI |
---|
| 313 | hsw_PCONFIG * |
---|
| 314 | form_printer_list(char *string, |
---|
| 315 | hsw_PCONFIG * prt_ptr, |
---|
| 316 | int ptype, int where) |
---|
| 317 | #else |
---|
| 318 | hsw_PCONFIG * |
---|
| 319 | form_printer_list(string, prt_ptr, ptype, where) |
---|
| 320 | char *string; /* String containing printer names */ |
---|
| 321 | hsw_PCONFIG *prt_ptr;/* Pointer to printer class */ |
---|
| 322 | int ptype; /* Printer type 0=> serial, 1=> Parallel */ |
---|
| 323 | int where; /* where=APPEND or PREPEND */ |
---|
| 324 | #endif |
---|
| 325 | { |
---|
| 326 | hsw_PCONFIG *runner, *node; |
---|
| 327 | char name1[50]; |
---|
| 328 | int i = 0; |
---|
| 329 | |
---|
| 330 | int limit = strlen(string); |
---|
| 331 | |
---|
| 332 | while (i < limit) { |
---|
| 333 | sscanf(string, "%s", name1); |
---|
| 334 | i += strlen(name1) + 1; /* One for blank space */ |
---|
| 335 | |
---|
| 336 | /* Remove the part of the string that has already been read */ |
---|
| 337 | |
---|
| 338 | string += strlen(name1) + 1; /* One for blank space */ |
---|
| 339 | |
---|
| 340 | /* Create an entry for the printer */ |
---|
| 341 | node = (hsw_PCONFIG *) malloc(sizeof(hsw_PCONFIG)); |
---|
| 342 | strcpy(node->printer_name, name1); |
---|
| 343 | node->ptype = ptype; |
---|
| 344 | node->next_printer = 0; |
---|
| 345 | if (!prt_ptr) |
---|
| 346 | prt_ptr = node; |
---|
| 347 | else { |
---|
| 348 | if (where == PREPEND) { |
---|
| 349 | node->next_printer = prt_ptr; |
---|
| 350 | prt_ptr = node; |
---|
| 351 | } else { |
---|
| 352 | runner = prt_ptr; |
---|
| 353 | while (runner->next_printer) |
---|
| 354 | runner = runner->next_printer; |
---|
| 355 | runner->next_printer = node; |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | } |
---|
| 359 | return (prt_ptr); |
---|
| 360 | } |
---|