#!/usr/bin/env bash
#############################################################################
##
## XML documenting files to (X)HTML conversion script
## Last updated on July 18, 2022
##
## This file is part of Logtalk
## SPDX-FileCopyrightText: 1998-2023 Paulo Moura
## SPDX-License-Identifier: Apache-2.0
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
#############################################################################
print_version() {
echo "$(basename "$0") 2.3"
exit 0
}
if ! [ "$LOGTALKHOME" ]; then
echo "The environment variable LOGTALKHOME should be defined first, pointing"
echo "to your Logtalk installation directory!"
echo "Trying the default locations for the Logtalk installation..."
if [ -d "/usr/local/share/logtalk" ]; then
LOGTALKHOME=/usr/local/share/logtalk
echo "... using Logtalk installation found at /usr/local/share/logtalk"
elif [ -d "/usr/share/logtalk" ]; then
LOGTALKHOME=/usr/share/logtalk
echo "... using Logtalk installation found at /usr/share/logtalk"
elif [ -d "/opt/local/share/logtalk" ]; then
LOGTALKHOME=/opt/local/share/logtalk
echo "... using Logtalk installation found at /opt/local/share/logtalk"
elif [ -d "/opt/share/logtalk" ]; then
LOGTALKHOME=/opt/share/logtalk
echo "... using Logtalk installation found at /opt/share/logtalk"
elif [ -d "$HOME/share/logtalk" ]; then
LOGTALKHOME="$HOME/share/logtalk"
echo "... using Logtalk installation found at $HOME/share/logtalk"
elif [ -f "$( cd "$( dirname "$0" )" && pwd )/../core/core.pl" ]; then
LOGTALKHOME="$( cd "$( dirname "$0" )" && pwd )/.."
echo "... using Logtalk installation found at $( cd "$( dirname "$0" )" && pwd )/.."
else
echo "... unable to locate Logtalk installation directory!" >&2
echo
exit 1
fi
echo
elif ! [ -d "$LOGTALKHOME" ]; then
echo "The environment variable LOGTALKHOME points to a non-existing directory!" >&2
echo "Its current value is: $LOGTALKHOME" >&2
echo "The variable must be set to your Logtalk installation directory!" >&2
echo
exit 1
fi
export LOGTALKHOME
if ! [ "$LOGTALKUSER" ]; then
echo "The environment variable LOGTALKUSER should be defined first, pointing"
echo "to your Logtalk user directory!"
echo "Trying the default location for the Logtalk user directory..."
export LOGTALKUSER=$HOME/logtalk
if [ -d "$LOGTALKUSER" ]; then
echo "... using Logtalk user directory found at $LOGTALKUSER"
else
echo "... Logtalk user directory not found at default location. Creating a new"
echo "Logtalk user directory by running the \"logtalk_user_setup\" shell script:"
logtalk_user_setup
fi
elif ! [ -d "$LOGTALKUSER" ]; then
echo "Cannot find \$LOGTALKUSER directory! Creating a new Logtalk user directory"
echo "by running the \"logtalk_user_setup\" shell script:"
logtalk_user_setup
fi
echo
html_entity_xslt="$LOGTALKUSER/tools/lgtdoc/xml/logtalk_entity_to_html.xsl"
xhtml_entity_xslt="$LOGTALKUSER/tools/lgtdoc/xml/logtalk_entity_to_xhtml.xsl"
html_index_xslt="$LOGTALKUSER/tools/lgtdoc/xml/logtalk_index_to_html.xsl"
xhtml_index_xslt="$LOGTALKUSER/tools/lgtdoc/xml/logtalk_index_to_xhtml.xsl"
format=xhtml
directory="."
index_file=index.html
index_title="Documentation index"
processor=xsltproc
# processor=xalan
# processor=saxon
usage_help()
{
echo
echo "This script converts all Logtalk XML files documenting files in the"
echo "current directory to XHTML or HTML files"
echo
echo "Usage:"
echo " $(basename "$0") [-f format] [-d directory] [-i index] [-t title] [-p processor]"
echo " $(basename "$0") -v"
echo " $(basename "$0") -h"
echo
echo "Optional arguments:"
echo " -f output file format (either xhtml or html; default is $format)"
echo " -d output directory for the generated files (default is $directory)"
echo " -i name of the index file (default is $index_file)"
echo " -t title to be used in the index file (default is $index_title)"
echo " -p XSLT processor (xsltproc, xalan, or saxon; default is $processor)"
echo " -v print version"
echo " -h help"
echo
}
create_index_file()
{
echo "" > "$index_file"
case "$format" in
xhtml)
echo "" >> "$index_file"
echo "" >> "$index_file"
echo "" >> "$index_file"
echo "" >> "$index_file"
;;
html)
echo "" >> "$index_file"
echo "" >> "$index_file"
;;
esac
echo "" >> "$index_file"
echo " " >> "$index_file"
echo " $index_title" >> "$index_file"
echo " " >> "$index_file"
echo "" >> "$index_file"
echo "" >> "$index_file"
echo "
$index_title
" >> "$index_file"
echo "
" >> "$index_file"
if [ -e "./directory_index.xml" ] ; then
echo "