home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / apsfiltr / part01 < prev    next >
Encoding:
Text File  |  1993-11-26  |  8.6 KB  |  320 lines

  1. Newsgroups: comp.sources.misc
  2. From: andreas@knobel.knirsch.de (Andreas Klemm)
  3. Subject: v40i165:  apsfilter - postscript filter with file type auto recognition, v1.3, Part01/01
  4. Message-ID: <1993Nov26.160826.29181@sparky.sterling.com>
  5. Summary: line printer filter with file conversion
  6. X-Md4-Signature: 2d89c1b9b0ad7094e121b16bde1a3e1e
  7. Keywords: ps postscript lpr printcap filter dj500
  8. Sender: kent@sparky.sterling.com (Kent Landfield)
  9. Organization: Andreas Klemm, 41469 Neuss, Germany
  10. Date: Fri, 26 Nov 1993 16:08:26 GMT
  11. Approved: kent@sparky.sterling.com
  12.  
  13. Submitted-by: andreas@knobel.knirsch.de (Andreas Klemm)
  14. Posting-number: Volume 40, Issue 165
  15. Archive-name: apsfilter/part01
  16. Environment: lpr, dj500
  17.  
  18. Here is apsfilter V 1.3 - an lp output filter for different file types.
  19.  
  20. Since there are possibly different versions around - many sent directly
  21. via e-mail - I deceided to post it again to the related groups 
  22. (of my interest) so everybody has the chance to get the newest version.
  23.  
  24. And I decided to give it a uniq name "apsfilter", so it's more easily
  25. to grab the newest version from a source group....
  26.  
  27. Perhaps some of you have to add some lines to the file /etc/magic, 
  28. so that the file(1) command is able to recognize dvi and postscript files.
  29. --------------
  30. #! /bin/sh
  31. # This is a shell archive.  Remove anything before this line, then feed it
  32. # into a shell via "sh file" or similar.  To overwrite existing files,
  33. # type "sh file -c".
  34. # Contents:  apsfilter magic
  35. # Wrapped by kent@sparky on Fri Nov 26 10:05:33 1993
  36. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  37. echo If this archive is complete, you will see the following message:
  38. echo '          "shar: End of archive 1 (of 1)."'
  39. if test -f 'apsfilter' -a "${1}" != "-c" ; then 
  40.   echo shar: Will not clobber existing file \"'apsfilter'\"
  41. else
  42.   echo shar: Extracting \"'apsfilter'\" \(5423 characters\)
  43.   sed "s/^X//" >'apsfilter' <<'END_OF_FILE'
  44. X#!/bin/sh
  45. X
  46. X# apsfilter-1.3 - HP Deskjet 500 - output filter - V 1.3
  47. X#
  48. X# copyright 1993 by Andreas Klemm <andreas@knobel.knirsch.de>
  49. X#
  50. X# Mon Nov 15 12:35:26 GMT 1993
  51. X#
  52. X# additional contributors:
  53. X#
  54. X#    Steven A. Reisman <unido!beehive.mn.org!sar>
  55. X#        - added dvi filter
  56. X#
  57. X#    Jeff Stern <jstern@eclectic.ss.uci.edu>
  58. X#        - use lpfilter as an input filter
  59. X#          so it's possible to print header pages
  60. X#          without confusing the filter.
  61. X#        --> see modification section
  62. X#
  63. X
  64. X####################################################################
  65. X# A running /etc/printcap
  66. X####################################################################
  67. X#
  68. X# My /etc/printcap entry for parallel printer port lpt1:
  69. X# on a 486/33 using Linux Slackware using this filter as
  70. X# an output filter, since I don't need header pages. (andreas)
  71. X#
  72. X# HP Deskjet
  73. X# lp|deskjet|HP Deskjet 500:\
  74. X#    :lp=/dev/lp1:\
  75. X#    :sd=/usr/spool/lp1:\
  76. X#    :sh:\
  77. X#    :mx#0:\
  78. X#    :of=/usr/lib/lpfilter:
  79. X#
  80. X####################################################################
  81. X
  82. X####################################################################
  83. X# MODIFICATION SECTION
  84. X#        suggestions from other creative people
  85. X#        which use another configuration than I
  86. X####################################################################
  87. X#
  88. X# A) WANT HEADER PAGES
  89. X#            Jeff Stern <jstern@eclectic.ss.uci.edu>
  90. X#            Mon Nov  1 21:21:45 GMT 1993
  91. X#
  92. X# "... I changed to using it as an input filter instead of an output 
  93. X#  filter. This way I can still print header pages without confusing 
  94. X#  the filter. This necessarily required adding a command to tell 
  95. X#  printcap to send a formfeed at the beginning of opening the device 
  96. X#  and also specifying that that formfeed really also includes the 
  97. X#  LF-> CR+LF translation: this is so that the translation also will 
  98. X#  work for the header page, too."
  99. X#  Necessary Printcap entry instead of the default:
  100. X#    lp:lp=/dev/lp1:sd=/usr/spool/lp1:if=/usr/lib/lpfilter:mx#0:\
  101. X#       :lf=/usr/adm/lpd-errs:ff=\033E\033&k2G\033&a10L:fo
  102. X#
  103. X####################################################################
  104. X# END OF MODIFICATION SECTION
  105. X####################################################################
  106. X
  107. XPATH=/usr/bin:/bin:/usr/local/bin:/usr/TeX/bin:/home/bin
  108. Xexport PATH
  109. X
  110. X# where do you have diskspace
  111. X#
  112. XTmpDir=/usr/tmp
  113. X
  114. X# Temp. filename
  115. XTmpFile=$TmpDir/deskjetof.$$
  116. X
  117. X# Who should be notified by e-mail in case of print problems ?
  118. XNOTIFY=root
  119. X
  120. X# write print data from stdin to temp file
  121. Xcat - > $TmpFile
  122. X
  123. X#
  124. X# reset printer to power on values before print job
  125. X#
  126. Xecho -ne '\033E'
  127. X
  128. X# determine file type
  129. X# set output of the ``file'' command to new script arguments $1, $2, ..., $n
  130. X#
  131. Xset -- `file $TmpFile`
  132. X
  133. X# throw away $1 since that is the *file name*
  134. X#
  135. Xshift
  136. X
  137. X# the rest is a "string" which consist of one or multiple words 
  138. X# describing the file type. For example: "Korn Shell Script"
  139. X#
  140. XFileType=$*
  141. X
  142. Xcase $FileType in
  143. X
  144. X    PostScript*)    #
  145. X            # pipe ps data through ghostscript
  146. X            #    
  147. X            cat $TmpFile            \
  148. X            | gs -q                \
  149. X                -sDEVICE=djet500    \
  150. X                -r300x300        \
  151. X                -sPAPERSIZE=a4        \
  152. X                -dNOPAUSE        \
  153. X                -dSAFER            \
  154. X                -sOutputFile=-        \
  155. X                    -        \
  156. X            /usr/local/lib/ghostscript/quit.ps \
  157. X            || echo -ne '\033&l0H'
  158. X            # ^  if an error occurs, then
  159. X            # |  eject already loaded paper
  160. X            ;;
  161. X
  162. X            
  163. X    *DVI*)        #
  164. X            # TeX dvi file -> dvips -> gs
  165. X            #    
  166. X            dvips 2>/dev/null $TmpFile -f    \
  167. X            | gs -q                \
  168. X                -sDEVICE=djet500    \
  169. X                -r300x300        \
  170. X                -sPAPERSIZE=a4        \
  171. X                -dNOPAUSE        \
  172. X                -dSAFER            \
  173. X                -sOutputFile=-        \
  174. X                    -        \
  175. X            /usr/local/lib/ghostscript/quit.ps \
  176. X            || echo -ne '\033&l0H'
  177. X            # ^  if an error occurs, then
  178. X            # |  eject already loaded paper
  179. X            ;;
  180. X
  181. X    *text*|*script*)    #
  182. X            # print normal text with
  183. X            #    - cr/nl conversion
  184. X            #    - letter quality
  185. X            #    - 66 lines/page
  186. X            #    - left margin
  187. X            #    - 12 cpi pitch
  188. X            #
  189. X
  190. X            # LINE TERMINATION    \E & k # G
  191. X            #    0 = CR=CR   ; LF=LF   ; FF=FF (default)
  192. X            #    1 = CR=CR+LF; LF=LF   ; FF=FF
  193. X            # **    2 = CR=CR   ; LF=CR+LF; FF=CR+FF
  194. X            #    3 = CR=CR+LF; LF=CR+LF; FF=CR+FF
  195. X            echo -ne '\033&k2G'
  196. X
  197. X            # QUALITY        \E ( s # Q
  198. X            #       1 = draft    = 240cps
  199. X            # **    2 = letter    = 120cps (default)
  200. X            echo -ne '\033(s2Q'
  201. X
  202. X            # Text Scale Mode        \E & k # W
  203. X            #       5 = off (default)
  204. X            #         6 = on
  205. X            #    ignored in landscape mode
  206. X            # echo -ne '\033&k5W'
  207. X
  208. X            # Perforation Skip Mode        \E & l # L
  209. X            #       0 = off = 0.0 in Top Margin
  210. X            #       1 = on  = 1/2 in Top Margin (default)
  211. X            echo -ne '\033&l0L'
  212. X
  213. X            # Left Margin            \E & a # L
  214. X            #     # Valu^ = column number
  215. X            #    default = 0 = 1/8 in left margin
  216. X            #    used = 7 for 1" left margin
  217. X            echo -ne '\033&a7L'
  218. X
  219. X            # Pitch                \E ( s # H
  220. X            #    # = cpi
  221. X            #    default = 10 characters per inch
  222. X            # **    12 cpi
  223. X            echo -ne '\033(s12H'
  224. X
  225. X            # print tmp file
  226. X            cat $TmpFile
  227. X            ;;
  228. X
  229. X    *data*)        #
  230. X            # print binary files
  231. X            #
  232. X
  233. X            # LINE TERMINATION    \E & k # G
  234. X            # **    0 = CR=CR   ; LF=LF   ; FF=FF (default)
  235. X            #    1 = CR=CR+LF; LF=LF   ; FF=FF
  236. X            #       2 = CR=CR   ; LF=CR+LF; FF=CR+FF
  237. X            #    3 = CR=CR+LF; LF=CR+LF; FF=CR+FF
  238. X            echo -ne '\033&k0G'
  239. X
  240. X            # print tmp file
  241. X            cat $TmpFile
  242. X            ;;
  243. X            
  244. X
  245. X    *)        #
  246. X            # Rest is an unknown file type ...... sorry ;-)
  247. X            #
  248. X
  249. X            echo "deskjetof: unknown filetype $FileType" > /dev/console
  250. X            echo "deskjetof: $TmpFile: unknown filetype $FileType" \
  251. X            | mail $NOTIFY
  252. X            NotOk=1
  253. X            ;;
  254. Xesac
  255. X
  256. X#
  257. X# keep print job, that couldn't be printed because of errors....
  258. X#
  259. Xif [ ! "$NotOk" = "1" ]
  260. Xthen 
  261. X    rm -f $TmpFile
  262. Xfi
  263. X
  264. X
  265. X#
  266. X# reset printer to power on values after print job
  267. X#
  268. Xecho -ne '\033E'
  269. X#
  270. END_OF_FILE
  271.   if test 5423 -ne `wc -c <'apsfilter'`; then
  272.     echo shar: \"'apsfilter'\" unpacked with wrong size!
  273.   fi
  274.   # end of 'apsfilter'
  275. fi
  276. if test -f 'magic' -a "${1}" != "-c" ; then 
  277.   echo shar: Will not clobber existing file \"'magic'\"
  278. else
  279.   echo shar: Extracting \"'magic'\" \(346 characters\)
  280.   sed "s/^X//" >'magic' <<'END_OF_FILE'
  281. X# magic.postscript: Magic for postscript files
  282. X#
  283. X0    string        %!        PostScript document
  284. X>2    string    PS-Adobe-        conforming
  285. X>11    string    1.0            at level %s
  286. X>11    string    2.0            at level %s
  287. X
  288. X# magic.tex: 
  289. X#
  290. X0    short    0173402    DVI File
  291. X>16    string    >\0    (%s)
  292. X0    short    0173531    Packed TeX Font
  293. X>4    string    >\0    (%s)
  294. X2    string    \000\022    Metafont Font Metric
  295. X>34    string    >\0    (%s)
  296. X
  297. END_OF_FILE
  298.   if test 346 -ne `wc -c <'magic'`; then
  299.     echo shar: \"'magic'\" unpacked with wrong size!
  300.   fi
  301.   # end of 'magic'
  302. fi
  303. echo shar: End of archive 1 \(of 1\).
  304. cp /dev/null ark1isdone
  305. MISSING=""
  306. for I in 1 ; do
  307.     if test ! -f ark${I}isdone ; then
  308.     MISSING="${MISSING} ${I}"
  309.     fi
  310. done
  311. if test "${MISSING}" = "" ; then
  312.     echo You have the archive.
  313.     rm -f ark[1-9]isdone
  314. else
  315.     echo You still must unpack the following archives:
  316.     echo "        " ${MISSING}
  317. fi
  318. exit 0
  319. exit 0 # Just in case...
  320.