| 1 | /* |
| 2 | * Printing interface for PuTTY. |
| 3 | */ |
| 4 | |
| 5 | #include <assert.h> |
| 6 | #include <stdio.h> |
| 7 | #include "putty.h" |
| 8 | |
| 9 | struct printer_job_tag { |
| 10 | FILE *fp; |
| 11 | }; |
| 12 | |
| 13 | printer_job *printer_start_job(char *printer) |
| 14 | { |
| 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; |
| 26 | } |
| 27 | |
| 28 | void printer_job_data(printer_job *pj, void *data, int len) |
| 29 | { |
| 30 | if (!pj) |
| 31 | return; |
| 32 | |
| 33 | fwrite(data, 1, len, pj->fp); |
| 34 | } |
| 35 | |
| 36 | void printer_finish_job(printer_job *pj) |
| 37 | { |
| 38 | if (!pj) |
| 39 | return; |
| 40 | |
| 41 | pclose(pj->fp); |
| 42 | sfree(pj); |
| 43 | } |