printing.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Printing interface for PuTTY.
  3. */
  4. #include <assert.h>
  5. #include <stdio.h>
  6. #include "putty.h"
  7. struct printer_job_tag {
  8. FILE *fp;
  9. };
  10. printer_job *printer_start_job(char *printer)
  11. {
  12. printer_job *pj = snew(printer_job);
  13. /*
  14. * On Unix, we treat the printer string as the name of a
  15. * command to pipe to - typically lpr, of course.
  16. */
  17. pj->fp = popen(printer, "w");
  18. if (!pj->fp) {
  19. sfree(pj);
  20. pj = NULL;
  21. }
  22. return pj;
  23. }
  24. void printer_job_data(printer_job *pj, const void *data, size_t len)
  25. {
  26. if (!pj)
  27. return;
  28. if (fwrite(data, 1, len, pj->fp) < len)
  29. /* ignore */;
  30. }
  31. void printer_finish_job(printer_job *pj)
  32. {
  33. if (!pj)
  34. return;
  35. pclose(pj->fp);
  36. sfree(pj);
  37. }
  38. /*
  39. * There's no sensible way to enumerate printers under Unix, since
  40. * practically any valid Unix command is a valid printer :-) So
  41. * these are useless stub functions, and config-unix.c will disable
  42. * the drop-down list in the printer configurer.
  43. */
  44. printer_enum *printer_start_enum(int *nprinters_ptr) {
  45. *nprinters_ptr = 0;
  46. return NULL;
  47. }
  48. char *printer_get_name(printer_enum *pe, int i) { return NULL;
  49. }
  50. void printer_finish_enum(printer_enum *pe) { }