#!/usr/bin/perl
#
#NAME
#  mktest
#
#SYNOPSIS
#  mktest PPP file..
#
#DESCRIPTION
#  For  each  file,  link  the  test/sh/PPP  test into the test/prog/
#  directory with an appropriate name for the test.  We also look  in
#  the data/ directory for the data file, and move it to test/data/.
#
#  At present, we give the test name that  starts  with  'D'  plus  a
#  digit  that  is the length (digits) of the data/file's size.  This
#  will cause the smaller tests to be done first.
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>

$P = shift || die "Usage: $0 prog file..\n";

$prog = "test/sh/$P";
die "$0: No program $prog\n" unless -f $prog;

name:
for $file (@ARGV) {
	print "$file:\n";
	($ddir,$dfil) = ($file =~ /^(.*)\/(.*)$/);
	($base,$suff) = ($dfil =~ /^(.*)\.(.*)$/);
	$base = $dfil unless $base;
	(undef,undef,undef,undef,undef,undef,undef,$size) = stat($file);
	$n = length($size);
	$data = "test/data/$base.dat";
	$test = "test/prog/D${n}-$base";
	if (-f $test) {
		print STDERR "$test already exists.\n";
	} else {
		link($prog, $test);
	}
	if (-f $data) {
		print STDERR "$data already exists.\n";
	} else {
		link($file, $data);
	}
#	system "/bin/mv $file test/data/";
	$fcmd =  "find test '(' -name '*$base' -o -name '*$base.*' ')' -exec ls -lidg {} ';'";
	system $fcmd;
}
