#!/bin/csh -f
# David R. Williams (dougie@athena.mit.edu)
# You wan't comments?  Put them in yourself...
# If you can't understand it, don't use it...

set W20 = 'ceres python ajax w20-east-1 w20-east-2 w20-east-3'
set M1 = 'plato'
set M4 = 'pandora medea'
set M6 = 'otho zeno'
set M16 = 'helios'
set M37 = 'electra'
set M66 = 'homer'
set E51 = 'picus'

set location = $1
switch ($location)
	case 1:
		set list = "$M1"
	breaksw
	case 4:
		set list = "$M4"
	breaksw
	case 6:
		set list = "$M6"
	breaksw
	case 16:
		set list = "$M16"
	breaksw
	case 37:
		set list = "$M37"
	breaksw
	case 66:
		set list = "$M66"
	breaksw
	case E51:
		set list = "$E51"
	breaksw
	default:
		set list = "$W20"
	breaksw
endsw
echo -n 'What file to print: '
set file = $<
foreach printer ($list)
	lpq -P$printer | grep 'no entries' > /dev/null
	if $status == 0 then
		echo $printer
		lpr -P$printer $file
		break
	endif
end
if $status == 1 then
	num = 1
	while stat != p
		lpq -P$list[num] | grep 'ready and printing' > /dev/null
		if status == 0 then
			lpr -P$list[num] $file
			echo $list[num]
			stat = p
			printer = $list[num]
		else
			@ num++
		endif
	end
endif
