! 8 Feb 87
!
! Name:		remlpr.cmd
! Purpose:	provide seamless remote file printing support... ie: print
!		local text files out on remote unix system such as altos, etc.
! Usage:	term -u remlpr <system> <file1> <file2> ... <file7>
!
!		Where:
!		<system> is a configuration which logs into the system
!			which is supposed to do the printing of the file(s)
!		<filen> is a filename.  Up to 6 files may be printed.
!
! WARNING:	Text file conversion is automatic, so do not try nifty
!		non-portable graphics and stuff like that.

if len("$1")=0 | len("$2")=0
	? "remlpr: You need to specify a system and the file(s) to print"
	quit
endif
connect $1

xmit "cd /tmp\r"
wait "bad",3
flush

if !_timeout
	? "remlpr: Unable to cd on remote"
	repeat
		xmit "^c^c\177\177^d^d^d"
		wait "ogin:",5
	until !_timeout 
	quit
endif

? "Establishing remote link..."
xmit "term -x\r"
wait "OK",15
flush

if _timeout
	? "remlpr: Unable to run term -x"
	repeat
		xmit "^c^c\177\177^d^d^d"
		wait "ogin:",5
	until !_timeout
	quit
endif

for i in ($2 $3 $4 $5 $6 $7) do
	iferror xfer $i .[c]
		? "remlpr: Failure of $i transfer"
	endif
endfor
flush
repeat
	xmit "^c"
	wait "\$",5
until !_timeout
flush

? "Starting printer on: $2 $3 $4 $5 $6 $7"
wait 1
xmit "lpr $2 $3 $4 $5 $6 $7\r"
wait 1
xmit "^D\n"
wait 1
flush

? "Disconnecting..."
repeat
	xmit "^c^c\177\177^d^d^d"
	wait "ogin:",5
until !_timeout
quit
