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 * This program 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 2, or (at your option)
16 * This program 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 this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
29 /************************** Types and definitions ***************************/
36 /* If using temporary file, this is its name. */
39 /* Command to spool the temporary output. This is NULL if we
40 already spooled the output to `fp' and there is no
41 post-processing to do. */
45 typedef struct PrinterCtxRec PrinterCtxStruct;
46 typedef struct PrinterCtxRec *PrinterCtx;
49 /***************************** Global functions *****************************/
52 printer_open(char *cmd, char *options, char *queue_param, char *printer_name,
53 void **context_return)
57 ctx = xcalloc(1, sizeof(*ctx));
61 if (tmpnam(ctx->tmpfile) == NULL)
62 FATAL((stderr, _("could not create temporary spool file name: %s"),
65 /* Spool output to a temporary file and spool with with command
66 when the printer is closed. */
68 ctx->command = buffer_alloc();
70 buffer_append(ctx->command, cmd);
71 buffer_append(ctx->command, " ");
75 buffer_append(ctx->command, options);
76 buffer_append(ctx->command, " ");
81 buffer_append(ctx->command, queue_param);
82 buffer_append(ctx->command, printer_name);
83 buffer_append(ctx->command, " ");
86 buffer_append(ctx->command, ctx->tmpfile);
88 /* Open the temporary spool file. */
89 ctx->fp = fopen(ctx->tmpfile, "wb");
91 FATAL((stderr, _("Could not open temporary spool file `%s': %s"),
92 ctx->tmpfile, strerror(errno)));
96 /* Just open file pointer to the printer. */
97 ctx->fp = fopen(printer_name, "wb");
99 FATAL((stderr, _("Could not open printer `%s': %s"), printer_name,
103 *context_return = ctx;
110 printer_close(void *context)
112 PrinterCtx ctx = (PrinterCtx) context;
114 /* Close the output stream. */
117 /* Do we need to do post-processing (read spooling). */
121 if (system(buffer_ptr(ctx->command)) == -1)
122 FATAL((stderr, _("Could not spool temporary output `%s': %s"),
123 ctx->tmpfile, strerror(errno)));
125 /* We do not need the spool command anymore. */
126 buffer_free(ctx->command);
128 /* Unlink the temporary output file. */
129 (void) remove(ctx->tmpfile);