#! /bin/sh


function terminate
{
	echo 'Usage:'
	echo '# hp50g <command>'
	echo 'Command:'
	echo '- bye'
	echo '- dir'
	echo '- bin'
	echo '- txt'
	echo '# hp50g <mode> <file> [<file2> [<file3> ... ]]'
	echo 'Mode:'
	echo '- p, s, t (put, send, transmit = PC-->HP50g)'
	echo '- g, r    (get, receive        = HP50g-->PC)'
	exit
}


function operate
{
	echo -e "$1\nquit" | kermit
 	echo
}


function operate_flag35
{
	operate "remote host -35. $1"
}


if test "$#" -lt 2
then
	if test "$#" -ne 1
	then
		terminate
	fi
	case "$1" in
		bye)	operate "bye"					;;
		dir)	operate "remote dir"			;;
		bin)	operate_flag35 "SF"				;;
		txt)	operate_flag35 "CF"
				operate "remote host 3 TRANSIO"	;;
		*)		terminate
	esac
	exit
fi
case "$1" in
	p|s|t)
		shift
		for fil in "$@"
		do
			if [ ! -f $fil ]
			then
				echo "$fil - file not found!"
				exit
			fi
		done
		operate "msend $*"
		;;

	g|r)
		shift
		for fil in "$@"
		do
			operate "get $fil"
		done
		;;

	*)
		terminate
esac
