#!/bin/sh
#
# Configure --- Configure ncurses from the matrix file
#
trap "rm -f config$$; exit 0" 0 1 2 15

if [ "$1" != "" ]
then
	opsys=$1;
else
	echo "Please select an OS by number from the following:"
	echo "";

	awk -F: <matrix '
BEGIN		{count = 1}
		{print count++ ") " $3 " (" $4 ")"}
END 		{print count ") Other..."}
'
	echo "";
	echo -n "What OS do you use? "
	read choice;
	grep "^:$choice:" matrix >config$$
	opsys=`cut -f3 -d: config$$`
	echo "";
fi

if grep ":$opsys:" matrix >config$$
then
	echo "Configuring ncurses..."
	awk -F: -f script.src <config$$
	awk -F: -f script.test  <config$$
	echo "catting Config.$opsys file and Makefile.dist to create Makefile"
	cat Config.$opsys Makefile.dist > Makefile
	echo "catting ../test/Config.$opsys file and ../test/Makefile.dist to create ../test/Makefile"
	cat ../test/Config.$opsys ../test/Makefile.dist > ../test/Makefile
else
	echo "For unsupported operating systems please consult 'README' in this directory." ;
	echo "As a first cut, do 'cat Config Makefile.dist >Makefile' and then type 'make'."
fi
