2004-08-16 17:41:11 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
## ================================================================
|
|
|
|
## Logtalk - Open source object-oriented logic programming language
|
2007-11-06 01:50:09 +00:00
|
|
|
## Release 2.30.7
|
2004-08-16 17:41:11 +01:00
|
|
|
##
|
2007-01-10 12:46:10 +00:00
|
|
|
## Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
|
2007-06-12 11:39:47 +01:00
|
|
|
## ================================================================
|
|
|
|
|
|
|
|
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"
|
|
|
|
else
|
|
|
|
echo "... unable to locate Logtalk installation directory!"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
elif ! [ -d "$LOGTALKHOME" ]; then
|
|
|
|
echo "The environment variable LOGTALKHOME points to a non-existing directory!"
|
|
|
|
echo "Its current value is: $LOGTALKHOME"
|
|
|
|
echo "The variable must be set to your Logtalk installation directory!"
|
|
|
|
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"
|
|
|
|
echo "new Logtalk user directory by running the \"cplgtdirs\" shell script:"
|
|
|
|
cplgtdirs
|
|
|
|
fi
|
|
|
|
elif ! [ -d "$LOGTALKUSER" ]; then
|
|
|
|
echo "Cannot find \$LOGTALKUSER directory! Creating a new Logtalk user directory"
|
|
|
|
echo "by running the \"cplgtdirs\" shell script:"
|
|
|
|
cplgtdirs
|
|
|
|
fi
|
|
|
|
echo
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2004-12-05 21:52:49 +00:00
|
|
|
a4_xsl="$LOGTALKUSER/xml/lgtpdfa4.xsl"
|
|
|
|
us_xsl="$LOGTALKUSER/xml/lgtpdfus.xsl"
|
2004-08-16 17:41:11 +01:00
|
|
|
|
|
|
|
format=a4
|
|
|
|
# format=us
|
|
|
|
|
|
|
|
processor=fop
|
|
|
|
# processor=xep
|
2005-12-24 18:00:21 +00:00
|
|
|
# processor=xinc
|
2004-08-16 17:41:11 +01:00
|
|
|
|
|
|
|
directory="."
|
|
|
|
|
|
|
|
usage_help()
|
|
|
|
{
|
|
|
|
echo
|
|
|
|
echo "This script converts all Logtalk XML documenting files in the"
|
|
|
|
echo "current directory to PDF files"
|
|
|
|
echo
|
|
|
|
echo "Usage:"
|
|
|
|
echo " $0 -f format -d directory -p processor"
|
|
|
|
echo " $0 -h"
|
|
|
|
echo
|
|
|
|
echo "Optional arguments:"
|
|
|
|
echo " -f paper format (either a4 or us; default is $format)"
|
|
|
|
echo " -d output directory for the PDF files (default is $directory)"
|
2005-12-24 18:00:21 +00:00
|
|
|
echo " -p XSL-FO processor (either fop, xep, or xinc; default is $processor)"
|
2004-08-16 17:41:11 +01:00
|
|
|
echo " -h help"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
while getopts "f:d:p:h" Option
|
|
|
|
do
|
|
|
|
case $Option in
|
|
|
|
f) f_arg="$OPTARG";;
|
|
|
|
d) d_arg="$OPTARG";;
|
|
|
|
p) p_arg="$OPTARG";;
|
|
|
|
h) usage_help;;
|
|
|
|
*) usage_help;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ "$f_arg" != "" && "$f_arg" != "a4" && "$f_arg" != "us" ]]
|
2005-12-24 18:00:21 +00:00
|
|
|
then
|
2007-06-12 11:39:47 +01:00
|
|
|
echo "Error! Unsupported output format: $f_arg"
|
|
|
|
usage_help
|
2005-12-24 18:00:21 +00:00
|
|
|
exit 1
|
2007-06-12 11:39:47 +01:00
|
|
|
elif [ "$f_arg" != "" ]
|
2004-08-16 17:41:11 +01:00
|
|
|
then
|
2007-06-12 11:39:47 +01:00
|
|
|
format=$f_arg
|
|
|
|
fi
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
if [[ "$d_arg" != "" && ! -d "$d_arg" ]]
|
|
|
|
then
|
|
|
|
echo "Error! directory does not exists: $d_arg"
|
|
|
|
usage_help
|
|
|
|
exit 1
|
|
|
|
elif [ "$d_arg" != "" ]
|
|
|
|
then
|
|
|
|
directory=$d_arg
|
|
|
|
fi
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
if [[ "$p_arg" != "" && "$p_arg" != "fop" && "$p_arg" != "xep" && "$p_arg" != "xinc" ]]
|
|
|
|
then
|
|
|
|
echo "Error! Unsupported XSL-FO processor: $p_arg"
|
|
|
|
usage_help
|
|
|
|
exit 1
|
|
|
|
elif [ "$p_arg" != "" ]
|
|
|
|
then
|
|
|
|
processor=$p_arg
|
|
|
|
fi
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
if [ "$format" = "a4" ]
|
|
|
|
then
|
|
|
|
xsl=$a4_xsl
|
|
|
|
else
|
|
|
|
xsl=$us_xsl
|
|
|
|
fi
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
if ! [[ -a "./logtalk.dtd" ]]
|
|
|
|
then
|
|
|
|
cp "$LOGTALKHOME"/xml/logtalk.dtd .
|
|
|
|
fi
|
2006-11-07 17:11:47 +00:00
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
if ! [[ -a "./custom.ent" ]]
|
|
|
|
then
|
|
|
|
cp "$LOGTALKUSER"/xml/custom.ent .
|
|
|
|
fi
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
if ! [[ -a "./logtalk.xsd" ]]
|
|
|
|
then
|
|
|
|
cp "$LOGTALKHOME"/xml/logtalk.xsd .
|
|
|
|
fi
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
if [[ `(ls *.xml | wc -l) 2> /dev/null` -gt 0 ]]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "converting XML files to PDF..."
|
|
|
|
for file in *.xml; do
|
|
|
|
echo " converting $file"
|
|
|
|
name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`"
|
|
|
|
case $processor in
|
|
|
|
xinc) eval xinc -xml \"$file\" -xsl \"$xsl\" -pdf \"$directory\"/\"$name.pdf\" 2> /dev/null;;
|
|
|
|
*) eval $processor -q -xml \"$file\" -xsl \"$xsl\" -pdf \"$directory\"/\"$name.pdf\";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
echo "conversion done"
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "No XML files exist in the current directory!"
|
|
|
|
echo
|
|
|
|
fi
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
rm -f logtalk.dtd
|
|
|
|
rm -f logtalk.xsd
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2007-06-12 11:39:47 +01:00
|
|
|
exit 0
|