#!/bin/sh

#
# sgml2S
# converts sgml documentation into a file that can be sourced
# by S to create a documentation object as a nested list of htmlTag
# objects.
# The content of the documentation object is mainly irrelevant
# as the work-horse underlying this takes a tag and its attributes
# and inserts them into the htmlTag constructor function and processes
# the body of the tag recursivel, providing this as the value(s) of 
# htmlTag() function.
#
# USAGE:
#    called as S sgml2S [-f] a.Sgml b.Sgml ....
#
#  -f   pass the value of SGML_SEARCH_PATH appended with the standard locations to 
#         docSourceGen. This may have no effect!
#  -ix  passed to docSourceGen with same effect as -ix
#
#  -wx   passed through to the docSourceGen with same effect as nsgmls
#

strict=""
args=""
files=""
verbose=""

SUFFIX="Sgml"

for i in "$@" ; do
  case $i in
       -v)   verbose="true"; shift;;
       -w*)  args="${args} ${i}"; shift;;
       -f)   LINUXDOCBIN=${LINUXDOCBIN-${SHOME}/cmd}
             LINUXDOCLIB=${LINUXDOCLIB-${SHOME}/library/documentation}
             SGML_SEARCH_PATH=${SGML_SEARCH_PATH}:$LINUXDOCLIB/dtd/:$LINUXDOCLIB/dtd/:$LINUXDOCLIB/rep/html/
             export SGML_SEARCH_PATH
              shift;;
       -i*)   args="$1 ${args}"; shift;; 
       *)   
            files="${files} ${i}";
            shift;;
     esac
done

if [ "${files}" = "" ] ; then
 echo "$0  must be called with at least on argument - the name of an sgml file"
 exit 1
fi


LINUXDOCBIN=${LINUXDOCBIN-${SHOME}/cmd}
LINUXDOCLIB=${LINUXDOCLIB-${SHOME}/library/documentation}

SGML_SEARCH_PATH=${SGML_SEARCH_PATH}:$LINUXDOCLIB/dtd/:
export SGML_SEARCH_PATH


LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${SHOME}/lib
export LD_LIBRARY_PATH

for f in  ${files} ; do
    DIR=`dirname "$f"`
    out="${DIR}/`basename "$f" .${SUFFIX}`"
    if  [ "${verbose}" != "" ] ; then
      echo "Writing output for $f to ${out}.Sdoc"
    fi
    $SHOME/cmd/docSourceGen $args $f > ${out}.Sdoc
#    echo $?
done
