Laserjet+ interface and printer script
Michael Wescott
wescott at sauron.UUCP
Sat Mar 22 02:34:06 AEST 1986
There are two shell scripts here. hplp.sh is an program that goes
into /usr/bin or /usr/local or ... hplp is an LP spooler interface program.
It is set up for parallel port operation but should be easily modified for
serial port operation. Hplp.sh is the program that handles setting up the
data sent to the Laserjet for various options like changing fonts, portrait or
landscape selection etc. It is invoked on the command line and automatically
invokes "lp -dhplp ..."
Sorry, no man page.
pr -l110 file1 file2 file3 | hplp -Flp -l110
puts 100 lines of text (from the files) plus 5 line headers and trailers. It
specifies portrait orientation and the line printer font.
# This is a shell archive. Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file". (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# hplp hplp.sh
echo x - hplp
cat > "hplp" << '//E*O*F hplp//'
#
#lp interface for hp laser jet
#staight cat of file - no banner
#
x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "\\033E\\c"
echo "\\033&k2G\\c"
echo "$x\n$x\n$x\n$x\n"
banner "$2"
echo "\n"
user=`grep "^$2:" /etc/passwd | line | cut -d: -f5`
if [ -n "$user" ]
then
echo "User: $user\n"
else
echo "\n"
fi
echo "Request id: $1 Printer: `basename $0`\n"
date
echo "\n"
if [ -n "$3" ]
then
banner $3
fi
copies=$4
echo "\n Copies: ${copies}"
#reset
echo "\\033E\\c"
shift; shift; shift; shift; shift
files="$*"
i=1
while [ $i -le $copies ]
do
for file in $files
do
cat $file 2>&1
done
i=`expr $i + 1`
done
#reset
echo "\\033E\\c"
exit 0
//E*O*F hplp//
echo x - hplp.sh
cat > "hplp.sh" << '//E*O*F hplp.sh//'
#! /bin/sh
# filter to set up for feeding data to the hp laserjet+
# -L = landscape -P = portrait
# -m = margins off; use "pr -l## -f -t" instead of cat
# -c ## = # of copies
# -F xx = set font (for now only lp has effect, only in portrait mode)
# -l xxx = set number of printed lines per page (used to calc VMI)
# -a = set auto feed
# -h = set hand feed
# -n no conv of nl to cr + nl
# -t no tabs expanded
# -T xxxx -> title
# defaults -Pa -l66 -c1
destination=hplp
portrait=1
copies=1
lines=0
margin=1
autofeed=1
autocrnl=1
font=courier
tabs=1
CAT=/bin/cat
NEWF="newform -i -l200"
set -- `getopt nPLc:ahl:mF:T: $*`
if [ $? != 0 ]
then
echo "usage: hplp [-[PLFmaht] [-l##] [-c##]] [files]"
exit 2
fi
for i in $*
do
case $i in
-L) portrait=0; shift;;
-P) portrait=1; shift;;
-m) margin=0; shift;;
-h) autofeed=0; shift;;
-a) autofeed=1; shift;;
-F) shift; font=$1; shift;;
-T) shift; title=$1; shift;;
-l) shift; lines=$1; shift;;
-c) shift; copies=$1; shift;;
-n) autocrnl=0; shift;;
-t) tabs=0; shift;;
--) shift; break;;
esac
done
if [ ${portrait} = 1 ]
then
if [ ${lines} = 0 ]
then
lines=66
fi
if [ ${margin} = 1 ]
then
pagelength=10.0
else
pagelength=10.5
CAT="/bin/pr -l${lines} -t -f"
fi
else
if [ ${lines} = 0 ]
then
lines=48
fi
if [ ${margin} = 1 ]
then
pagelength=7.5
else
pagelength=8.0
CAT="/bin/pr -l${lines} -t -f"
fi
fi
if [ -z "${title}" ]
then
title=$LOGNAME
fi
if [ -z "${title}" ]
then
title="Laserjet"
fi
# set VMI
VMI=`dc <<XxXxXxX
4k 48 ${pagelength} * ${lines} / pq
XxXxXxX`
( echo "\033E\c" # reset
if [ ${portrait} != 1 ]
then
echo "\033&l1O\c" # set landscape
else
if [ ${font} = lp ]
then
echo "\033(0U\033(s16.6h8.5v0s-3b0T\c" # line printer font
fi
fi
echo "\033&l${lines}f${VMI}C\c" # set text length and VMI
echo "\033&s1C\c" # no auto wrap at eol
if [ ${margin} = 0 ]
then
echo "\033&l0L\033&a0r0C\c" # reset perf skip; goto 0,0
fi
if [ ${autocrnl} = 1 ]
then
echo "\033&k2G\c" # set lf = cr + lf
fi
if [ ${autofeed} = 0 ]
then
echo "\033&l2H\c" # set manual feed
fi
if [ tabs = 0 ]
then
if test $1
then
for i in $*
do
if test -r $i
then
${CAT} $i
fi
done
else
${CAT} -
fi
else
if test $1
then
for i in $*
do
if test -r $i
then
${CAT} $i
fi
done
else
${CAT} -
fi | ${NEWF}
fi
) | lp -d${destination} -n${copies} -t${title}
//E*O*F hplp.sh//
exit 0
More information about the Comp.sources.unix
mailing list