121240Swosch#!/bin/sh 221240Swosch# 321240Swosch# hpdf - Print DVI data on HP/PCL printer 421240Swosch# Installed in /usr/local/libexec/hpdf 521240Swosch 621240SwoschPATH=/usr/local/bin:$PATH; export PATH 721240Swosch 821240Swosch# 921240Swosch# Define a function to clean up our temporary files. These exist 1021240Swosch# in the current directory, which will be the spooling directory 1121240Swosch# for the printer. 1221240Swosch# 1321240Swoschcleanup() { 1421240Swosch rm -f hpdf$$.dvi 1521240Swosch} 1621240Swosch 1721240Swosch# 1821240Swosch# Define a function to handle fatal errors: print the given message 1921240Swosch# and exit 2. Exiting with 2 tells LPD to do not try to reprint the 2021240Swosch# job. 2121240Swosch# 2221240Swoschfatal() { 2321240Swosch echo "$@" 1>&2 2421240Swosch cleanup 2521240Swosch exit 2 2621240Swosch} 2721240Swosch 2821240Swosch# 2921240Swosch# If user removes the job, LPD will send SIGINT, so trap SIGINT 3021240Swosch# (and a few other signals) to clean up after ourselves. 3121240Swosch# 3221240Swoschtrap cleanup 1 2 15 3321240Swosch 3421240Swosch# 3521240Swosch# Make sure we are not colliding with any existing files. 3621240Swosch# 3721240Swoschcleanup 3821240Swosch 3921240Swosch# 4021240Swosch# Link the DVI input file to standard input (the file to print). 4121240Swosch# 4221240Swoschln -s /dev/fd/0 hpdf$$.dvi || fatal "Cannot symlink /dev/fd/0" 4321240Swosch 4421240Swosch# 4521240Swosch# Make LF = CR+LF 4621240Swosch# 4721240Swoschprintf "\033&k2G" || fatal "Cannot initialize printer" 4821240Swosch 4921240Swosch# 5021240Swosch# Convert and print. Return value from dvilj2p does not seem to be 5121240Swosch# reliable, so we ignore it. 5221240Swosch# 5321240Swoschdvilj2p -M1 -q -e- dfhp$$.dvi 5421240Swosch 5521240Swosch# 5621240Swosch# Clean up and exit 5721240Swosch# 5821240Swoschcleanup 5921240Swoschexit 0 60