#! /bin/sh


echo "This is PRE PRE alpha stuff not running yet"
exit 1

### termcap stuff

CLS="tput cl"			# clear screen and home cursor
HOME="tput ho"			# home cursor
BOLD="tput md"			# bold on
STANDOUT="tput so"		# standout on
NORMAL="tput me"		# turn off all attributes
CEOS="tput cd"			# clear to end of screen
CEOL="tput ce"			# clear to end of line
DOWN="tput do"			# cursor down one line
UP="tput up"			# cursor up one line


################################################################################
# how to suppress newlines on echo command for nicer display ...
################################################################################

newlines()
{
	c=''
	n=''
	# first determine how to suppress newline on echo command
	(echo "hi there\c" ; echo " ") > /tmp/.echotmp
	if grep c /tmp/.echotmp >/dev/null 2>&1 ; then
    		n='-n'
    		c=''
	else
    		n=''
    		c='\c'
	fi
	rm -f /tmp/.echotmp
}

################################################################################
## wait for a keypress
################################################################################

KEYPRESS()
{
	$HOME
	for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
	do
		$DOWN
	done
	$BOLD
	echo $n "-- press <RETURN> to continue -- $c"
	read answer
	$NORMAL
}


################################################################################
## Do you really want to quit ?
################################################################################
GOTO_23()
{
	$HOME
	for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
	do
		$DOWN
	done
}

################################################################################
## Do you really want to quit ?
################################################################################
REALLY_QUIT()
{
	while [ ! $answer ]
	do
		$STANDOUT
		echo $n "Do you really want to quit ? $c"
		read answer
		$NORMAL
		case $answer in
			q|Q)	exit		;;
			*)	set answer=''	;;
		esac
	done
}

################################################################################
## help on keys
################################################################################
KEYS()
{
	echo ""
	echo "	[ press 'p' to enter previous menue || 'q' to quit ]"
	echo ""
}



################################################################################
## the introduction screen
################################################################################

banner()
{
# first clear screen
$CLS
cat << !EOM


	---------------------------------------------------------------
!EOM
$BOLD
cat << !EOM

	   A P S F I L T E R   V 4.8  *** The Unix Print Solution ***
!EOM
$NORMAL
cat << !EOM

	---------------------------------------------------------------

                     copyright Andreas Klemm 1993, 1994

                            andreas@knobel.gun.de

                   ---------------------------------------

			co-author Thomas Bueschgens 

			    sledge@hammer.oche.de

                         ---------------------------

!EOM
$NORMAL
# clear to end of screen
$CEOS
KEYPRESS
}

################################################################################
## ask user for choice
################################################################################
ASK()
{
	$HOME
	for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
	do
		$DOWN
	done
cat << !EOM
-------------------------------------------------------------------------------
!EOM
$STANDOUT
echo ""
if  [ ! DEFAULT ]; then
	echo $n "	Your choice ? $c"
else
	echo $n "	Your choice [ $DEFAULT ] ? $c"
fi
	read answer
$NORMAL
	case $answer in
		'')	set answer=$DEFAULT
			set DEFAULT=''
			;;
	esac
}

#------------------------------------------------------------------------------
# main menue screen
#------------------------------------------------------------------------------
main_screen()
{
$CLS
cat << !EOM
-------------------------------------------------------------------------------

!EOM
$BOLD
cat << !EOM
A P S F I L T E R   V 4.8           by Andreas Klemm <andreas@knobel.gun.de>
!EOM
$NORMAL
cat << !EOM

-------------------------------------------------------------------------------
!EOM
$BOLD
	echo ""
	echo ""
	echo "	S E T U P"
	echo ""
$NORMAL
cat << !EOM

	1) add a printer

	2) compile and install utilities (a2ps, rewindstdin)

	3) re-scan system for installed utilities

	q) quit setup

!EOM
# inform about 'p'
KEYS

	PREVIOUS=main_screen
	ASK
	case $answer in 
		1)	NEXT=printer_add	;;
		2)	NEXT=compile_install	;;
		3)	NEXT=printer_add	;;
		p)	NEXT=$PREVIOUS		;;
		q)	exit			;;
		*)	NEXT=main_screen	;;
	esac
	$NEXT
}

##
## main routine
##

	# when receiving a trap, then cleanup everything a bit ;-)
	trap '$NORMAL; REALLY_QUIT' 1 2 15

	$NORMAL
	# print the name of the game
	banner
	# calculate $n and $c how to suppress newlines
	newlines
	# draw the main screen
	main_screen
