gdevsppr.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* Copyright (C) 1992, 1993, 1996, 1998, 1999 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gdevsppr.c,v 1.5 2001/10/12 21:37:08 ghostgum Exp $*/
  16. /* SPARCprinter driver for Ghostscript */
  17. #include "gdevprn.h"
  18. #include <stdio.h>
  19. #include <sys/types.h>
  20. #include <sys/ioccom.h>
  21. #include <unbdev/lpviio.h>
  22. /*
  23. Thanks to Martin Schulte (schulte@thp.Uni-Koeln.DE) for contributing
  24. this driver to Ghostscript. He supplied the following notes.
  25. The device-driver (normally) returns two differnt types of Error-Conditions,
  26. FATALS and WARNINGS. In case of a fatal, the print routine returns -1, in
  27. case of a warning (such as paper out), a string describing the error is
  28. printed to stderr and the output-operation is repeated after five seconds.
  29. A problem is that not all possible errors seem to return the correct error,
  30. under some circumstance I get the same response as if an error repeated,
  31. that's why there is this the strange code about guessing the error.
  32. I didn't implement asynchronous IO (yet), because "`normal"' multipage-
  33. printings like TEX-Output seem to be printed with the maximum speed whereas
  34. drawings normally occur as one-page outputs, where asynchronous IO doesn't
  35. help anyway.
  36. */
  37. private dev_proc_open_device(sparc_open);
  38. private dev_proc_print_page(sparc_print_page);
  39. #define SPARC_MARGINS_A4 0.15, 0.12, 0.12, 0.15
  40. #define SPARC_MARGINS_LETTER 0.15, 0.12, 0.12, 0.15
  41. gx_device_procs prn_sparc_procs =
  42. prn_procs(sparc_open, gdev_prn_output_page, gdev_prn_close);
  43. const gx_device_printer far_data gs_sparc_device =
  44. prn_device(prn_sparc_procs,
  45. "sparc",
  46. DEFAULT_WIDTH_10THS,DEFAULT_HEIGHT_10THS,
  47. 400,400,
  48. 0,0,0,0,
  49. 1,
  50. sparc_print_page);
  51. /* Open the printer, and set the margins. */
  52. private int
  53. sparc_open(gx_device *pdev)
  54. { /* Change the margins according to the paper size. */
  55. const float *m;
  56. static const float m_a4[4] = { SPARC_MARGINS_A4 };
  57. static const float m_letter[4] = { SPARC_MARGINS_LETTER };
  58. m = (pdev->height / pdev->y_pixels_per_inch >= 11.1 ? m_a4 : m_letter);
  59. gx_device_set_margins(pdev, m, true);
  60. return gdev_prn_open(pdev);
  61. }
  62. char *errmsg[]={
  63. "EMOTOR",
  64. "EROS",
  65. "EFUSER",
  66. "XEROFAIL",
  67. "ILCKOPEN",
  68. "NOTRAY",
  69. "NOPAPR",
  70. "XITJAM",
  71. "MISFEED",
  72. "WDRUMX",
  73. "WDEVEX",
  74. "NODRUM",
  75. "NODEVE",
  76. "EDRUMX",
  77. "EDEVEX",
  78. "ENGCOLD",
  79. "TIMEOUT",
  80. "EDMA",
  81. "ESERIAL"
  82. };
  83. /* The static buffer is unfortunate.... */
  84. static char err_buffer[80];
  85. private char *
  86. err_code_string(int err_code)
  87. {
  88. if ((err_code<EMOTOR)||(err_code>ESERIAL))
  89. {
  90. sprintf(err_buffer,"err_code out of range: %d",err_code);
  91. return err_buffer;
  92. }
  93. return errmsg[err_code];
  94. }
  95. int warning=0;
  96. private int
  97. sparc_print_page(gx_device_printer *pdev, FILE *prn)
  98. {
  99. struct lpvi_page lpvipage;
  100. struct lpvi_err lpvierr;
  101. char *out_buf;
  102. int out_size;
  103. if (ioctl(fileno(prn),LPVIIOC_GETPAGE,&lpvipage)!=0)
  104. {
  105. errprintf("sparc_print_page: LPVIIOC_GETPAGE failed\n");
  106. return -1;
  107. }
  108. lpvipage.bitmap_width=gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  109. lpvipage.page_width=lpvipage.bitmap_width*8;
  110. lpvipage.page_length=pdev->height;
  111. lpvipage.resolution = (pdev->x_pixels_per_inch == 300 ? DPI300 : DPI400);
  112. if (ioctl(fileno(prn),LPVIIOC_SETPAGE,&lpvipage)!=0)
  113. {
  114. errprintf(sparc_print_page: LPVIIOC_SETPAGE failed\n");
  115. return -1;
  116. }
  117. out_size=lpvipage.bitmap_width*lpvipage.page_length;
  118. out_buf=gs_malloc(out_size,1,"sparc_print_page: out_buf");
  119. gdev_prn_copy_scan_lines(pdev,0,out_buf,out_size);
  120. while (write(fileno(prn),out_buf,out_size)!=out_size)
  121. {
  122. if (ioctl(fileno(prn),LPVIIOC_GETERR,&lpvierr)!=0)
  123. {
  124. errprintf(sparc_print_page: LPVIIOC_GETERR failed\n");
  125. return -1;
  126. }
  127. switch (lpvierr.err_type)
  128. {
  129. case 0:
  130. if (warning==0)
  131. {
  132. errprintf(
  133. "sparc_print_page: Printer Problem with unknown reason...");
  134. dflush();
  135. warning=1;
  136. }
  137. sleep(5);
  138. break;
  139. case ENGWARN:
  140. errprintf(
  141. "sparc_print_page: Printer-Warning: %s...",
  142. err_code_string(lpvierr.err_code));
  143. dflush();
  144. warning=1;
  145. sleep(5);
  146. break;
  147. case ENGFATL:
  148. errprintf(
  149. "sparc_print_page: Printer-Fatal: %s\n",
  150. err_code_string(lpvierr.err_code));
  151. return -1;
  152. case EDRVR:
  153. errprintf(
  154. "sparc_print_page: Interface/driver error: %s\n",
  155. err_code_string(lpvierr.err_code));
  156. return -1;
  157. default:
  158. errprintf(
  159. "sparc_print_page: Unknown err_type=%d(err_code=%d)\n",
  160. lpvierr.err_type,lpvierr.err_code);
  161. return -1;
  162. }
  163. }
  164. if (warning==1)
  165. {
  166. errprintf("OK.\n");
  167. warning=0;
  168. }
  169. gs_free(out_buf,out_size,1,"sparc_print_page: out_buf");
  170. return 0;
  171. }