generic 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/bin/rc
  2. # Tries to determine what type of file you are printing and do the correct
  3. # thing with it.
  4. # It currently knows about images, troff intermediate, and ascii files.
  5. rfork e
  6. temp=/tmp/lp$pid
  7. fn sigexit { rm -f $temp }
  8. proc=$LPLIB/process
  9. if (! ~ $DEBUG '')
  10. flag x +
  11. cat >$temp
  12. type=`{file $temp}
  13. switch ($type(2)) {
  14. case troff
  15. switch ($LPCLASS) {
  16. case *Latin1* *post* *opost*
  17. switch ($type(5)) {
  18. # Latin1 is for compatibility with old research UNIX systems,
  19. # doesn't work on Plan 9
  20. case Latin1 post
  21. tcs -s -f utf -t latin1 <$temp | $proc/dpost
  22. case UTF
  23. $proc/tr2post <$temp
  24. }
  25. case *gs!* *gsijs!*
  26. switch ($type(5)) {
  27. # Latin1 is for compatibility with old research UNIX systems,
  28. # doesn't work on Plan 9
  29. case Latin1 post
  30. tcs -s -f utf -t latin1 <$temp | $proc/dpost |
  31. $proc/gspipe
  32. case UTF
  33. $proc/tr2post <$temp | $proc/gspipe
  34. }
  35. case *
  36. echo $type(2) -T$type(5) output is improper for $LPDEST >[1=2]
  37. }
  38. case special
  39. switch ($type(4)) {
  40. case '#b'
  41. switch ($LPCLASS) {
  42. case *post*
  43. $proc/p9bitpost <$temp
  44. case *gs!*
  45. $proc/p9bitpost <$temp | $proc/gspipe
  46. case *gsijs!*
  47. $proc/p9bitpost <$temp | $proc/gspipeijs
  48. }
  49. case *
  50. echo $type file is improper for $LPDEST >[1=2]
  51. }
  52. case Compressed plan old subfont
  53. # type is really 'Compressed image' or 'plan 9 image' or
  54. # 'old plan 9 image'
  55. # 'subfont' is to cope with a bug in png (writing wrong length),
  56. # 6 may 2008
  57. switch ($LPCLASS) {
  58. case *post*
  59. $proc/p9bitpost <$temp
  60. case *gs!*
  61. $proc/p9bitpost <$temp | $proc/gspipe
  62. case *gsijs!*
  63. $proc/p9bitpost <$temp | $proc/gspipeijs
  64. }
  65. case jpeg
  66. switch ($LPCLASS) {
  67. case *post*
  68. $proc/jpgpost <$temp
  69. case *gs!*
  70. $proc/jpgpost <$temp | $proc/gspipe
  71. case *gsijs!*
  72. $proc/jpgpost <$temp | $proc/gspipeijs
  73. }
  74. case GIF
  75. switch ($LPCLASS) {
  76. case *post*
  77. $proc/gifpost <$temp
  78. case *gs!*
  79. $proc/gifpost <$temp | $proc/gspipe
  80. case *gsijs!*
  81. $proc/gifpost <$temp | $proc/gspipeijs
  82. }
  83. case PNG
  84. switch ($LPCLASS) {
  85. case *post*
  86. $proc/pngpost <$temp
  87. case *gs!*
  88. $proc/pngpost <$temp | $proc/gspipe
  89. case *gsijs!*
  90. $proc/pngpost <$temp | $proc/gspipeijs
  91. }
  92. case ccitt-g31
  93. switch ($LPCLASS) {
  94. case *post*
  95. $proc/g3post <$temp
  96. case *gs!*
  97. $proc/g3post <$temp | $proc/gspipe
  98. case *gsijs!*
  99. $proc/g3post <$temp | $proc/gspipeijs
  100. }
  101. case bitmap
  102. # bitmap for research UNIX compatibility, does not work on Plan 9.
  103. switch ($LPCLASS) {
  104. case *post*
  105. $proc/bpost <$temp
  106. case *mhcc*
  107. $proc/bpost <$temp | $proc/mhcc
  108. case *
  109. echo $type(2) file is improper for $LPDEST >[1=2]
  110. }
  111. case tex
  112. mv $temp $temp.dvi
  113. temp=$temp.dvi
  114. switch ($LPCLASS) {
  115. case *post*
  116. $proc/dvipost $temp
  117. case *gs!*
  118. $proc/dvipost $temp | $proc/gspipe
  119. case *gsijs!*
  120. $proc/dvipost $temp | $proc/gspipeijs
  121. case *
  122. echo $type(2) file is improper for $LPDEST >[1=2]
  123. }
  124. case postscript
  125. switch ($LPCLASS) {
  126. case *post*
  127. $proc/post <$temp
  128. case *gs!*
  129. $proc/post <$temp | $proc/gspipe
  130. case *gsijs!*
  131. $proc/post <$temp | $proc/gspipeijs
  132. case *
  133. echo $type(2) file is improper for $LPDEST >[1=2]
  134. }
  135. case HPJCL
  136. switch ($LPCLASS) {
  137. case *HPJCL*
  138. $proc/noproc <$temp
  139. case *
  140. echo $type(2) file is improper for $LPDEST >[1=2]
  141. }
  142. case daisy
  143. switch ($LPDEST) {
  144. case *
  145. echo $type(2) file is improper for $LPDEST >[1=2]
  146. }
  147. case tiff
  148. switch ($LPCLASS) {
  149. case *post*
  150. $proc/tiffpost $temp
  151. case *gs!*
  152. $proc/tiffpost $temp | $proc/gspipe
  153. case *gsijs!*
  154. $proc/tiffpost $temp | $proc/gspipeijs
  155. case *
  156. echo Unrecognized class of line printer for $LPDEST >[1=2]
  157. }
  158. case PDF
  159. switch ($LPCLASS) {
  160. case *pdf*
  161. # if (~ $LPCLASS *duplex* && ~ $LPCLASS *HPJCL*)
  162. # echo -n '&l1S' # HP JCL: duplex on
  163. if (~ $LPCLASS *duplex* && ~ $LPCLASS *HPJCL*) {
  164. echo '%-12345X@PJL DEFAULT DUPLEX=ON' # HP PJL
  165. echo '%-12345X'
  166. echo '%-12345X@PJL DEFAULT PS:MBT=ON' # `memory boost'
  167. echo '%-12345X'
  168. }
  169. cat $temp # pass pdf unaltered to pdf printer
  170. case *post*
  171. $proc/pdfpost $temp
  172. case *gs!*
  173. $proc/pdfgs $temp
  174. case *gsijs!*
  175. $proc/pdfgsijs $temp
  176. case *
  177. echo Unrecognized class of line printer for $LPDEST >[1=2]
  178. }
  179. case empty
  180. echo file is empty >[1=2]
  181. case cannot
  182. echo cannot open file >[1=2]
  183. case English short extended alef limbo [Aa]scii assembler c latin rc sh \
  184. as mail email message/rfc822 manual HTML
  185. switch ($LPCLASS) {
  186. case *post*
  187. $proc/ppost <$temp
  188. case *gs!*
  189. $proc/ppost <$temp | $proc/gspipe
  190. case *gsijs!*
  191. $proc/ppost <$temp | $proc/gspipeijs
  192. case *canon*
  193. $proc/can $* <$temp
  194. case *
  195. echo Unrecognized class of line printer for $LPDEST >[1=2]
  196. }
  197. case *
  198. echo $type(2) file is improper for $LPDEST >[1=2]
  199. }
  200. wait
  201. rv=$status
  202. rm -f $temp
  203. # exit $rv
  204. exit