xref: /freebsd/share/examples/printing/ifhp (revision 70fe3a9f9ff404ba6fe007d83f98c55383e288da)
1f5bc5997SWolfram Schneider#!/bin/sh
2f5bc5997SWolfram Schneider#
3f5bc5997SWolfram Schneider#  ifhp - Print Ghostscript-simulated PostScript on a DesJet 500
4f5bc5997SWolfram Schneider#  Installed in /usr/local/libexec/hpif
5f5bc5997SWolfram Schneider
6f5bc5997SWolfram Schneider#
7f5bc5997SWolfram Schneider#  Treat LF as CR+LF:
8f5bc5997SWolfram Schneider#
9f5bc5997SWolfram Schneiderprintf "\033&k2G" || exit 2
10f5bc5997SWolfram Schneider
11f5bc5997SWolfram Schneider#
12f5bc5997SWolfram Schneider#  Read first two characters of the file
13f5bc5997SWolfram Schneider#
14f5bc5997SWolfram Schneiderread first_line
15f5bc5997SWolfram Schneiderfirst_two_chars=`expr "$first_line" : '\(..\)'`
16f5bc5997SWolfram Schneider
17f5bc5997SWolfram Schneiderif [ "$first_two_chars" = "%!" ]; then
18f5bc5997SWolfram Schneider    #
19f5bc5997SWolfram Schneider    #  It is PostScript; use Ghostscript to scan-convert and print it
20f5bc5997SWolfram Schneider    #
21f5bc5997SWolfram Schneider    /usr/local/bin/gs -dSAFER -dNOPAUSE -q -sDEVICE=djet500 -sOutputFile=- - \
22f5bc5997SWolfram Schneider        && exit 0
23f5bc5997SWolfram Schneider
24f5bc5997SWolfram Schneiderelse
25f5bc5997SWolfram Schneider    #
26f5bc5997SWolfram Schneider    #  Plain text or HP/PCL, so just print it directly; print a form
27f5bc5997SWolfram Schneider    #  at the end to eject the last page.
28f5bc5997SWolfram Schneider    #
2970fe3a9fSRobert Nordier    echo "$first_line" && cat && printf "\f" && exit 0
30f5bc5997SWolfram Schneiderfi
31f5bc5997SWolfram Schneider
32f5bc5997SWolfram Schneiderexit 2
33