generic 4.4 KB

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