#!/bin/sh

abspath () {
    readlink -f "$1"
}

dstDir=`dirname $0`

srcDir=`abspath $dstDir/../docbook5`

sed -r -e 's^\{db5\}^{db51}^g' \
    -e 's^filterDuplicateIDs="true"^filterDuplicateIDs="false"^' \
    -e '/<.copyDocument>/a\
\
      <invoke method="com.xmlmind.xmleditext.assembly.TransclusionProcessor.process">\
        <argument>-v</argument>\
        <argument>__doc.xml</argument>\
      </invoke>' \
    $srcDir/docbook5_convert_input.incl > $dstDir/docbook51_convert_input.incl

sed -r -e 's^\{db5\}^{db51}^g' \
    -e 's^db5\.^db51.^g' \
    -e 's^"@xsl/^"@docbook5-config:xsl/^g' \
    -e 's^"xsl/^"docbook5-config:xsl/^g' \
    $srcDir/docbook5_convert_menu.incl > $dstDir/docbook51_convert_menu.incl

sed -r -e 's^\{db5\}^{asm}^g' \
    -e 's^db5\.^asm.^g' \
    -e 's^"@xsl/^"@docbook5-config:xsl/^g' \
    -e 's^"xsl/^"docbook5-config:xsl/^g' \
    -e 's^"_DocBook"^"_Assembly"^g' \
    -e 's^\|svg\|webp"^webp"^g' \
    -e 's^\|svg"^"^g' \
    -e 's^\|eps\|epsf\|epsi"^eps"^g' \
    -e 's^\|pdf"^pdf"^g' \
    -e '/<command name="selectConvertedFile"/ i\
        <command name="XXE.save" parameter="[checkIsSaved]" />' \
    $srcDir/docbook5_convert_menu.incl > $dstDir/assembly_convert_menu.incl

echo '*** NOW MOVE BY HAND <get expression="if(contains(system-property(...> AFTER <command name=XXE.save parameter=[checkIsSaved]> in assembly_convert_menu.incl ***'
echo '*** Also remove false comment "parameters here are:..." from assembly_convert_menu.incl ***'
