[comp.sources.games] v03i091: quizm - a menu driven quiz using ksh

games-request@tekred.TEK.COM (03/02/88)

Submitted by: "Dik T. Winter" <mcvax!cwi.nl!dik@uunet.uu.net>
Comp.sources.games: Volume 3, Issue 91
Archive-name: quizm

	[As we don't have the Korn shell on this system, I wasn't
	 able to try it out - you're on your own. WARNING: when
	 you unshar quiz.sh, it creates filenames with imbedded
	 whitespace. This may not be a problem for ksh, but could
	 cause potential problems with other shells.  -br]

This is something I made together with a silly co-worker (this is
the third time, I hope he minds).  It shows that on a Berkeley
system with the Korn shell there are simple methods to create a
menu driven system.  It provides a completely menu driven front-end
for quiz.  See README and Makefile for details.  (Note that quiz.sh,
one of the files, is a sharfile itself.)  If there is real interest
for a man page for quizm (menu-driven quiz), I can write it; a man
page for the system is a whole other story;  I will write it only
if there is sufficient interest.  Note: no compilers are needed,
only the original game of quiz (which is assumed to reside in /usr/games).

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 1)."
# Contents:  README MANIFEST Makefile menusystem quiz.sh
# Wrapped by billr@saab on Tue Mar  1 16:21:37 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f README -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"README\"
else
echo shar: Extracting \"README\" \(348 characters\)
sed "s/^X//" >README <<'END_OF_README'
XThis set of files provide a menu based interface to quiz.
XThe interface is probably incomplete, but additions are easy to make.
XAlso the response to interrupts is not yet as is should be.
XThey show how you can use the Korn shell to provide a menu system.
XFor more information see the Makefile.
X
Xdik t. winter
Xdik@cwi.nl
X{ dik%cwi.nl@uunet.uu.net }
END_OF_README
if test 348 -ne `wc -c <README`; then
    echo shar: \"README\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f MANIFEST -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"MANIFEST\"
else
echo shar: Extracting \"MANIFEST\" \(264 characters\)
sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X MANIFEST                  1	This shipping list
X Makefile                  1	
X README                    1	
X menusystem                1	
X quiz.sh                   1	
END_OF_MANIFEST
if test 264 -ne `wc -c <MANIFEST`; then
    echo shar: \"MANIFEST\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(1177 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X# A simple (?) makefile for menu quiz.
X# prerequisites for this to work are:
X# a) Korn shell is present
X# b) insult is present in /usr/games
X#    (if not edit the appropriate lines in menusystem)
X# c) your system allows filenames of arbitrary (eh, well, at least 40
X#    characters) length with embedded spaces and arbitrary other
X#    characters (Berkeley?).
X# You might get it working (with huge modifications) if some (or all)
X# of the preriquisites are not met.  Anyhow, if you do that, this
X# makefile (and the associated files) become null and void.
X#
X# change the following define to get at the destination:
XDEST = /usr/games
X# the following defines the destination of the subfiles (directory):
XDESTLIB = ${DEST}/lib
X# the following define gives the place of the Korn shell:
XKSH = /usr/local/ksh
X
X# the - in front of the test is a kludge because the Bourne shell
X# terminates if the test is false!
Xall:
X	-if test ! -d ${DESTLIB} ; then mkdir ${DESTLIB} ; fi
X	echo ${KSH} -c "'${DESTLIB}/menusystem ${DESTLIB}/Quiz'" >${DEST}/quizm
X	chmod +x ${DEST}/quizm
X	-if test '${DESTLIB}' != `pwd` ; then cp menusystem ${DESTLIB} ; fi
X	SRC=`pwd` ; cd ${DESTLIB} ; sh $$SRC/quiz.sh
END_OF_Makefile
if test 1177 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f menusystem -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"menusystem\"
else
echo shar: Extracting \"menusystem\" \(1044 characters\)
sed "s/^X//" >menusystem <<'END_OF_menusystem'
XO_PWD="$PWD"
XWD="$1"
X# if not an absolute path prepend current directory
Xcase "$WD" in
X/*)	;;
X*)	WD="$PWD/$WD"
Xesac
Xcd "$WD"
XOWD="$WD"
XTOPLEVEL=0
Xtypeset -i NUM
X# different from trap "" and no trap
Xtrap true 2 19
Xtrap "echo Bye bye ....." 0
Xulimit -c 0
Xwhile true
Xdo
X	NUM=`ls | wc -l | sed 's/ *//'`+1+$TOPLEVEL
X	NPS3="(choose a number from 1 to $NUM or enter RETURN for list) : "
X	if test -f .heading
X	then
X		. .heading
X	else
X		echo Make your choice:
X	fi
X	PS3="? "
X	game=
X	AUX="(stop)"
X	if test $TOPLEVEL = 1
X	then
X		AUX="(return) $AUX"
X	fi
X	select game in * $AUX
X	do
X		if test "$game" != ""
X		then
X			break
X		fi
X		echo
X		if test "$PS3" = "? "
X		then
X			echo Will you PLEASE follow instructions?
X		else
X			/usr/games/insult
X		fi
X		echo
X		PS3="$NPS3"
X	done
X	if test "$game" = "(stop)"
X	then
X		break
X	elif test "$game" = "(return)"
X	then
X		cd ..
X		WD="$PWD"
X		if test "$WD" = "$OWD"
X		then
X			TOPLEVEL=0
X		fi
X	elif test -d "$game"
X	then
X		cd "$game"
X		WD="$WD"/"$game"
X		TOPLEVEL=1
X	else
X		cd $O_PWD
X		. "$WD"/"$game"
X		echo
X		cd "$WD"
X	fi
Xdone
END_OF_menusystem
if test 1044 -ne `wc -c <menusystem`; then
    echo shar: \"menusystem\" unpacked with wrong size!
fi
chmod +x menusystem
# end of overwriting check
fi
if test -f quiz.sh -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"quiz.sh\"
else
echo shar: Extracting \"quiz.sh\" \(10251 characters\)
sed "s/^X//" >quiz.sh <<'END_OF_quiz.sh'
X#! /bin/sh
X# This is a shell archive, meaning:
X# 1. Remove everything above the #! /bin/sh line.
X# 2. Save the resulting text in a file.
X# 3. Execute the file with /bin/sh (not csh) to create:
X#	Quiz
X# This archive created: Sat Feb 20  0:00:00 1988
Xexport PATH; PATH=/bin:/usr/bin:$PATH
Xif test ! -d 'Quiz'
Xthen
X	mkdir 'Quiz'
Xfi
Xcd 'Quiz'
Xif test ! -d 'Geography'
Xthen
X	mkdir 'Geography'
Xfi
Xcd 'Geography'
Xcat << \SHAR_EOF > 'State -> Flower'
X/usr/games/quiz state flower
XSHAR_EOF
Xcat << \SHAR_EOF > 'African state -> Capital'
X/usr/games/quiz African capital
XSHAR_EOF
Xcat << \SHAR_EOF > 'Asian state -> Capital'
X/usr/games/quiz Asian capital
XSHAR_EOF
Xcat << \SHAR_EOF > 'Capital -> State'
X/usr/games/quiz capital state
XSHAR_EOF
Xcat << \SHAR_EOF > 'Capital -> African state'
X/usr/games/quiz capital African
XSHAR_EOF
Xcat << \SHAR_EOF > 'Capital -> Asian state'
X/usr/games/quiz capital Asian
XSHAR_EOF
Xcat << \SHAR_EOF > 'State -> Capital'
X/usr/games/quiz state capital
XSHAR_EOF
Xcat << \SHAR_EOF > 'State -> Abbreviation'
X/usr/games/quiz state abbreviation
XSHAR_EOF
Xcat << \SHAR_EOF > 'American state -> Capital'
X/usr/games/quiz American capital
XSHAR_EOF
Xcat << \SHAR_EOF > 'European state -> Capital'
X/usr/games/quiz European capital
XSHAR_EOF
Xcat << \SHAR_EOF > 'Middle-Earth state -> Capital'
X/usr/games/quiz Middle-Earth capital
XSHAR_EOF
Xcat << \SHAR_EOF > 'Canadian province -> Capital'
X/usr/games/quiz province capital
XSHAR_EOF
Xcat << \SHAR_EOF > 'Abbreviation -> State'
X/usr/games/quiz abbreviation state
XSHAR_EOF
Xcat << \SHAR_EOF > 'Flower -> State'
X/usr/games/quiz flower state
XSHAR_EOF
Xcat << \SHAR_EOF > '.heading'
Xecho Choose the one you want:
XSHAR_EOF
Xcat << \SHAR_EOF > 'Capital -> American state'
X/usr/games/quiz capital American
XSHAR_EOF
Xcat << \SHAR_EOF > 'Capital -> European state'
X/usr/games/quiz capital European
XSHAR_EOF
Xcat << \SHAR_EOF > 'Capital -> Middle-Earth state'
X/usr/games/quiz capital Middle-Earth
XSHAR_EOF
Xcat << \SHAR_EOF > 'Capital -> Canadian province'
X/usr/games/quiz capital province
XSHAR_EOF
Xcd ..
Xcat << \SHAR_EOF > '.heading'
Xecho Which subject do you want?
XSHAR_EOF
Xif test ! -d 'History'
Xthen
X	mkdir 'History'
Xfi
Xcd 'History'
Xcat << \SHAR_EOF > 'President -> Successor'
X/usr/games/quiz president successor
XSHAR_EOF
Xcat << \SHAR_EOF > 'Inca -> Successor'
X/usr/games/quiz inca successor
XSHAR_EOF
Xcat << \SHAR_EOF > '.heading'
Xecho Choose the one you want:
XSHAR_EOF
Xcat << \SHAR_EOF > 'President -> Term'
X/usr/games/quiz president term
XSHAR_EOF
Xcat << \SHAR_EOF > 'Term -> President'
X/usr/games/quiz term president
XSHAR_EOF
Xcat << \SHAR_EOF > 'Sovereign -> Century'
X/usr/games/quiz sovereign century
XSHAR_EOF
Xcat << \SHAR_EOF > 'Sovereign -> Successor'
X/usr/games/quiz sovereign successor
XSHAR_EOF
Xcd ..
Xif test ! -d 'Mathematics'
Xthen
X	mkdir 'Mathematics'
Xfi
Xcd 'Mathematics'
Xcat << \SHAR_EOF > '.heading'
Xecho Choose the one you want:
XSHAR_EOF
Xcat << \SHAR_EOF > 'Sequence -> Name (hard)'
X/usr/games/quiz hard-sequence name
XSHAR_EOF
Xcat << \SHAR_EOF > 'Sequence -> Next element (easy)'
X/usr/games/quiz easy-sequence next
XSHAR_EOF
Xcat << \SHAR_EOF > 'Sequence -> Name (easy)'
X/usr/games/quiz easy-sequence name
XSHAR_EOF
Xcat << \SHAR_EOF > 'Sequence -> Next element (hard)'
X/usr/games/quiz hard-sequence next
XSHAR_EOF
Xcat << \SHAR_EOF > 'Arithmetic'
X/usr/games/quiz arithmetic answer
XSHAR_EOF
Xcd ..
Xif test ! -d 'Miscellaneous'
Xthen
X	mkdir 'Miscellaneous'
Xfi
Xcd 'Miscellaneous'
Xcat << \SHAR_EOF > 'Startrek'
X/usr/games/quiz star trek
XSHAR_EOF
Xcat << \SHAR_EOF > '.heading'
Xecho Choose the one you want:
XSHAR_EOF
Xcat << \SHAR_EOF > 'Clear -> Morse'
X/usr/games/quiz clear morse
XSHAR_EOF
Xcat << \SHAR_EOF > 'Morse -> Clear'
X/usr/games/quiz morse clear
XSHAR_EOF
Xcat << \SHAR_EOF > 'Chinese year -> Next'
X/usr/games/quiz year next
XSHAR_EOF
Xcat << \SHAR_EOF > 'Function -> ed-command'
X/usr/games/quiz function ed-command
XSHAR_EOF
Xcat << \SHAR_EOF > 'Victim -> Killer'
X/usr/games/quiz victim killer
XSHAR_EOF
Xcat << \SHAR_EOF > 'Killer -> Victim'
X/usr/games/quiz killer victim
XSHAR_EOF
Xcat << \SHAR_EOF > 'Locomotive model -> Name'
X/usr/games/quiz locomotive name
XSHAR_EOF
Xcat << \SHAR_EOF > 'Locomotive name -> Model'
X/usr/games/quiz name locomotive
XSHAR_EOF
Xcat << \SHAR_EOF > 'Description -> Law-section'
X/usr/games/quiz ucc section
XSHAR_EOF
Xcd ..
Xif test ! -d 'Chemistry'
Xthen
X	mkdir 'Chemistry'
Xfi
Xcd 'Chemistry'
Xcat << \SHAR_EOF > 'Symbol -> Element'
X/usr/games/quiz symbol element
XSHAR_EOF
Xcat << \SHAR_EOF > 'Element -> Weight'
X/usr/games/quiz element weight
XSHAR_EOF
Xcat << \SHAR_EOF > 'Number -> Symbol'
X/usr/games/quiz number symbol
XSHAR_EOF
Xcat << \SHAR_EOF > '.heading'
Xecho Choose the one you want:
XSHAR_EOF
Xcat << \SHAR_EOF > 'Symbol -> Number'
X/usr/games/quiz symbol number
XSHAR_EOF
Xcat << \SHAR_EOF > 'Symbol -> Weight'
X/usr/games/quiz symbol weight
XSHAR_EOF
Xcat << \SHAR_EOF > 'Element -> Number'
X/usr/games/quiz element number
XSHAR_EOF
Xcat << \SHAR_EOF > 'Element -> Symbol'
X/usr/games/quiz element symbol
XSHAR_EOF
Xcat << \SHAR_EOF > 'Number -> Element'
X/usr/games/quiz number element
XSHAR_EOF
Xcd ..
Xif test ! -d 'Language'
Xthen
X	mkdir 'Language'
Xfi
Xcd 'Language'
Xcat << \SHAR_EOF > '.heading'
Xecho Choose the one you want:
XSHAR_EOF
Xcat << \SHAR_EOF > 'Greek -> English'
X/usr/games/quiz greek english
XSHAR_EOF
Xcat << \SHAR_EOF > 'Baby -> Adult'
X/usr/games/quiz baby adult
XSHAR_EOF
Xcat << \SHAR_EOF > 'Adult -> Baby'
X/usr/games/quiz adult baby
XSHAR_EOF
Xcat << \SHAR_EOF > 'Positive -> Negative'
X/usr/games/quiz positive negative
XSHAR_EOF
Xcat << \SHAR_EOF > 'Female -> Male'
X/usr/games/quiz female male
XSHAR_EOF
Xcat << \SHAR_EOF > 'Male -> Female'
X/usr/games/quiz male female
XSHAR_EOF
Xcat << \SHAR_EOF > 'Individuals -> Collective'
X/usr/games/quiz individuals collective
XSHAR_EOF
Xcat << \SHAR_EOF > 'Latin -> English'
X/usr/games/quiz latin english
XSHAR_EOF
Xcat << \SHAR_EOF > 'English -> Greek'
X/usr/games/quiz english greek
XSHAR_EOF
Xcat << \SHAR_EOF > 'English -> Latin'
X/usr/games/quiz english latin
XSHAR_EOF
Xcat << \SHAR_EOF > 'Collective -> Individuals'
X/usr/games/quiz collective individuals
XSHAR_EOF
Xcat << \SHAR_EOF > 'Negative -> Positive'
X/usr/games/quiz negative positive
XSHAR_EOF
Xif test ! -d 'Poetry'
Xthen
X	mkdir 'Poetry'
Xfi
Xcd 'Poetry'
Xcat << \SHAR_EOF > '.heading'
Xecho Choose the one you want:
XSHAR_EOF
Xcat << \SHAR_EOF > 'Shakespeare-line -> Next'
X/usr/games/quiz Shakespeare-line next
XSHAR_EOF
Xcat << \SHAR_EOF > 'Line -> Next'
X/usr/games/quiz poemline next
XSHAR_EOF
Xcat << \SHAR_EOF > 'Shakespeare-line -> Character'
X/usr/games/quiz Shakespeare-line character
XSHAR_EOF
Xcat << \SHAR_EOF > 'Shakespeare-line -> Work'
X/usr/games/quiz Shakespeare-line work
XSHAR_EOF
Xcat << \SHAR_EOF > 'Line -> Poem'
X/usr/games/quiz poemline poem
XSHAR_EOF
Xcat << \SHAR_EOF > 'Line -> Author'
X/usr/games/quiz poemline author
XSHAR_EOF
Xcd ..
Xcd ..
Xif test ! -d 'Telecom'
Xthen
X	mkdir 'Telecom'
Xfi
Xcd 'Telecom'
Xcat << \SHAR_EOF > 'Area-code -> City'
X/usr/games/quiz area-code city
XSHAR_EOF
Xcat << \SHAR_EOF > 'Area-code -> State-region'
X/usr/games/quiz area-code state-region
XSHAR_EOF
Xcat << \SHAR_EOF > 'City -> Area-code'
X/usr/games/quiz city area-code
XSHAR_EOF
Xcat << \SHAR_EOF > 'State-region -> Area-code'
X/usr/games/quiz state-region area-code
XSHAR_EOF
Xcat << \SHAR_EOF > '.heading'
Xecho Choose the one you want:
XSHAR_EOF
Xcat << \SHAR_EOF > 'Country-code -> Country'
Xa=country-code
Xb=country
X. $WD/.quiz
XSHAR_EOF
Xcat << \SHAR_EOF > 'Country -> Country-code'
Xa=country
Xb=country-code
X. $WD/.quiz
XSHAR_EOF
Xcat << \SHAR_EOF > '.quiz'
Xecho $WD/.country:country-code:country >/tmp/$$
Xquiz -i /tmp/$$ $a $b
Xrm /tmp/$$
XSHAR_EOF
Xcat << \SHAR_EOF > '.country'
X1:USA and Canada
X20:Egypt
X212:Morocco
X213:Algeria
X216:Tunisia
X218:Libya
X220:The Gambia
X221:Senegal
X222:Mauritania
X223:Mali
X224:Guinea
X225:Ivory Coast
X226:Burkina Fasso|Upper Volta
X227:Niger
X228:Togo
X229:Benin
X230:Mauritius
X231:Liberia
X232:Sierra Leone
X233:Ghana
X234:Nigeria
X235:Chad
X236:Central African Republic
X237:Cameroon
X238:Cape Verde Islands
X239:Sao Tome and Principe Island
X240:Equatorial Guinea
X241:Gabon
X242:Congo
X243:Zaire
X244:Angola
X245:Guinea-Bissau
X247:Ascension Island
X248:Seychelles
X249:Sudan
X250:Rwanda
X251:Ethiopia
X252:Somali
X253:Djibouti
X254:Kenya
X255:Tanzania
X256:Uganda
X257:Burundi
X258:Mozambique
X260:Zambia
X261:Madagascar|Malagasy Republic
X262:Reunion
X263:Zimbabwe
X264:Namibia
X265:Malawi
X266:Lesotho
X267:Botswana
X268:Swaziland
X269:Comoros{ and Mayotte}
X27:South Africa
X297:Aruba
X298:Faeroe Islands
X299:Greenland
X30:Greece
X31:Netherlands
X32:Belgium
X33:France
X33078:Andorra
X3393:Monaco
X34:Spain
X350:Gibraltar
X351:Portugal
X352:Luxembourg
X353:Ireland
X354:Iceland
X355:Albania
X356:Malta
X357:Cyprus
X358:Finland
X359:Bulgaria
X36:Hungary
X37:German Democratic Republic
X38:Yugoslavia
X39:Italy
X39541:San Marino
X396:Vatican City
X40:Rumania
X41:Switzerland
X4175:Liechtenstein
X42:Czechoslovakia
X43:Austria
X44:United Kingdom
X45:Denmark
X46:Sweden
X47:Norway
X48:Poland
X49:Federal Republic of Germany
X501:Belize
X502:Guatemala
X503:El Salvador
X504:Honduras
X505:Nicaragua
X506:Costa Rica
X507:Panama
X508:St. Pierre et Miquelon
X509:Haiti
X51:Peru
X52:Mexico
X53:Cuba
X5399:Guantanamo Bay US Naval Base
X54:Argentina
X55:Brazil
X56:Chile
X57:Colombia
X58:Venezuela
X590:Guadeloupe
X591:Bolivia
X592:Guyana
X593:Ecuador
X594:French Guiana
X595:Paraguay
X596:St. Barthelemy, Martinique, St. Martin
X597:Surinam
X598:Uruguay
X599:Netherlands Antilles
X60:Malaysia
X61:Australia
X62:Indonesia
X63:Phillippines
X64:New Zealand
X65:Singapore
X66:Thailand
X670:Mariana Island|Saipan
X671:Guam
X672:Timor
X673:Brunei
X674:Nauru
X675:Papua New Guinea
X676:Tonga
X677:Solomon Islands
X678:Vanatu|New Hebrides
X679:Fiji
X681:Wallis and Futuna
X682:Cook Island
X683:Niue
X684:Samoa (US)
X685:West Samoa
X686:Gilbert and Ellice Islands
X687:New Caledonia
X688:Tuvalu
X689:French Polynesia
X691:Micronesia
X692:Marshall Islands
X7:Sovjet Union
X81:Japan
X82:South Korea
X84:Viet Nam
X852:Hong Kong
X853:Macao
X855:Kampuchea|Khmer Republic
X856:Lao|Laos
X86:China
X880:Bangla Desh
X886:Taiwan
X90:Turkey
X91:India
X92:Pakistan
X93:Afghanistan
X94:Sri Lanka
X95:Burma
X960:Maldive Islands
X961:Lebanon
X962:Jordan
X963:Syria
X964:Iraq
X965:Kuwait
X966:Saudi Arabia
X967:Yemen Arab Republic
X968:Oman
X969:Yemen
X971:United Arabian Republics
X972:Israel
X973:Bahrein
X974:Qatar
X976:Mongolia
X977:Nepal
X98:Iran
XSHAR_EOF
Xcd ..
Xcd ..
Xexit 0
X#	End of shell archive
END_OF_quiz.sh
if test 10251 -ne `wc -c <quiz.sh`; then
    echo shar: \"quiz.sh\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 1 archives.
    echo Now type 'sh quiz.sh'
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0