From: rick@digibd.digibd.com (Rick Richardson)
Subject: Re: HP LJ4: Postscript vs. Text
Organization: DigiBoard, Incorporated, Eden Prairie,MN
Date: Tue, 15 Dec 1992 10:01:45 GMT

tspila@uxa.cso.uiuc.edu (Spila Timothy) writes:

>I have heard that the new HP LJ4 is supposed to be able to handle both
>postscript and text.  (I am assuming the correct type of LJ4).  How does
>it handle the two possibilites?  Does it look at the first few
>characters, and use that do to decide whether it is trying to print
>postscript or text?

I think it does, but it doesn't always work correctly coming out of
PS mode back into PCL mode.  However, it has explicit methods to
set the mode, which seem to work correctly all the time.  Here is
our LP model, which I just hacked the other day when we got the LJ4.
Sorry it still shows the signs of recent hacking.  But it works for
us fine.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  hp4laser
# Wrapped by rick@digibd on Tue Dec 15 04:01:24 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f hp4laser -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"hp4laser\"
else
echo shar: Extracting \"hp4laser\" \(5882 characters\)
sed "s/^X//" >hp4laser <<'END_OF_hp4laser'
X# hplaser:
X#	lp model interface for HP LaserJet Series IV
X#
X#	Note: hacked from the LJ2/Pacific Page version, and I haven't
X#	cleaned up the comments in this script yet.
X#
X#	See the CONFIGURATION SECTION below to adjust for your site.
X#
X# Copyright 1990 PC Research, Inc. All Rights Reserved.
X# Copyright 1992 DigiBoard, Inc. All Rights Reserved.
X# Permission granted for non-commercial use without fee
X#
X# command arguments are:
X#	request-id user-name title copies printer-options file1 [file2 ...]
X#	$1         $2        $3    $4     $5
X#
X# options are:
X#	-otroff		#No cr/lf mapping (for JetRoff, etc.)
X#	-oraw		#Same
X#	-oland		#Landscape orientation for unformatted text
X#	-oport		#Portrait orientation for unformatted text
X#	-o2on1		#Two pages on one page for unformatted text
X#	-oi		#Indent 8 characters for unformatted text
X#	-o17cpi		#17 CPI for unformatted text
X#	-ohp		#Force use of PCL mode
X#	-ops		#Force use of PS mode
X#
X#	-onobanner	Force no banner
X#	-onofilebreak	Force no file break
X# TODO:
X#	-ocpi=pica	10 CPI
X#	-ocpi=elite	12 CPI
X#	-ocpi=		Other CPI
X#	-olpi=		LPI
X#	-olength=
X#	-owidth=
X#	-oindent=	Offset page by N characters
X#
X
X#
X# BEGIN CONFIGURATION SECTION (adjust these as needed)
X#
Xspeed=38400	#Serial interface speed (19.2)
Xspeed=		#Parallel interface leave blank
Xbanner=0	#Enable printing of banner page
Xpacpage=1	#Postscript capability installed
Xidlemode="hp"	#Idle printer in "hp" mode or "ps" mode (when pacpage=1)
Xpost_pcl_sleep=60	# Sleep time switching from PCL to PS
Xpost_ps_sleep=120	# Sleep time switching from PS to PCL
X#
X# END CONFIGURATION SECTION
X#
X
X#
X#	Give names to the command line arguments
X#
Xprinter=`basename $0`
Xrequest_id=$1
Xuser_name=$2
Xtitle="$3"
Xcopies=$4
Xoptions=$5
Xshift 5
Xfiles="$*"
Xnfiles=$#
X
X#
X#	If serial interface, set speed
X#
Xif [ "$speed" != "" ]
Xthen
X	stty $speed clocal cs8 ixon ixoff -ixany -parenb onlcr -tabs -opost <&1
Xfi
X
X#
X#	Define some shorthand for PCL sequences
X#
XNORAW="\033&k2G"		#Translate LF to CR+LF and FF to CR+FF
XRAW="\033&k0G"			#Do not translate CR, LF, or FF
X
XRESETJOB="\033E\033&l2A"	#Reset printer, eject if any printing on page,
X				#Select letter paper by default
XRESETPAGE="\033E"		#Reset printer, eject if any printing on page
X
X#
X#	getarg <arg>:	given an <arg> of the form "x=y", return the "y"
X#
Xgetarg () {
X	echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
X}
X
X#
X#	postscript <file>: if <file> is a Postscript file, return true
X#
Xpostscript () {
X	if [ $pacpage = 0 ]; then return 1; fi
X	if [ $force = "hp" ]; then return 1; fi
X	if [ $force = "ps" ]; then return 0; fi
X	#case "`sed -n '1s/\(..\).*/\1/p' $1`" in
X	#%!)	return 0;;
X	#?%)	return 0;;
X	#*)	return 1;;
X	#esac
X	ctrl_d=`echo "\004\c"`
X	read a <$1
X	case "$a" in
X	%!*)		return 0;;
X	"$ctrl_d"%!*)	return 0;;
X	*)		return 1;;
X	esac
X}
X
X#
X#	Definition of the banner page for an HP printer
X#
Xhp_banner () {
X	PCOURIER=	# "\033&l66p2e7.6c66F"
X	GRAY="\033*c2400a150b30g2P"
X	TLOC="\033*p0x0Y"
X	echo "$RESETJOB$NORAW$PCOURIER$TLOC$GRAY\n\n\n\n"
X	banner "  $user_name"
X	echo "\n"
X	full_name=`grep "^$user_name:" /etc/passwd | line | cut -d: -f5`
X	if [ -n "$full_name" ]
X	then
X		echo "                User: $full_name\n"
X	else
X		echo "\n"
X	fi
X	echo "                Request id: $request_id    Printer: $printer`\n"
X	echo "                Options: $options\n"
X	echo "                `date`"
X	echo "\n"
X	if [ -n "$title" ]
X	then
X		banner $title
X	fi
X	echo "$RESETJOB\c"
X}
X
X#
X#	Postscript banner page
X#
Xps_banner () {
X	:
X}
X
X#
X#	Switch to PS mode
X#
Xps_mode () {
X	#sleep 5
X	echo "\033%-12345X@PJL enter language=postscript"
X	echo "\r\004\c"
X	#if [ $cur_mode != "ps" ]
X	#then
X	#	sleep $post_pcl_sleep
X	#	cur_mode="ps"
X	#	echo "$PSMODE\c"
X	#	sleep 40
X	#else
X	#	echo "\r\004\c"
X	#fi
X}
X
X#
X#	Switch to HP mode
X#
Xhp_mode () {
X	#sleep 5
X	echo "\033%-12345X@PJL enter language=pcl"
X	echo "$RESETJOB\c"
X	#if [ $cur_mode != "hp" ]
X	#then
X	#	echo "\r\r\004\c"
X	#	sleep $post_ps_sleep
X	#	cur_mode="hp"
X	#	echo "$HPMODE\c"
X	#	sleep 30
X	#else
X	#	echo "$RESETJOB\c"
X	#fi
X}
X
X#
X#	Process user options
X#
Xraw=0
Xorient=port
Xcpi=10
Xlpi=6
Xindent=0
Xlength=0
Xwidth=0
Xfilebreak=1
Xtwo_on_one=0
Xforce=no
Xfor o in $options
Xdo
X	case $o in
X	raw|troff)	raw=1;;
X	land)		orient=land;;
X	port)		orient=port;;
X	17cpi)		cpi=16.66;;
X	i)		indent=8;;
X	2on1)		two_on_one=1;;
X	cpi=pica)	cpi=10;;
X	cpi=elite)	cpi=12;;
X	cpi=*)		cpi=`getarg ${o}`;;
X	indent=*)	indent=`getarg ${o}`;;
X	length=*)	length=`getarg ${o}`;;
X	width=*)	width=`getarg ${o}`;;
X	lpi=*)		lpi=`getarg ${o}`;;
X	nobanner)	banner=0;;
X	nofilebreak)	filebreak=0;;
X	ps)		force="ps";;
X	hp)		force="hp";;
X	ps_sleep=*)	post_ps_sleep=`getarg ${o}`;;
X	pcl_sleep=*)	post_pcl_sleep=`getarg ${o}`;;
X	esac
Xdone
X
X#
X#	Init the printer, set exit traps
X#
Xif [ $pacpage = 0 ]
Xthen	# force PCL only operation
X	HPMODE=
X	idlemode=hp
Xfi
X#case $idlemode in
X#hp)	cur_mode=hp; hp_mode; echo "$RESETJOB\c"
X#	trap 'hp_mode; exit' 0 2 3 15
X#	;;
X#ps)	cur_mode=ps; ps_mode;
X#	trap 'ps_mode; exit' 0 2 3 15
X#	;;
X#esac
X
X#
X#	Get printer banner page out in portrait, courier
X#
Xif [ $banner = 1 ]
Xthen
X	case $idlemode in
X	hp)	hp_banner;;
X	ps)	ps_banner;;
X	esac
Xfi
X
X#
X#	Set variables to use when file is printed in PCL mode
X#
XSET=
XSET="$SET\033(s${cpi}H"
XSET="$SET\033&a${indent}L"
Xif [ $raw = 1 ]; then CRMODE=$RAW; else CRMODE=$NORAW; fi
Xif [ $orient = "land" ]; then
X	SET="$SET\033&l1O\033(s16.66H\033&l5.4C\033&l6E\033&a0R\033&l66F"
Xfi
Xif [ $two_on_one = 1 ]; then
X	SET="$SET\033&l1O\033(s16.66H\033&l5.4C\033&l6E\033&a0R\033&l66F"
Xfi
X
X#
X#	Loop for each copy, and then for each file
X#
Xcopy=1
Xwhile [ $copy -le $copies ]
Xdo
X	for file in $files
X	do
X		if postscript $file
X		then
X			ps_mode
X			cat $file
X		else
X			hp_mode
X			echo "$SET$CRMODE\c"
X			if [ $two_on_one = 1 ]
X			then
X				cat "$file" | newform -i | \
X					sed "s/^/| /" | pr -2 -w175 -t
X			else
X				cat "$file"
X			fi
X			if [ $filebreak = 1 ]; then echo "$RESETPAGE\c"; fi
X		fi
X	done
X	copy=`expr $copy + 1`
Xdone
Xexit 0
END_OF_hp4laser
if test 5882 -ne `wc -c <hp4laser`; then
    echo shar: \"hp4laser\" unpacked with wrong size!
fi
chmod +x hp4laser
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
--
Rick Richardson		Senior Staff Engineer	Investment advice for 1993-1996:
DigiBoard, Inc.		Email: rick@digibd.com	Go long on Arkansas chicken
6400 Flying Cloud Dr.	Fax:   (612) 943-0803	Go short on everything else
Eden Prarie, MN 55344	Tel:   (612) 943-5383	<standard disclaimer>
Newsgroups: comp.periphs.printers