: #########################################################################
#
#	SCCS:  @(#)  wrptm.sh Rel 1.1	    (1/16/92)
#
# 	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:		wrptm.sh - script for multiple run reports		#
#									#
# PROJECT:	VSW (X/OPEN Validation Suite)				#
#									#
# AUTHOR:	Geoff Clare, UniSoft Ltd.				#
#									#
# CREATED:	13 Jan 1988						#
#									#
# MODIFICATIONS:							#
#		Geoff Clare, 13 Feb 1990				#
#			Change /bin/rm to rm				#
#		Stuart Boutell, 16 Jan 1992				#
#			Incorporated into VSW				#
#									#
#########################################################################

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

TMPFILE=/tmp/wrptm$$

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 "$XTESTBIN" = ""
then
	XTESTBIN=$TET_ROOT/xtest/bin
fi

if test ! -d "$XTESTBIN"
then
	echo >&2 "$0: Please set either XTESTBIN or TET_ROOT - can't find awk scripts" 
	exit 1
fi

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

# produce the report

(
	echo "$HEADER
Multiple Run
$LEN
$WID


"
	(
		awk -f "$XTESTBIN"/wrptm.awk1 tmpfile="$TMPFILE" "$@" &&
		sort -k 2,3 -k 3n,4 -k 4 "$TMPFILE"
	) | awk -f "$XTESTBIN"/wrptm.awk2
) | "$XTESTBIN"/wrpt.page

rm -f "$TMPFILE"

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