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