#!/bin/bash
# SZARP: SCADA software 
# 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

#  2003 Pawe Paucha PRATERM S.A pawel@praterm.com.pl

# $Id: ipk_normal_draws 4393 2007-09-13 16:37:10Z reksio $

# Skrypt normalizuje atrybuty prior w pliku.
# Parametry:
#	- nazwa pliku z konfiguracj (jeli nie ma, przyjmowane jest
#	standardowe wejcie)

. `dirname $0`/ipk_config

function Usage() {
	echo -e "\
Usage:\n\
 ipk_normal_draws [ <config_file> ]\n\
or\n\
 ipk_normal_draws -h | --help \n\
Normalize prior attributes of IPK 'draw' elements.\n\
\n\
	-h, --help	print help and exit\n\
	<config_file>	path to configuration file, standard input is used if\n\
			none is given\n\
\n\
Return code is 0 on success and 1 on error (if configuration doesn't validate\n\
against IPK schema). If prior is like X.Y it is transformed to 1.Y, if it is\n\
like X (without fractional part), it is transformed to 1.X. Transformed\n\
configuration file is printed on standard output."
	exit 1;
}

if [ "x$1" = "x-h" -o "x$1" = "x--help" ] ; then
	Usage
fi

[ $# -gt 1 ] && Usage

if [ $# -eq 0 ] ; then
	INPUT="-"
else
	INPUT=$1
fi

TEMPLATES_DIR=$SZARP_DIR/resources/xslt

xmllint $XMLLINT_VALID_ARGS "$INPUT" \
| xsltproc $TEMPLATES_DIR/normalize_draw.xsl - \
| xmllint --format --encode ISO-8859-2 - \
| xmllint - 

