: #######################################################################
#									#
#	SCCS:	@(#)common/vrpt/vrptm.sh	4.1 (01/21/97)  VSXgen release 1.4#
#									#
#	UniSoft Ltd., London, England
#									#
# (C) Copyright 1991 X/Open Company Limited
#
# All rights reserved.  No part of this source code may be reproduced,
# stored in a retrieval system, or transmitted, in any form or by any
# means, electronic, mechanical, photocopying, recording or otherwise,
# except as stated in the end-user licence agreement, without the prior
# permission of the copyright owners.
#
# X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
# the UK and other countries.
#									#
#########################################################################

#########################################################################
#									#
# NAME:		vrptm.sh - script for multiple run reports		#
#									#
# PROJECT:	VSX (X/OPEN Validation Suite)				#
#									#
# AUTHOR:	Geoff Clare, UniSoft Ltd.				#
#									#
# CREATED:	13 Jan 1988						#
#									#
# MODIFICATIONS:							#
#		Geoff Clare, 13 Feb 1990				#
#			Change /bin/rm to rm				#
#									#
#########################################################################

USAGE="usage: $0 [-H] [-Llen] [-Wwid] file1 file2 ..."

TMPFILE=/tmp/vrptm$$

HEADER=YES
LEN=66
WID=80

# Get command line options

while test $# -gt 0
do
	case $1 in
	-H)	HEADER=NO
		;;
	-L)
		if test $# -gt 1
		then
			shift
			LEN="$1"
		else
			echo >&2 "$USAGE"
			exit 1
		fi
		;;
	-L*)
		LEN=`expr "$1" : "-L\(.*\)"`
		;;
	-W)
		if test $# -gt 1
		then
			shift
			WID="$1"
		else
			echo >&2 "$USAGE"
			exit 1
		fi
		;;
	-W*)
		WID=`expr "$1" : "-W\(.*\)"`
		;;
	-*)
		echo >&2 "$USAGE"
		exit 1
		;;
	*)
		break
		;;
	esac
	shift
done

if test $# -lt 2
then
	echo >&2 "$USAGE"
	exit 1
fi

# Check input files are readable

OK=Y
for file
do
	if test ! -r "$file"
	then
		echo >&2 "$0: cannot read input file \"$file\""
		OK=N
	fi
done

if test "$OK" = N
then
	exit 2
fi

# Validate page length and width

if test "$LEN" -lt 20
then
	LEN=66
fi

MINWID=`expr $# \* 15 + 4`
if test "$WID" -lt "$MINWID"
then
	WID="$MINWID"
	echo >&2 "$0: insufficient page width for number of files - using $WID"
fi

# Where to find awk scripts and pager

if test "$VSXBIN" = ""
then
	VSXBIN=$HOME/BIN
fi

trap "rm -f $TMPFILE; exit 1" 1 2 3 15

# produce the report

(
	echo "$HEADER
Multiple Run
$LEN
$WID



"
	(
		awk -f "$VSXBIN"/vrptm.awk1 tmpfile="$TMPFILE" "$@" &&
		sort +1 -2 +2n -3 +3 "$TMPFILE"
	) | awk -f "$VSXBIN"/vrptm.awk2
) | "$VSXBIN"/vrpt.page

rm -f "$TMPFILE"

stat=$?
if test $stat -eq 0
then
	exit 0
else
	exit 2
fi
