/* filename can be one of the following values * "" Spool in default queue * "\\spool\queue" Spool in "queue" * "|command" open an output pipe using popen() * "filename" open filename using fopen() * "port" open port using fopen() */ FILE * gp_open_printer(char fname[gp_file_name_sizeof], int binary_mode) { FILE *pfile; if ((strlen(fname) == 0) || is_os2_spool(fname)) { if (isos2) { /* default or spool */ if (pm_spool(NULL, fname)) /* check if spool queue valid */ return NULL; pfile = gp_open_scratch_file(gp_scratch_file_name_prefix, pm_prntmp, (binary_mode ? "wb" : "w")); } else pfile = fopen("PRN", (binary_mode ? "wb" : "w")); } else if ((isos2) && (fname[0] == '|')) /* pipe */ pfile = popen(fname + 1, (binary_mode ? "wb" : "w")); else /* normal file or port */ pfile = fopen(fname, (binary_mode ? "wb" : "w")); if (pfile == (FILE *) NULL) return (FILE *) NULL; if (!isos2) gp_set_file_binary(fileno(pfile), binary_mode); return pfile; }
static int os2_printer_fclose(gx_io_device * iodev, FILE * file) { os2_printer_t *pr = (os2_printer_t *)iodev->state; fclose(file); pm_spool(pr->memory, pr->filename, pr->queue); unlink(pr->filename); return 0; }
/* Close the connection to the printer. */ void gp_close_printer(FILE * pfile, const char *fname) { if (isos2 && (fname[0] == '|')) pclose(pfile); else fclose(pfile); if ((strlen(fname) == 0) || is_os2_spool(fname)) { /* spool temporary file */ pm_spool(pm_prntmp, fname); unlink(pm_prntmp); } }