#!/bin/sh

# This script was written by Roberto C. Sánchez and is based on code from the
# "Shorewall Release Processing" script
#
# That script is copyright as follows:
#  -- (C) 2003,2004,2005 -- Tom Eastep (teastep@shorewall.net)
#  -- (C) 2005,2006 -- Cristian Rodriguez (webmaster@shorewall.net)
#
# That script is licensed under the GPLv2
#

STYLESHEET=/usr/share/xml/docbook/stylesheet/nwalsh/xhtml/docbook.xsl

HTMFILES="6to4.htm
          blacklisting_support.htm
          configuration_file_basics.htm
          CorpNetwork.htm
          dhcp.htm
          Documentation.htm
          errata.htm
          fallback.htm
          FAQ.htm
          GnuCopyright.htm
          Install.htm
          IPIP.htm
          IPSEC.htm
          kernel.htm
          myfiles.htm
          NAT.htm
          ports.htm
          PPTP.htm
          ProxyARP.htm
          quotes.htm
          samba.htm
          shorewall_extension_scripts.htm
          shorewall_features.htm
          shorewall_mirrors.htm
          shorewall_prerequisites.htm
          shorewall_quickstart_guide.htm
          shorewall_setup_guide_fr.htm
          shorewall_setup_guide.htm
          Shorewall_sfindex_frame.htm
          standalone.htm
          starting_and_stopping_shorewall.htm
          support.htm
          three-interface.htm
          traffic_shaping.htm
          troubleshoot.htm
          two-interface.htm
          upgrade_issues.htm
          VPN.htm
          whitelisting_under_shorewall.htm"

NOTOC="Documentation_Index.xml
       ECN.xml
       fallback.xml
       GettingStarted.xml
       IPP2P.xml
       ping.xml
       ProxyARP.xml
       Shorewall_Doesnt.xml
       shorewall_features.xml
       shorewall_prerequisites.xml
       SimpleBridge.xml"

list_search() # $1 = element to search for , $2-$n = list
{
    local e=$1

    while [ $# -gt 1 ]; do
        shift
        [ "x$e" = "x$1" ] && return 0
    done

    return 1
}

mkdir html

for file in *.xml; do
    b=${file%.*}
    list_search $b.htm $HTMFILES && b=$b.htm || b=$b.html
    list_search $1 $NOTOC && GENTOC="--stringparam generate.toc ''" || GENTOC=

    case $file in
        *_ru.xml)
            LANGUAGE="--stringparam l10n.gentext.default.language ru"
            ;;
        *_fr.xml)
            LANGUAGE="--stringparam l10n.gentext.default.language fr"
            ;;
        *)
            LANGUAGE=
            ;;
    esac

    echo "Converting $file from XML to HTML (html/$b) ..."
    xsltproc --output html/$b --stringparam html.stylesheet html.css --stringparam ulink.target _self $GENTOC -param toc.section.depth 3 $STYLESHEET $file
done

cd manpages
for f in *.xml; do
    if [ $f != shorewall-template.xml ]; then
        echo "Generating HTML from $f..."
        xsltproc --output ${f%.xml}.html --stringparam html.stylesheet html.css --stringparam ulink.target _self -param toc.section.depth 3 $STYLESHEET $f
    fi
done

