#!/bin/csh -f
##############################################################################
#
# Name:
#
#    testSaxParser.csh
#
# Purpose:
#
#    Used to wrap the test_SAX_parser binary, and do output differencing
#
# Modification History:
#
# Date       PR       Who         Reason
# ---------  -------- ----------  --------------------------------------------
# 05May2006  54226    Sontag      Initial version.
# 08Feb2006  57334    Sontag      Allow the different tag closing syntaxes
##############################################################################

# Check args
set debug = 0
if ($#argv != 1 && $#argv != 2) then
   echo "usage: `basename $0` <XML file> [-debug]"
   exit 1
endif
if ($#argv == 2) then
   if ("$argv[2]" != "-Debug" && "$argv[2]" != "-debug") then
      echo "usage: `basename $0` <XML file> [-debug]"
      exit 1
   endif
   set debug = 1
endif

set origXML  = $argv[1]
set out      = "test.$$.out"
set origCopy = `basename $origXML`.$$.copy

# Copy the orig, and remove comments, empty lines, any proc'g instruction
# (our parser currently does not handle the proc'g instr), and any namespace
# attributes (will add the handling of xmlns attrs w/ next version of ACE).
cat $origXML | grep -v '<\!\-\-' \
             | grep -v '^ *$' \
             | grep -v '^ *<?xml ' \
             | sed 's/ * xmlns:[A-Za-z]* *= *"[^"]*"//' \
             > $origCopy

# See if the XML file in question uses the short tag closing syntax
set extraArg = ""
egrep -s '/> *$' $origXML > /dev/null
if ($status == 0) then
   set extraArg = "-shortCutSyntax"
endif

# Run SAX parser and dump it to a file (also rm empty lines and xmlns attrs)
/bin/rm -f $out
test_SAX_parser $origXML $extraArg \
             | grep -v '^ *$' \
             | sed 's/ * xmlns:[A-Za-z]* *= *"[^"]*"//' \
             > $out

# Do the diff
diff -w $origCopy $out
set savestat = $status
if ($debug == 0) then
   /bin/rm -f $origCopy
   /bin/rm -f $out
endif

# Exit
if (0 != $savestat) then
   echo ""
   echo 'TEST FAILED \!'
   echo ""
   exit $savestat
endif
exit 0
