#!/bin/sh
# $Id: index_builder,v 1.4 2001/10/31 17:16:48 philippe Exp $
# Generate an index out of a given set of .naat
# - The first argument is the directory containing the .naat file to process
exec 1>index.log  2>&1

TEMP="tmp"
#XSL_COMPILER=xsl-c
XSL_COMPILER=xsltproc
XSL_COMPILER_OPTIONS=--timing
[ -d $TEMP ] || mkdir -p $TEMP

if [ -z $1 ]; then
echo "usage: index_builder <naat directory> <result file> <OPTIONS>";
exit 1;
fi

DESTDIR=""
OPT=
if [ "${XSL_COMPILER}" = "xsltproc" ]; then
[ -z $2 ] || DESTDIR="$2";
[ -z $3 ] || OPT="--param $3 $4";
else
[ -z $2 ] || DESTDIR="-OUT $2";
[ -z $3 ] || OPT="-PARAM $3 $4";
fi

# 1. create an index.xml containing only the "Wizard" tags of all the wizards in the directory. The file has the form 
#    <Index>
#      <Wizard name="name1" group="group1"/>
#      <Wizard name="name2" group="group2"/>
#      ... ...
#    </Index>
#
#    The extract.xsl stylesheet is used to select only the Wizard tags
 
#cat <<EOF > $TEMP/index.xml
#<?xml version="1.0"?>
#<Index>
#EOF

#for i in `find $1 -name "*.naat" |sort` 
#do
#	${XSL_COMPILER} -IN $i -XSL xsl/extract.xsl $OPT
#done >> $TEMP/index.xml

#echo "</Index>" >> $TEMP/index.xml

# 2. Apply  the groups.xsl stylesheet to transform index.xml in a file of this form:
#    <Index>
#       <Group>group1
#          <Group name="localisation1">name 1</Group>
#       </Group>
#       <Group>group2
#          <Group name="localisation3">name 3</Group>
#    </Index>
     
#${XSL_COMPILER} -IN $TEMP/index.xml -XSL xsl/group.xsl  $OPT > $TEMP/temporary

# 3. Apply hierarchy.xsl to obtain the final file where
#    tags appartaining to the same group are under the same tag.
#${XSL_COMPILER} -IN $TEMP/temporary  -XSL xsl/hierarchy.xsl $DESTDIR $OPT

# . New stuff for table summary
# uncomment all previous XSL_compiler stuff
#${XSL_COMPILER} -IN $1/index.frontend.xml  -XSL xsl/index-group.xsl $DESTDIR $OPT
if [ "${XSL_COMPILER}" = "xsltproc" ]; then
#echo ${XSL_COMPILER}  $OPT xsl/index.xsl $1/index.frontend.xml '>' $DESTDIR;
${XSL_COMPILER} ${XSL_COMPILER_OPTIONS} $OPT xsl/index.xsl $1/index.frontend.xml > $DESTDIR;
else
#echo ${XSL_COMPILER} -IN $1/index.frontend.xml  -XSL xsl/index.xsl $DESTDIR $OPT;
${XSL_COMPILER} -IN $1/index.frontend.xml  -XSL xsl/index.xsl $DESTDIR $OPT;
fi

# End script
