#!/bin/sh -
PATH=/l/picons/apps:$PATH; export PATH

mail="$MAIL"
newshome="$HOME"
orachome=/nfs/moose/u/oracle
cmqhost=moose
nftarg=cs.system
wxtarg=dtw

NEWSRC="${NEWSRC-$newshome/.nn/newsrc}"; export NEWSRC

# facemon - personalized convenience front-end for faces monitors
# Steve Kinzler, steve@kinzler.com, Oct 93/Feb 95
# https://kinzler.com/me/home.html#x11
# https://kinzler.com/ftp/faces/

mailqs='mailq mailqto'
cmailqs='cmailq cmailqto'
amailqs="$mailqs $cmailqs"
system="lpqall $amailqs wx"
oracle='vote recd'
incoming="$oracle newscheck"
sidebar="lpqall $cmailqs wx $oracle newscheck"
all="$system $incoming"

xmailqs='xmailq xmailqto'
xcmailqs='xcmailq xcmailqto'
xamailqs="$xmailqs $xcmailqs"
xsystem="xlpqall $xamailqs xwx"
xoracle='xvote xrecd'
xincoming="$xoracle xnewscheck"
xsidebar="xlpqall $xcmailqs xwx $xoracle xnewscheck"
xall="$xsystem $xincoming"

slots=; bad=; fargs=; args=

while :
do
	case $# in
	0)	break;;
	*)	case "$1" in
		-G)		slots=t;;

		-h)		case "$2" in
				[0-9]*)	fargs="$fargs $1 $2"; shift;;
				*)	bad=t; break;;
				esac;;

		-W[pP])		fargs="$fargs $1 $2 $3"; shift; shift;;
		-[BHPSbcdefglpsw]|-[bf]g|-db|-dbn|-NF|-W|-pop|-name)
				fargs="$fargs $1 $2";    shift;;
		-*)		fargs="$fargs $1";;

		mailqs)		args="$args $mailqs";;
		cmailqs)	args="$args $cmailqs";;
		amailqs)	args="$args $amailqs";;
		system)		args="$args $system";;
		oracle)		args="$args $oracle";;
		incoming)	args="$args $incoming";;
		sidebar)	args="$args $sidebar";;
		all)		args="$args $all";;

		xmailqs)	args="$args $xmailqs";;
		xcmailqs)	args="$args $xcmailqs";;
		xamailqs)	args="$args $xamailqs";;
		xsystem)	args="$args $xsystem";;
		xoracle)	args="$args $xoracle";;
		xincoming)	args="$args $xincoming";;
		xsidebar)	args="$args $xsidebar";;
		xall)		args="$args $xall";;

		*)		args="$args $1";;
		esac
		shift;;
	esac
done

if test -z "$args" -o -n "$bad"
then
	cat << EOF 1>&2
usage: $0 [ -G ] [ faces options | xfaces options ]
       [ NAME | xNAME ] ...
	-G	place monitors in their allocated geometry slots
NAMEs:
	all      = $all
	sidebar  = $sidebar
	system   = $system
	amailqs  = $amailqs
	mailqs   = $mailqs
	cmailqs  = $cmailqs
	incoming = $incoming
	oracle   = $oracle
	SLOT# mail from newsfrom newsrc lpq lp[0-9]* ps[0-9]* xface
	{,new}local {,new}domains {,new}unknown {,new}news {,new}weather
	{,new}misc {,new}users usenix
EOF
	exit 1
fi

case "$slots" in
?*)	slot1='-WP 0 0   -iconic'
	slot2='-WP 0 66  -iconic'
	slot3='-WP 0 132 -iconic'
	slot4='-WP 0 198 -iconic'
	slot5='-WP 0 264 -iconic'

	slot6='-WP 0 368 -iconic'
	slot7='-WP 0 434 -iconic'
	slot8='-WP 0 500 -iconic'
	slot9='-WP 0 566 -g +0-268'

	slotx='-geometry +0-260';;

*)	slot1=; slot2=; slot3=; slot4=; slot5=
	slot6=; slot7=; slot8=; slot9=; slotx=;;
esac

for arg in $args
do
	case "$arg" in
	1|lpqall)	 faces -PA $slot1 $fargs &;;
	xlpqall)	xfaces -PA	  $fargs &;;

	2|cmailq)	xrsh "$cmqhost" \
			 faces -Q  $slot2 -l	 mailq@$cmqhost   $fargs &;;
	xcmailq)	xrsh "$cmqhost" \
			xfaces -Q	  -title mailq@$cmqhost   $fargs &;;
	mailq)		 faces -Q				  $fargs &;;
	xmailq)		xfaces -Q				  $fargs &;;
	3|cmailqto)	xrsh "$cmqhost" \
			 faces -Q2 $slot3 -l	 mailqto@$cmqhost $fargs &;;
	xcmailqto)	xrsh "$cmqhost" \
			xfaces -Q2	  -title mailqto@$cmqhost $fargs &;;
	mailqto)	 faces -Q2				  $fargs &;;
	xmailqto)	xfaces -Q2				  $fargs &;;

	4|wx)		 faces -W $wxtarg $slot4 $fargs &;;
	xwx)		xfaces -W $wxtarg	 $fargs &;;

	6|vote)		(MAIL="$orachome"/post/vote; export MAIL
			  faces -alt -F $slot6 -l vote		  $fargs &);;
	xvote)		(MAIL="$orachome"/post/vote; export MAIL
			 xfaces      -F -C -title vote -s "$MAIL" $fargs &);;

	7|recd)		(MAIL="$orachome"/post/recd; export MAIL
			  faces -alt -F $slot7 -l recd		  $fargs &);;
	xrecd)		(MAIL="$orachome"/post/recd; export MAIL
			 xfaces      -F -C -title recd -s "$MAIL" $fargs &);;

	8|newscheck)	(HOME="$newshome"; export HOME
			  faces -N $slot8 -p 150 $fargs &);;
	xnewscheck)	(HOME="$newshome"; export HOME
			 xfaces -N	  -p 150 $fargs &);;

	9|from)		(MAIL="$mail"; export MAIL
			  faces -alt -F $slot9 -p 15 $fargs &);;
	xfrom)		(MAIL="$mail"; export MAIL
			 xfaces -alt -F        -p 15 $fargs &);;

	mail)		(MAIL="$mail"; export MAIL
			  faces -F	     -s "$MAIL" -p 5 $fargs &);;
	xmail)		(MAIL="$mail"; export MAIL
			 xfaces -F -C $slotx -s "$MAIL" -p 5 $fargs &);;

	newsfrom)	 faces -NF "$nftarg" $fargs &;;
	xnewsfrom)	xfaces -NF "$nftarg" $fargs &;;
	newsrc)		 faces -NR	     $fargs &;;
	xnewsrc)	xfaces -NR	     $fargs &;;

	lpq)		 faces -P ${PRINTER-lp} -p 15 $fargs &;;
	lp[0-9]*)	 faces -P "$arg"        -p 15 $fargs &;;
	ps[0-9]*)	 faces -P "$arg"        -p 15 $fargs &;;

	xface)		 faces -dbn xface   $fargs &;;
	newxface)	 faces -dbn xface   $fargs &;;
	local)		 faces -db  local   $fargs &;;
	newlocal)	 faces -dbn local   $fargs &;;
	domains)	 faces -db  domains $fargs &;;
	newdomains)	 faces -dbn domains $fargs &;;
	unknown)	 faces -db  unknown $fargs &;;
	newunknown)	 faces -dbn unknown $fargs &;;
	news)		 faces -db  news    $fargs &;;
	newnews)	 faces -dbn news    $fargs &;;
	weather)	 faces -db  weather $fargs &;;
	newweather)	 faces -dbn weather $fargs &;;
	misc)		 faces -db  misc    $fargs &;;
	newmisc)	 faces -dbn misc    $fargs &;;
	users)		 faces -db  users   $fargs &;;
	newusers)	 faces -dbn users   $fargs &;;
	usenix)	 	 faces -db  usenix  $fargs &;;

	xxface)		xfaces -dbn xface   $fargs &;;
	xnewxface)	xfaces -dbn xface   $fargs &;;
	xlocal)		xfaces -db  local   $fargs &;;
	xnewlocal)	xfaces -dbn local   $fargs &;;
	xdomains)	xfaces -db  domains $fargs &;;
	xnewdomains)	xfaces -dbn domains $fargs &;;
	xunknown)	xfaces -db  unknown $fargs &;;
	xnewunknown)	xfaces -dbn unknown $fargs &;;
	xnews)		xfaces -db  news    $fargs &;;
	xnewnews)	xfaces -dbn news    $fargs &;;
	xweather)	xfaces -db  weather $fargs &;;
	xnewweather)	xfaces -dbn weather $fargs &;;
	xmisc)		xfaces -db  misc    $fargs &;;
	xnewmisc)	xfaces -dbn misc    $fargs &;;
	xusers)		xfaces -db  users   $fargs &;;
	xnewusers)	xfaces -dbn users   $fargs &;;
	xusenix)	xfaces -db  usenix  $fargs &;;

	*)		echo "$0: unknown name ($arg)" 1>&2;;
	esac
done
