]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Printer support: cfg.printer is assumed to be a Unix command through
authorSimon Tatham <anakin@pobox.com>
Tue, 15 Oct 2002 17:38:04 +0000 (17:38 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 15 Oct 2002 17:38:04 +0000 (17:38 +0000)
which to pipe printed data. Of course by default printing is
disabled; typically cfg.printer would be set to `lpr', perhaps with
some arguments.

[originally from svn r2073]

unix/uxprint.c

index 6558317b44f5ddec311c71dfc553e877edd07198..387ea28d1ac940dd1af12be56ddb9db57cc22dd2 100644 (file)
@@ -3,22 +3,41 @@
  */
 
 #include <assert.h>
+#include <stdio.h>
 #include "putty.h"
 
+struct printer_job_tag {
+    FILE *fp;
+};
+
 printer_job *printer_start_job(char *printer)
 {
-    /* FIXME: open pipe to lpr */
-    return NULL;
+    printer_job *ret = smalloc(sizeof(printer_job));
+    /*
+     * On Unix, we treat cfg.printer as the name of a command to
+     * pipe to - typically lpr, of course.
+     */
+    ret->fp = popen(cfg.printer, "w");
+    if (!ret->fp) {
+       sfree(ret);
+       ret = NULL;
+    }
+    return ret;
 }
 
 void printer_job_data(printer_job *pj, void *data, int len)
 {
-    /* FIXME: receive a pipe to lpr, write things to it */
-    assert(!"We shouldn't get here");
+    if (!pj)
+       return;
+
+    fwrite(data, 1, len, pj->fp);
 }
 
 void printer_finish_job(printer_job *pj)
 {
-    /* FIXME: receive a pipe to lpr, close it */
-    assert(!"We shouldn't get here either");
+    if (!pj)
+       return;
+
+    pclose(pj->fp);
+    sfree(pj);
 }