#! /bin/sh
#
# This takes the results from a summary file generated by testall,
# figures out which configuration is best for your host, and tells
# you what options to set to get it
#
# USAGE
#	recommend [ -n ] [ -o output ] [ -y ] [ options to testall ]
# Options are:
#	-n		if no summary file exists, stop
#	-y		if no summary file exists, run testall to make one
#	-o output	the summary file is to be named output (note that
#			if it does not exist and -y is given, it will be
#			created)
#
#################################################################
# Copyright notice.						#
# This software is copyrighted (c) 1991 by Matt Bishop and the	#
# Trustees of Dartmouth College.  All rights reserved.		#
# 								#
# Author:	Matt Bishop					#
# Address:	Department of Mathematics and Computer Science	#
#	 	Dartmouth College				#
# 		Hanover, NH  03755-1831				#
# 		USA						#
# telephone:	+1 603 646 3267					#
# fax:		+1 603 646 1312					#
# internet:	Matt.Bishop@dartmouth.edu			#
# usenet:	...!decvax!dartvax!Matt.Bishop			#
#################################################################
#
# Parameters -- changing these affects how the program works
VERSION="Version GAMMA 6/31/91 Matt.Bishop@dartmouth.edu"	# version
PATH=%%TSTDIR%%:/usr/ucb:/bin:/usr/bin	# execution path
GENDATA=no				# do not run testall
SUMMARYFILE=./results/%%HOSTTYPE%%	# default name of summary file
# VARIABLES -- the program will change these
# i=					# counter in a for loop
# flag=					# argument to options
# testopt=				# options to be passed to testall
#
# process the arguments
#
for i in $*
do
	if test -n "$flag"
	then
		# process argument to previous option
		case $flag in
		o)	SUMMARYFILE="$i"; flag= ;;
		esac
	else
		# process option
		case $i in
		-n)	GENDATA=no		# do not regenrate the data
			;;
		-o)	x=`expr "$i" : '-v\(.*\)'`  # look here for the data
			if test -n "$x"
			then
				SUMMARYFILE="$x"
			else
				flag=o
			fi
			;;
		-y)	GENDATA=yes		# regenerate the data
			;;
		*)	testopt="$testopt $i"	# an option to testall
			;;
		esac
	fi
done
#
# if the Summary file does not exist,
# regenerate it ONLY if asked to
#
if test ! -r $SUMMARYFILE
then
	# do we regenerate
	if test "$GENDATA" = "yes"
	then
		# yes
		make testall 2>&1 > /dev/null
		./testall $testopt -o$SUMMARYFILE
	else
		# no -- announce failure and stop
		echo "$SUMMARYFILE does not exist -- run testall to create it"
		exit 1
	fi
fi
#
# this figures out the fastest version of encrypt(3),
# the DES library, and tells you how to compile to get it
#
sed -n '/^des.*/p' $SUMMARYFILE | awk '$8 == $9 { print $0 }' |\
						  sort +10nr | head -1 | awk '
$2 == "sys"	{
		printf "Use the system library DES function "
		printf " to get %s calls per second\n", $11;
	    }
$2 != "sys"	{
		printf "The %s-bit DES,", $2;
		if ($7 == "U")		printf " UNIX interface ";
		else if ($7 == "D")	printf " DESZIP interface ";
		else			printf " unknown interface ", $7;
		printf "gets %s calls/sec with settings:\n", $11;
		printf "\tPATH=%s\n", $3;
		printf "\tKEY=%s\n", $4;
		if ($5 == "sm")		printf "\tPACKBITS=SHIFTANDMASK\n";
		else if ($5 == "bf")	printf "\tPACKBITS=BITFIELDS\n";
		else if ($5 == "by")	printf "\tPACKBITS=BYTES\n";
		else			printf "\tPACKBITS=%s\n", $5;
		if ($6 == "of")		printf "\tCOMPSALT=ONFLY\n";
		else if ($6 == "pc")	printf "\tCOMPSALT=PRECOMPUTE\n";
		else			printf "\tCOMPSALT=%s\n", $6;
	   }'
#
# this figures out the fastest version of crypt(3),
# the UNIX password hashing library, and tells you how to compile to get it
#
sed -n '/^crypt.*/p' $SUMMARYFILE | awk '$8 == $9 { print $0 }' |\
	 					 sort +10nr | head -1 | awk '
$2 == "sys"	{
		printf "Use the system library CRYPT function "
		printf " to get %s calls per second\n", $11;
	    }
$2 != "sys"	{
		printf "The %s-bit CRYPT,", $2;
		if ($7 == "U")		printf " UNIX interface ";
		else if ($7 == "D")	printf " DESZIP interface ";
		else			printf " unknown interface ", $7;
		printf "gets %s calls/sec with settings:\n", $11;
		printf "\tPATH=%s\n", $3;
		printf "\tKEY=%s\n", $4;
		if ($5 == "sm")		printf "\tPACKBITS=SHIFTANDMASK\n";
		else if ($5 == "bf")	printf "\tPACKBITS=BITFIELDS\n";
		else if ($5 == "by")	printf "\tPACKBITS=BYTES\n";
		else			printf "\tPACKBITS=%s\n", $5;
		if ($6 == "of")		printf "\tCOMPSALT=ONFLY\n";
		else if ($6 == "pc")	printf "\tCOMPSALT=PRECOMPUTE\n";
		else			printf "\tCOMPSALT=%s\n", $6;
	   }'


