:
# NAME:
#	regress - run regression tests
#
# SYNOPSIS:
#	regress "repository" "file" ...
#	
# DESCRIPTION:
#	This script makes it easy to implement CVS pre-commit checks.
#	It locates the "file" being committed and looks from its
#	directory up towards the root processing any regress.d
#	directories found along the way.
#
# SEE ALSO:
#	rc.sh(8).
#
# AUTHOR:
#	Simon J. Gerraty <sjg@crufty.net>

# RCSid:
#	$Id: regress,v 1.8 2023/06/11 06:22:06 sjg Exp $
#
#	@(#) Copyright (c) 1997-2022 Simon J. Gerraty.
#
#	This file is provided in the hope that it will
#	be of use.  There is absolutely NO WARRANTY.
#	Permission to copy, redistribute or otherwise
#	use this file is hereby granted provided that 
#	the above copyright notice and this notice are
#	left intact. 
#      
#	Please send copies of changes and bug-fixes to:
#	sjg@crufty.net
#

Myname=regress
Mydir=`dirname $0`
PATH=$Mydir:`cd $Mydir/../bin; pwd`:$PATH:${RC_D:-/etc/rc_d}
. debug.sh

DebugOn setup

echo "$Myname: checking $*"
PWD=${PWD:-`pwd`}
REGRESS_D=${REGRESS_D:-$Myname.d}
RC_SH=${RC_SH:-/etc/rc.sh}

export PATH PWD

check() {
        if [ -d $1 ]; then
                rd=`cd $1; pwd`
                shift
                case ",$Checked," in
		*,$rd,*) ;;
		*)	Checked="$Checked,$rd"
                        $RC_SH -N $Myname -e -d $rd -c S "$@" || exit 1
                        ;;
		esac
	fi
}

check $Mydir/$REGRESS_D "$@"
check $Mydir/../$REGRESS_D "$@"

# if $PWD/$2 is not a directory then $2 must name a file in $PWD.
# so we assume we were called by cvs.
if [ ! -d $PWD/$2 ]; then
        d=`dirname $PWD/$2`
else
	d=$PWD
fi

while :
do
        case "$d" in
	*/?*)
                check $d/$REGRESS_D "$@"
		d=`dirname $d`
		;;
	*)	break;;
	esac
done
