1709795f |
1 | /* |
2 | * Printing interface for PuTTY. |
3 | */ |
4 | |
5 | #include <assert.h> |
356a1706 |
6 | #include <stdio.h> |
1709795f |
7 | #include "putty.h" |
8 | |
356a1706 |
9 | struct printer_job_tag { |
10 | FILE *fp; |
11 | }; |
12 | |
1709795f |
13 | printer_job *printer_start_job(char *printer) |
14 | { |
356a1706 |
15 | printer_job *ret = smalloc(sizeof(printer_job)); |
16 | /* |
17 | * On Unix, we treat cfg.printer as the name of a command to |
18 | * pipe to - typically lpr, of course. |
19 | */ |
20 | ret->fp = popen(cfg.printer, "w"); |
21 | if (!ret->fp) { |
22 | sfree(ret); |
23 | ret = NULL; |
24 | } |
25 | return ret; |
1709795f |
26 | } |
27 | |
28 | void printer_job_data(printer_job *pj, void *data, int len) |
29 | { |
356a1706 |
30 | if (!pj) |
31 | return; |
32 | |
33 | fwrite(data, 1, len, pj->fp); |
1709795f |
34 | } |
35 | |
36 | void printer_finish_job(printer_job *pj) |
37 | { |
356a1706 |
38 | if (!pj) |
39 | return; |
40 | |
41 | pclose(pj->fp); |
42 | sfree(pj); |
1709795f |
43 | } |