#! /bin/tcsh -f
#
# Test script for CSC 357 program 1, Spring 2007.
#


#
# Create output, expected-output, and diffs dirs if necessary.
#
if (! -e output) then
    mkdir output
endif

if (! -e expected-output) then
    mkdir expected-output
endif

if (! -e diffs) then
    mkdir diffs
endif

#
# Define the grep program.
#
set grep = ./sgrep

#
# Set path to timelimit function (thanks, Phil).
#
alias timelimit /home/gfisher/classes/357/bin/timelimit

#
# Set var so that files from /usr are referenced as local copies.
#
set usr_copy = /home/gfisher/usr-truncated

#
# Define the input files.
#
set in1 = inputs/von
set in2 = inputs/lectures/1.html
set in3 = /home/gfisher/classes/357/programs/1/writeup-revised.html
set in4 = inputs/lectures/1.2.html
set in5 = inputs/misc-inputs
set in6 = (inputs/lectures/1.html inputs/lectures/1.2.html)
set in7 = inputs/lectures/*.html
set in8 = $usr_copy/man/man1/*
set longpat = `cat inputs/longpat`
set longline = inputs/longline
set unreadable = inputs/unreadable
set notfound = inputs/1094388724908

#
# Zero out the scores file.
#
echo 0 > score

#
# Run the cases.  The $* argument sent to diff case is whatever is passed into
# run.csh.  At present, diff-case uses none of these args.
#
# Case 1.1
if ($1 == "-v") echo Case 1.1
timelimit 10 $grep V < $in1 > output/out1.1
diff-case.csh 1.1 out1.1 1 $*

# Case 1.2
if ($1 == "-v") echo Case 1.2
timelimit 10 $grep v < $in1 > output/out1.2
diff-case.csh 1.2 out1.2 1 $*

# Case 1.3
if ($1 == "-v") echo Case 1.3
timelimit 10 $grep x < $in1 > output/out1.3
diff-case.csh 1.3 out1.3 1 $*

# Case 1.4
if ($1 == "-v") echo Case 1.4
timelimit 10 $grep the < $in2 > output/out1.4
diff-case.csh 1.4 out1.4 1 $*

# Case 1.5
if ($1 == "-v") echo Case 1.5
timelimit 10 $grep 'the ' < $in2 > output/out1.5
diff-case.csh 1.5 out1.5 1 $*

# Case 1.6
if ($1 == "-v") echo Case 1.6
timelimit 10 $grep 'size of' < $in2 > output/out1.6
diff-case.csh 1.6 out1.6 1 $*

# Case 1.7
if ($1 == "-v") echo Case 1.7
timelimit 10 $grep 'size of' < $in3 > output/out1.7
diff-case.csh 1.7 out1.7 1 $*

# Case 1.8
if ($1 == "-v") echo Case 1.8
timelimit 10 $grep 'size of' < $in4 > output/out1.8
diff-case.csh 1.8 out1.8 1 $*

# Case 1.9
if ($1 == "-v") echo Case 1.9
timelimit 10 $grep X < $in5 > output/out1.9
diff-case.csh 1.9 out1.9 1 $*

# Case 1.10
if ($1 == "-v") echo Case 1.10
timelimit 10 $grep Y < $in5 > output/out1.10
diff-case.csh 1.10 out1.10 1 $*

# Case 1.11
if ($1 == "-v") echo Case 1.11
timelimit 10 $grep Z < $in5 > output/out1.11
diff-case.csh 1.11 out1.11 1 $*

# Case 1.12
if ($1 == "-v") echo Case 1.12
timelimit 10 $grep xxx < $in5 > output/out1.12
diff-case.csh 1.12 out1.12 1 $*

# Case 1.13
if ($1 == "-v") echo Case 1.13
timelimit 10 $grep xxxxxxx < $in5 > output/out1.13
diff-case.csh 1.13 out1.13 1 $*

# Case 1.14
if ($1 == "-v") echo Case 1.14
timelimit 10 $grep 'in the middle;' < $in5 > output/out1.14
diff-case.csh 1.14 out1.14 1 $*

# Case 1.15
if ($1 == "-v") echo Case 1.15
timelimit 10 $grep e < $in5 > output/out1.15
diff-case.csh 1.15 out1.15 1 $*

# Case 2.1
if ($1 == "-v") echo Case 2.1
timelimit 10 $grep V $in1 > output/out2.1
diff-case.csh 2.1 out2.1 1 $*

# Case 2.2
if ($1 == "-v") echo Case 2.2
timelimit 10 $grep v $in1 > output/out2.2
diff-case.csh 2.2 out2.2 1 $*

# Case 2.3
if ($1 == "-v") echo Case 2.3
timelimit 10 $grep x $in1 > output/out2.3
diff-case.csh 2.3 out2.3 1 $*

# Case 2.4
if ($1 == "-v") echo Case 2.4
timelimit 10 $grep 'the ' $in2 > output/out2.4
diff-case.csh 2.4 out2.4 1 $*

# Case 2.5
if ($1 == "-v") echo Case 2.5
timelimit 10 $grep 'This line has pattern operator characters xxx' $in5 > output/out2.5
diff-case.csh 2.5 out2.5 1 $*

# Case 3.1
if ($1 == "-v") echo Case 3.1
timelimit 10 $grep 'size of' $in6 > output/out3.1
diff-case.csh 3.1 out3.1 2 $*

# Case 3.2
if ($1 == "-v") echo Case 3.2
timelimit 10 $grep memory $in6 > output/out3.2
diff-case.csh 3.2 out3.2 2 $*

# Case 3.3
if ($1 == "-v") echo Case 3.3
timelimit 10 $grep memory $in7 > output/out3.3
diff-case.csh 3.3 out3.3 2 $*

# Case 3.4
if ($1 == "-v") echo Case 3.4
timelimit 10 $grep telephone $in8 > output/out3.4
diff-case.csh 3.4 out3.4 2 $*

# Case 3.5
if ($1 == "-v") echo Case 3.5
timelimit 10 $grep lipstick $in8 > output/out3.5
diff-case.csh 3.5 out3.5 2 $*

# Case 4.1
if ($1 == "-v") echo Case 4.1
timelimit 10 $grep -n V $in1 > output/out4.1
diff-case.csh 4.1 out4.1 1 $*

# Case 4.2
if ($1 == "-v") echo Case 4.2
timelimit 10 $grep -n V < $in1 > output/out4.2
diff-case.csh 4.2 out4.2 1 $*

# Case 4.3
if ($1 == "-v") echo Case 4.3
timelimit 10 $grep -n memory $in6 > output/out4.3
diff-case.csh 4.3 out4.3 1 $*

# Case 4.4
if ($1 == "-v") echo Case 4.4
timelimit 10 $grep -n memory $in7 > output/out4.4
diff-case.csh 4.4 out4.4 1 $*

# Case 4.5
if ($1 == "-v") echo Case 4.5
timelimit 10 $grep -n telephone $in8 > output/out4.5
diff-case.csh 4.5 out4.5 1 $*

# Case 5.1
if ($1 == "-v") echo Case 5.1
timelimit 10 $grep line $in5 > output/out5.1
diff-case.csh 5.1 out5.1 1 $*

# Case 5.2
if ($1 == "-v") echo Case 5.2
timelimit 10 $grep lINe $in5 > output/out5.2
diff-case.csh 5.2 out5.2 1 $*

# Case 5.3
if ($1 == "-v") echo Case 5.3
timelimit 10 $grep -i line $in5 > output/out5.3
diff-case.csh 5.3 out5.3 1 $*

# Case 5.4
if ($1 == "-v") echo Case 5.4
timelimit 10 $grep -i LINE $in5 > output/out5.4
diff-case.csh 5.4 out5.4 1 $*

# Case 5.5
if ($1 == "-v") echo Case 5.5
timelimit 10 $grep LINE $in5 > output/out5.5
diff-case.csh 5.5 out5.5 1 $*

# Case 6.1
if ($1 == "-v") echo Case 6.1
timelimit 10 $grep -l V $in1 > output/out6.1
diff-case.csh 6.1 out6.1 1 $*

# Case 6.2
if ($1 == "-v") echo Case 6.2
timelimit 10 $grep V $in6 > output/out6.2
diff-case.csh 6.2 out6.2 1 $*

# Case 6.3
if ($1 == "-v") echo Case 6.3
timelimit 10 $grep V $in7 > output/out6.3
diff-case.csh 6.3 out6.3 1 $*

# Case 6.4
if ($1 == "-v") echo Case 6.4
timelimit 10 $grep -l telephone $in8 > output/out6.4
diff-case.csh 6.4 out6.4 1 $*

# Case 6.5
if ($1 == "-v") echo Case 6.5
timelimit 10 $grep -l -n telephone $in8 > output/out6.5
diff-case.csh 6.5 out6.5 1 $*

# Case 7.1
if ($1 == "-v") echo Case 7.1
timelimit 10 $grep '^X' $in5 > output/out7.1
diff-case.csh 7.1 out7.1 1 $*

# Case 7.2
if ($1 == "-v") echo Case 7.2
timelimit 10 $grep '^line' $in5 > output/out7.2
diff-case.csh 7.2 out7.2 1 $*

# Case 7.3
if ($1 == "-v") echo Case 7.3
timelimit 10 $grep '^This line has a Y character' $in5 > output/out7.3
diff-case.csh 7.3 out7.3 1 $*

# Case 7.4
if ($1 == "-v") echo Case 7.4
timelimit 10 $grep '^This line has a Y characterx' $in5 > output/out7.4
diff-case.csh 7.4 out7.4 1 $*

# Case 7.5
if ($1 == "-v") echo Case 7.5
timelimit 10 $grep ' X' $in5 > output/out7.5
diff-case.csh 7.5 out7.5 1 $*

# Case 8.1
if ($1 == "-v") echo Case 8.1
timelimit 10 $grep 'Z$' $in5 > output/out8.1
diff-case.csh 8.1 out8.1 1 $*

# Case 8.2
if ($1 == "-v") echo Case 8.2
timelimit 10 $grep 'line$' $in5 > output/out8.2
diff-case.csh 8.2 out8.2 1 $*

# Case 8.3
if ($1 == "-v") echo Case 8.3
timelimit 10 $grep 'This line has a Y character$' $in5 > output/out8.3
diff-case.csh 8.3 out8.3 1 $*

# Case 8.4
if ($1 == "-v") echo Case 8.4
timelimit 10 $grep 'This line has a Y characterx$' $in5 > output/out8.4
diff-case.csh 8.4 out8.4 1 $*

# Case 8.5
if ($1 == "-v") echo Case 8.5
timelimit 10 $grep 'Z $' $in5 > output/out8.5
diff-case.csh 8.5 out8.5 1 $*

# Case 8.6
if ($1 == "-v") echo Case 8.6
timelimit 10 $grep 'xxx' $in5 > output/out8.6
diff-case.csh 8.6 out8.6 1 $*

# Case 8.7
if ($1 == "-v") echo Case 8.7
timelimit 10 $grep '^xxx' $in5 > output/out8.7
diff-case.csh 8.7 out8.7 1 $*

# Case 8.8
if ($1 == "-v") echo Case 8.8
timelimit 10 $grep 'xxx$' $in5 > output/out8.8
diff-case.csh 8.8 out8.8 1 $*

# Case 9.1
if ($1 == "-v") echo Case 9.1
timelimit 10 $grep 't.e' $in1 > output/out9.1
diff-case.csh 9.1 out9.1 1 $*

# Case 9.2
if ($1 == "-v") echo Case 9.2
timelimit 10 $grep 'Y.' $in5 > output/out9.2
diff-case.csh 9.2 out9.2 1 $*

# Case 9.3
if ($1 == "-v") echo Case 9.3
timelimit 10 $grep 'Y.c' $in5 > output/out9.3
diff-case.csh 9.3 out9.3 1 $*

# Case 9.4
if ($1 == "-v") echo Case 9.4
timelimit 10 $grep 'a.Y' $in5 > output/out9.4
diff-case.csh 9.4 out9.4 1 $*

# Case 9.5
if ($1 == "-v") echo Case 9.5
timelimit 10 $grep '<.>' $in2 > output/out9.5
diff-case.csh 9.5 out9.5 1 $*

# Case 9.6
if ($1 == "-v") echo Case 9.6
timelimit 10 $grep '<x>' $in2 > output/out9.6
diff-case.csh 9.6 out9.6 1 $*

# Case 9.7
if ($1 == "-v") echo Case 9.7
timelimit 10 $grep 'm.x' $in7 > output/out9.7
diff-case.csh 9.7 out9.7 1 $*

# Case 9.8
if ($1 == "-v") echo Case 9.8
timelimit 10 $grep 'y.y' $in8 > output/out9.8
diff-case.csh 9.8 out9.8 1 $*

# Case 10.1
if ($1 == "-v") echo Case 10.1
timelimit 10 $grep '[abc]' $in5 > output/out10.1
diff-case.csh 10.1 out10.1 2 $*

# Case 10.2
if ($1 == "-v") echo Case 10.2
timelimit 10 $grep '[qrst]' $in5 > output/out10.2
diff-case.csh 10.2 out10.2 2 $*

# Case 10.3
if ($1 == "-v") echo Case 10.3
timelimit 10 $grep '[@#%&()]' $in5 > output/out10.3
diff-case.csh 10.3 out10.3 2 $*

# Case 10.4
if ($1 == "-v") echo Case 10.4
timelimit 10 $grep '[@#%&{}\|]' $in1 > output/out10.4
diff-case.csh 10.4 out10.4 2 $*

# Case 10.5
if ($1 == "-v") echo Case 10.5
timelimit 10 $grep '[*^.$]' $in5 > output/out10.5
diff-case.csh 10.5 out10.5 2 $*

# Case 11.1
if ($1 == "-v") echo Case 11.1
timelimit 10 $grep 'x.*x' $in5 > output/out11.1
diff-case.csh 11.1 out11.1 2 $*

# Case 11.2
if ($1 == "-v") echo Case 11.2
timelimit 10 $grep '<o.*>' $in2 > output/out11.2
diff-case.csh 11.2 out11.2 2 $*

# Case 11.3
if ($1 == "-v") echo Case 11.3
timelimit 10 $grep '<ul.*>' $in2 > output/out11.3
diff-case.csh 11.3 out11.3 2 $*

# Case 11.4
if ($1 == "-v") echo Case 11.4
timelimit 10 $grep '<u.*>' $in3 > output/out11.4
diff-case.csh 11.4 out11.4 2 $*

# Case 11.5
if ($1 == "-v") echo Case 11.5
timelimit 10 $grep '<u.*>' $in7 > output/out11.5
diff-case.csh 11.5 out11.5 2 $*

# Case 11.6
if ($1 == "-v") echo Case 11.6
timelimit 10 $grep -i 'x.*x' $in5 > output/out11.6
diff-case.csh 11.6 out11.6 2 $*

# Case 12.1
if ($1 == "-v") echo Case 12.1
timelimit 10 $grep -n '<[ou].*>' $in2 > output/out12.1
diff-case.csh 12.1 out12.1 2 $*

# Case 12.2
if ($1 == "-v") echo Case 12.2
timelimit 10 $grep -n '<[ou].*' $in2 > output/out12.2
diff-case.csh 12.2 out12.2 2 $*

# Case 12.3
if ($1 == "-v") echo Case 12.3
timelimit 10 $grep -n '[ou].*>' $in2 > output/out12.3
diff-case.csh 12.3 out12.3 2 $*

# Case 12.4
if ($1 == "-v") echo Case 12.4
timelimit 10 $grep -n '<[ou].*l>' $in7 > output/out12.4
diff-case.csh 12.4 out12.4 2 $*

# Case 13.1
if ($1 == "-v") echo Case 13.1
timelimit 10 $grep $longpat $in1 >& output/out13.1
diff-case.csh 13.1 out13.1 1 $*

# Case 13.2
if ($1 == "-v") echo Case 13.2
timelimit 10 $grep x $longline >& output/out13.2
diff-case.csh 13.2 out13.2 1 $*

# Case 13.3
if ($1 == "-v") echo Case 13.3
timelimit 10 sgrep x inputs/unreadable >& output/out13.3
diff-case.csh 13.3 out13.3 1 $*

# Case 13.4
if ($1 == "-v") echo Case 13.4
timelimit 10 $grep x $notfound >& output/out13.4
diff-case.csh 13.4 out13.4 1 $*

#
# Print score.
#
echo ""
echo "Score: " `cat score`/100
echo ""
