#!/bin/csh -f

switch (`uname -s``uname -r`)
case SunOS5*:
	breaksw
case Linux2*:
	breaksw
default:
	exec echo ${0}: does not run on `uname -s` `uname -r`
endsw

while($#argv)
	switch ("$1")
	case -d:
		set DEBUG
#		shift
#		breaksw
# fall through to verbose
	case -v:
		set VERBOSE
		shift
		breaksw
	default:
		set DQ = '"'
		exec echo ${0}: "What do I do with $DQ$1$DQ?"
	endsw
end

# Some newer versions of head and tail do not take simple "-<n>"
# options.  This script determines which require a new form and
# demonstrate that.

@ PRINTED = 0
foreach DIR ( $path )
	set TESTS
	if ( -e $DIR/head ) set TESTS = ( $TESTS $DIR/head )
	if ( -e $DIR/tail ) set TESTS = ( $TESTS $DIR/tail )
	if ( "$TESTS" == "") then
	   continue
	endif
	foreach TEST ( $TESTS )
		unset PRINT
		@ WORKED = 0

		set RESULT = "`echo test | $TEST -1 |& grep .`"
		if ("$RESULT" == "test") then
		   if ($?VERBOSE) then
		   	echo "$TEST works with -<n>"
			set PRINT
		   endif
		   @ WORKED += 1
		else
		   echo "$TEST does not work with -<n>"
		   set PRINT
		endif

		set RESULT = "`echo test | $TEST +1 |& grep .`"
		if ("$RESULT" == "test") then
		   if ($?PRINT) echo "$TEST works with +<n>"
		   @ WORKED += 1
		endif

		set RESULT = "`echo test | $TEST -n1 |& grep .`"
		if ("$RESULT" == "test") then
		   if ($?PRINT) echo "$TEST works with -n<n>"
		   @ WORKED += 1
		endif

		set RESULT = "`echo test | $TEST -n+1 |& grep .`"
		if ("$RESULT" == "test") then
		   if ($?PRINT) echo "$TEST works with -n+<n>"
		   @ WORKED += 1
		endif

		set RESULT = "`echo test | $TEST --lines=1 |& grep .`"
		if ("$RESULT" == "test") then
		   if ($?PRINT) echo "$TEST works with --lines=<n>"
		   @ PRINTED += 1
		endif

		set RESULT = "`echo test | $TEST --lines=+1 |& grep .`"
		if ("$RESULT" == "test") then
		   if ($?PRINT) echo "$TEST works with --lines=+<n>"
		   @ PRINTED += 1
		endif

		if (! $WORKED) then
		   echo Nothing seems to work for $TEST
		endif
	end
	
end
