2 * Printer interface for DOS.
3 * Copyright (c) 1996-2001 Markku Rossi.
5 * Author: Markku Rossi <mtr@iki.fi>
9 * This file is part of GNU Enscript.
11 * Enscript is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * Enscript is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Enscript. If not, see <http://www.gnu.org/licenses/>.
27 /************************** Types and definitions ***************************/
34 /* If using temporary file, this is its name. */
37 /* Command to spool the temporary output. This is NULL if we
38 already spooled the output to `fp' and there is no
39 post-processing to do. */
43 typedef struct PrinterCtxRec PrinterCtxStruct;
44 typedef struct PrinterCtxRec *PrinterCtx;
47 /***************************** Global functions *****************************/
50 printer_open(char *cmd, char *options, char *queue_param, char *printer_name,
51 void **context_return)
55 ctx = xcalloc(1, sizeof(*ctx));
59 if (tmpnam(ctx->tmpfile) == NULL)
60 FATAL((stderr, _("could not create temporary spool file name: %s"),
63 /* Spool output to a temporary file and spool with with command
64 when the printer is closed. */
66 ctx->command = buffer_alloc();
68 buffer_append(ctx->command, cmd);
69 buffer_append(ctx->command, " ");
73 buffer_append(ctx->command, options);
74 buffer_append(ctx->command, " ");
79 buffer_append(ctx->command, queue_param);
80 buffer_append(ctx->command, printer_name);
81 buffer_append(ctx->command, " ");
84 buffer_append(ctx->command, ctx->tmpfile);
86 /* Open the temporary spool file. */
87 ctx->fp = fopen(ctx->tmpfile, "wb");
89 FATAL((stderr, _("Could not open temporary spool file `%s': %s"),
90 ctx->tmpfile, strerror(errno)));
94 /* Just open file pointer to the printer. */
95 ctx->fp = fopen(printer_name, "wb");
97 FATAL((stderr, _("Could not open printer `%s': %s"), printer_name,
101 *context_return = ctx;
108 printer_close(void *context)
110 PrinterCtx ctx = (PrinterCtx) context;
112 /* Close the output stream. */
115 /* Do we need to do post-processing (read spooling). */
119 if (system(buffer_ptr(ctx->command)) == -1)
120 FATAL((stderr, _("Could not spool temporary output `%s': %s"),
121 ctx->tmpfile, strerror(errno)));
123 /* We do not need the spool command anymore. */
124 buffer_free(ctx->command);
126 /* Unlink the temporary output file. */
127 (void) remove(ctx->tmpfile);