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