/share/examples/printing/hpdf

https://bitbucket.org/freebsd/freebsd-head/ · Shell · 59 lines · 16 code · 9 blank · 34 comment · 2 complexity · f8976e1be7a0cc273cedf2a44affe9de MD5 · raw file

  1. #!/bin/sh
  2. #
  3. # hpdf - Print DVI data on HP/PCL printer
  4. # Installed in /usr/local/libexec/hpdf
  5. PATH=/usr/local/bin:$PATH; export PATH
  6. #
  7. # Define a function to clean up our temporary files. These exist
  8. # in the current directory, which will be the spooling directory
  9. # for the printer.
  10. #
  11. cleanup() {
  12. rm -f hpdf$$.dvi
  13. }
  14. #
  15. # Define a function to handle fatal errors: print the given message
  16. # and exit 2. Exiting with 2 tells LPD to do not try to reprint the
  17. # job.
  18. #
  19. fatal() {
  20. echo "$@" 1>&2
  21. cleanup
  22. exit 2
  23. }
  24. #
  25. # If user removes the job, LPD will send SIGINT, so trap SIGINT
  26. # (and a few other signals) to clean up after ourselves.
  27. #
  28. trap cleanup 1 2 15
  29. #
  30. # Make sure we are not colliding with any existing files.
  31. #
  32. cleanup
  33. #
  34. # Link the DVI input file to standard input (the file to print).
  35. #
  36. ln -s /dev/fd/0 hpdf$$.dvi || fatal "Cannot symlink /dev/fd/0"
  37. #
  38. # Make LF = CR+LF
  39. #
  40. printf "\033&k2G" || fatal "Cannot initialize printer"
  41. #
  42. # Convert and print. Return value from dvilj2p does not seem to be
  43. # reliable, so we ignore it.
  44. #
  45. dvilj2p -M1 -q -e- dfhp$$.dvi
  46. #
  47. # Clean up and exit
  48. #
  49. cleanup
  50. exit 0