#!/bin/sh
#******************************************************************************
# @(#)
# @(#)  File           :      type01
# @(#)
# @(#)  Printer        :      HP LaserJet 4
# @(#)  Emulation Mode :      HP
# @(#)  Character Set  :      -
# @(#)
# @(#)  Date           :      09-07-97
# @(#)  Driverset      :      97.002
# @(#)  Bshell Version :      6.1C
# @(#)  Driver Version :      6.1.01
# @(#)  Copyright      :      Simac Services b.v. (c)
# @(#)  Customer       :      Baan Development b.v.
# @(#)
# @(#)  Comment        :
# @(#)      Driver for HP Laserjet 4 with "Bar Codes & More Font Cartridge"
# @(#)
# @(#)      Prints EAN/UPC with the code under it.
# @(#)      According HP's manual it should be possible to print OCR-A or OCR-B
# @(#)      between the three barcode stop marks. This is not true. This font is
# @(#)      too large. So a 12 cpi pitch is used.
# @(#)      30-09-1998 : Driver changed for System IBM_AS400.
# @(#)                   Change made by IBM-CTC,  Baan Development n.v., ML
# @(#)
# @(#)
#******************************************************************************

PLATFORM=`uname`
IBM_AS400="OS400"

code=$1
height=$2

Push()
{
	# push cursor position (max 20x)
	echo "\033&f0S\c"
}

Pop()
{
	# pop cursor position
	echo "\033&f1S\c"
}

NextRow()
{
	# move to next row, relative
	echo "\033&a+1R\c"
}

# - save cursor position - filter assumes same position after barcode print
Push

if [ ${PLATFORM} = ${IBM_AS400} ]
then

	# Break the 10 character input string into two 5 character strings.
	# qsh does not support substing...

	eval $(echo $code | sed -e 's/^.\{5\}/str1=&;str2=/;')

else

	#  This is the way it is done on other unix systems, but qsh does not support awk

	str1=`echo $code | awk '{ print substr($1, 1, 5) }'`
	str2=`echo $code | awk '{ print substr($1, 6, 5) }'`
fi

# - select EAN/UPC 13 mil font
echo "\033(8Y\033(s1p12v0s3b0T\c"

while [ $height -gt 1 ]
do
	Push
	echo "($str1-$str2(\c"
	Pop
	NextRow
	height=`expr $height - 1`
done

# - last (empty) line of barcode
Push
	echo "(     -     (\c"
Pop

# - select Courier Bold 12 cpi
echo "\033(12U\033(s0p12h0s3b4099T\c"

# - move x+25 dots
echo "\033*p+25X\c"

# - print code (text)
echo "$str1 $str2\c"

# - restore cursor position for filter
Pop

exit 0
