#! /bin/csh

if ($#argv == 0) then
    set tarFile = m2.tar
else if ($#argv == 1) then
    set tarFile = $1
else
    echo 'usage: maketar [filename]'
    exit 1
endif

echo Making tar file $tarFile for Modula-2 distribution
tar cvfR $tarFile tarfiles >& maketar.write
if ($status != 0) then
    echo Error creating the tar file
    exit 1
endif
echo Looking for files named in tarfiles that tar couldn\'t find
fgrep 'tar:' maketar.write
if ($status == 0) then
    echo Error writing the above files to $tarFile
    exit 1
endif

tar tvf $tarFile >& maketar.read
if ($status != 0) then
    echo Error trying to check the tar file
    exit 1
endif
awk -f awkread maketar.read > maketar.read1
diff tarfiles maketar.read1
if ($status != 0) then
    echo Error checking the tar file
    exit 1
endif
echo Tar file successfully written and verified
ls -l $tarFile
#echo Compressing tar file
#compress $tarFile
#if ($status != 0) then
#    echo Error compressing tar file
#    exit 1
#endif
#echo Tar file successfully written and compressed
#ls -l $tarFile.Z
