#!/bin/sh
# Shell script that runs the backward compatibility filter on a MoML file

# Author:  Christopher Hylands
# Version: $Id: updatemoml 21300 2002-03-27 03:53:10Z cxh $
#
# Copyright (c) 1999-2002 The Regents of the University of California.
# 	All Rights Reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in all
# copies of this software.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
# FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
# THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
# PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
# CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
# ENHANCEMENTS, OR MODIFICATIONS.
#
# 						PT_COPYRIGHT_VERSION_2
# 						COPYRIGHTENDKEY


# This script reads in one or more MoML files, filters each file
# and writes the results out
# Usage: updatemoml [-n] moml.xml [file2.xml . . .]
# -n means print the diffs only, do not update the original file

#
#  cd $PTII
#  $PTII/adm/bin/ptIItxtfiles | egrep '.xml$' > /tmp/x
# Remove the .xml files that declare libraries
#  grep -v 'lib/[a-z][^/]*.xml' /tmp/x > /tmp/x2
# updatemoml `cat /tmp/x2

PTII=` echo "$PTII" | sed 's@\\\@/@'`
UPDATEMOMLFILE="$PTII/adm/bin/updateMoMLFile.tcl"


printonly=no
if [ "$1" = "-n" ]; then
    printonly=yes
    shift
fi

for file in $@
do
    if [ ! -f $file ]; then
	echo "$0: $file does not exist"
	continue
    fi
    grep 'EntityLibrary' $file
    retval=$?
    if [ "$retval" = "0" ]; then
	echo "$0: $file contains EntityLibrary, skipping"
	continue
    fi
    $PTII/bin/ptjacl "$UPDATEMOMLFILE" "$file"
    if [ ! -f updateMoMLFiles.xml ]; then
	echo "$0: $file: error: updateMoMLFiles.xml not found"
    else
	echo "diff $file updateMoMLFiles.xml" 
	diff $file updateMoMLFiles.xml 
	retval=$?
	if [ "$retval" = "1" ]; then
	    if [ "$printonly" = "no" ]; then
		echo "Updating $file"
		cp updateMoMLFiles.xml $file
	    else
		echo "Would update $file"
	    fi
	else    
	    echo "No differences, so no update"
	fi    
    fi	
done
