home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / cupsys / examples / samba-to-ps < prev   
Encoding:
Text File  |  2006-08-30  |  2.3 KB  |  57 lines

  1. #!/bin/sh
  2.  
  3. # CUPS (Common Unix Printing System) filter to fix certain "broken" PostScript files
  4.  
  5. # The files generated by Hewlett-Packard's Windows drivers for the "LaserJet
  6. # 5P/5MP PostScript" printer include a PJL header (that switches that printer
  7. # to PostScript) before the actual PostScript file, and some weird additional
  8. # comments within the PostScript.  If you are sending these files (via Samba)
  9. # to a plain LaserJet 5P (i.e., without PostScript), you need to remove the
  10. # header and the weird additional comments before sending the file to
  11. # ghostscript.  Though it is a reasonable guess that the same situation applies
  12. # to other pairs of HP printers with and without native PostScript
  13. # capabilities, I have tested this script only with the LaserJet 5P.
  14.  
  15. # The garbage we are trimming at top and bottom of the file is fixed-length, so
  16. # we could use something simpler than awk to trim it, but we have to use awk
  17. # anyway to skip those weird comment lines (3d line of the program below), so
  18. # let's just use awk for the whole thing.
  19.  
  20. # I wrote this awk script in the mid-1990s when I bought this printer, and it
  21. # still serves me well today, with the latest versions of Windows, Debian, and
  22. # Samba, and with CUPS instead of old BSD lpd and magicfilter.  I adapted it
  23. # for CUPS in April 2004.  I put this code into the public domain.  I am not
  24. # putting my name on it because I do not want to receive emails with questions
  25. # about things I do not know much about.
  26.  
  27. # TODO
  28. #   does the code here involve gawk extensions?
  29.  
  30. # on error, exit with this status.
  31. CUPS_SAMBAPS_ERREXIT=2
  32.  
  33. prog=$(basename "$0")
  34. # This statement needs bash I think.
  35. echo "DEBUG: $prog: \"$0\" has been called with these arguments:" >&2
  36. count=1
  37. for x; do
  38.     echo "DEBUG: $prog: arg $((count++)): \"$x\"" >&2
  39. done
  40.  
  41. if ! shift 5; then
  42.     echo "ERROR: $prog: expected 5 or 6 arguments and received <5" >&2
  43.     exit $CUPS_SAMBAPS_ERREXIT
  44. elif [ $# -gt 1 ]; then
  45.     echo "ERROR: $prog: expected 5 or 6 arguments and received >6" >&2
  46.     exit $CUPS_SAMBAPS_ERREXIT
  47. fi
  48.  
  49. # variable `printme' starts as 0
  50. /usr/bin/awk \
  51.     '/^%\!PS-Adobe-/                           {printme = 1}
  52.      /^%%EOF/                                  {print; printme = 0}
  53.      /\(%%\[ ?(ProductName:|Page:|LastPage ?)/ {next}
  54.                                                { if (printme) print; else next }' \
  55.     ${1--}    
  56. exit
  57.