#!/bin/bash
## =================================================================
## Logtalk - Object oriented extension to Prolog
## Release 2.22.1
##
## Copyright (c) 1998-2004 Paulo Moura. All Rights Reserved.
a4_xsl="$LOGTALKUSER/xml/lgtpdfa4.xsl"
us_xsl="$LOGTALKUSER/xml/lgtpdfus.xsl"
format=a4
# format=us
processor=fop
# processor=xep
directory="."
usage_help()
{
echo
echo "This script converts all Logtalk XML documenting files in the"
echo "current directory to PDF files"
echo "Usage:"
echo " $0 -f format -d directory -p processor"
echo " $0 -h"
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)"
echo " -p XSL-FO processor (either fop or xep; default is $processor)"
echo " -h help"
exit 1
}
if ! [ $LOGTALKUSER ]
then
echo "Error! The environment variable LOGTALKUSER must be defined first!"
else
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" ]]
echo "Error! Unsupported output format: $f_arg"
usage_help
elif [ "$f_arg" != "" ]
format=$f_arg
fi
if [[ "$d_arg" != "" && ! -d "$d_arg" ]]
echo "Error! directory does not exists: $d_arg"
elif [ "$d_arg" != "" ]
directory=$d_arg
if [[ "$p_arg" != "" && "$p_arg" != "fop" && "$p_arg" != "xep" ]]
echo "Error! Unsupported XSL-FO processor: $p_arg"
elif [ "$p_arg" != "" ]
processor=$p_arg
if [ "$format" = "a4" ]
xsl=$a4_xsl
xsl=$us_xsl
cp $LOGTALKUSER/xml/logtalk.dtd .
cp $LOGTALKUSER/xml/logtalk.xsd .
echo "converting XML files to PDF..."
for file in *.xml; do
echo " converting $file"
name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`"
eval $processor -q -xml $file -xsl $xsl -pdf $directory/$name.pdf
echo "conversion done"
rm -f logtalk.dtd
rm -f logtalk.xsd
exit 0