#!/bin/bash
# Copyright 2006-2008 The FLWOR Foundation.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
# http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if test $# != 2; then
  echo 'Args: submissionid1 submissionid2'
  echo 'Identify submissionids from dashboard test result links'
  exit 1
fi

URL='http://fifthelement.inf.ethz.ch:8082/zorba/Dashboard/TestCatalog?submissionid='
SAXON=`dirname $0`/zorbatest/xquery
test -f $SAXON || { echo 'xquery script not present'; echo 'run setup_framework in test/zorbatest'; exit 1; }

q=`mktemp /tmp/ctr.XXXXXX`
cat > $q <<"EOF"
declare default element namespace "http://www.w3.org/1999/xhtml";
declare option saxon:output "omit-xml-declaration=yes";
string-join (fn:data (//td [@class eq "warning"]/a/@href), "
")
EOF

f1=`mktemp /tmp/ctr.XXXXXX`

wget "$URL""$1" -O - | sed -e's/\&nbsp;/ /g;s/\&/\&amp;/g' | tidy -q -asxml 2>/dev/null | $SAXON -s - $q | sort | cut -f6- -d'.' | cut -f1 -d'&' >$f1
wget "$URL""$2" -O - | sed -e's/\&nbsp;/ /g;s/\&/\&amp;/g' | tidy -q -asxml 2>/dev/null | $SAXON -s - $q | sort | cut -f6- -d'.' | cut -f1 -d'&' | diff -U0 $f1 - | tail -n +3 | egrep -v '^@' | perl -pe 's#[.]#/#g'

rm -f $f1 $q
