1 /*
2 * Printer interface for popen() / lpr systems.
3 * Copyright (c) 1995-1999 Markku Rossi.
4 *
5 * Author: Markku Rossi <mtr@iki.fi>
6 */
7
8 /*
9 * This file is part of GNU Enscript.
10 *
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.
15 *
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.
20 *
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/>.
23 */
24
25 #include "gsint.h"
26
27 /*
28 * Global functions.
29 */
30
31 FILE *
printer_open(char * cmd,char * options,char * queue_param,char * printer_name,void ** context_return)32 printer_open(char *cmd, char *options, char *queue_param, char *printer_name,
33 void **context_return)
34 {
35 Buffer pipe_cmd;
36 FILE *fp;
37
38 buffer_init(&pipe_cmd);
39
40 buffer_append(&pipe_cmd, cmd);
41 buffer_append(&pipe_cmd, " ");
42
43 if (options)
44 {
45 buffer_append(&pipe_cmd, options);
46 buffer_append(&pipe_cmd, " ");
47 }
48
49 if (printer_name)
50 {
51 buffer_append(&pipe_cmd, queue_param);
52 buffer_append(&pipe_cmd, printer_name);
53 }
54
55 fp = popen(buffer_ptr(&pipe_cmd), "w");
56
57 buffer_uninit(&pipe_cmd);
58
59 *context_return = fp;
60 return fp;
61 }
62
63
64 void
printer_close(void * context)65 printer_close(void *context)
66 {
67 FILE *fp = (FILE *) context;
68
69 pclose(fp);
70 }
71