#!/bin/sh

usage() {
cat <<EOF
#
#	text2landfax [options] text-file fax-file
#
#	Convert wide plain-text files to Landscape mode using the
#	"faxjet" HP LaserJet emulator and its 16.66 cpi Courier font.
#
#	Options:
#	-l		Low resolution fax output
#	-P letter	Use letter size paper for 178 columns wide
#	-P a4		Use A4 size paper for 189 columns wide
#	-P legal	Use legal size paper for 228 columns wide
#
EOF
}

#
#	Process the options
#
Paper=letter
Res=

set -- `getopt ?lP: $*`
if [ $? != 0 ]; then usage; exit 2; fi

for i in $*
do
	case $i in
	-l)		Res="-l"; shift;;
	-P)		Paper="$2"; shift; shift;;
	--)		shift; break;;
	-?)		usage; exit 0;;
	esac
done
if [ $# != 2 ]; then usage; exit 2; fi

#
#	Figure out the PCL we need to put the printer into the right modes
#
SET=
SET="$SET\033E"		# Printer reset
SET="$SET\033&l1O"	# Landscape orientation (1)
SET="$SET\033(s16.66H"	# Select 16.66 CPI Courier font
SET="$SET\033&l5.45C"	# Vertical motion in 48ths of an inch
SET="$SET\033&l6E"	# Top margin in lines (6)
SET="$SET\033&a0R"	# Move to line 0
SET="$SET\033&l66F"	# Text length in lines (66)

#
#	Pass the PCL and the text file thru "faxjet" to make a fax file
#
(echo "$SET\c"; cat $1) | faxjet2 -T2 -P$Paper $Res -o $2
