root/trunk/xml/lgt2pdf.sh

Revision 4662, 4.6 KB (checked in by pmoura, 6 days ago)

Updated copyright notice.

  • Property svn:mime-type set to application/x-sh
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/bin/sh
2
3## ================================================================
4## Logtalk - Open source object-oriented logic programming language
5## Release 2.35.0
6##
7## Copyright (c) 1998-2009 Paulo Moura.        All Rights Reserved.
8## Logtalk is free software.  You can redistribute it and/or modify
9## it under the terms of the "Artistic License 2.0" as published by
10## The Perl Foundation. Consult the "LICENSE.txt" file for details.
11## ================================================================
12
13if ! [ "$LOGTALKHOME" ]; then
14    echo "The environment variable LOGTALKHOME should be defined first, pointing"
15    echo "to your Logtalk installation directory!"
16    echo "Trying the default locations for the Logtalk installation..."
17    if [ -d "/usr/local/share/logtalk" ]; then
18        LOGTALKHOME=/usr/local/share/logtalk
19        echo "... using Logtalk installation found at /usr/local/share/logtalk"
20    elif [ -d "/usr/share/logtalk" ]; then
21        LOGTALKHOME=/usr/share/logtalk
22        echo "... using Logtalk installation found at /usr/share/logtalk"
23    elif [ -d "/opt/local/share/logtalk" ]; then
24        LOGTALKHOME=/opt/local/share/logtalk
25        echo "... using Logtalk installation found at /opt/local/share/logtalk"
26    elif [ -d "/opt/share/logtalk" ]; then
27        LOGTALKHOME=/opt/share/logtalk
28        echo "... using Logtalk installation found at /opt/share/logtalk"
29    else
30        echo "... unable to locate Logtalk installation directory!"
31        echo
32        exit 1
33    fi
34    echo
35elif ! [ -d "$LOGTALKHOME" ]; then
36    echo "The environment variable LOGTALKHOME points to a non-existing directory!"
37    echo "Its current value is: $LOGTALKHOME"
38    echo "The variable must be set to your Logtalk installation directory!"
39    echo
40    exit 1
41fi
42export LOGTALKHOME
43
44if ! [ "$LOGTALKUSER" ]; then
45    echo "The environment variable LOGTALKUSER should be defined first, pointing"
46    echo "to your Logtalk user directory!"
47    echo "Trying the default location for the Logtalk user directory..."
48    export LOGTALKUSER=$HOME/logtalk
49    if [ -d "$LOGTALKUSER" ]; then     
50        echo "... using Logtalk user directory found at $LOGTALKUSER"
51    else
52        echo "... Logtalk user directory not found at default location. Creating a"
53        echo "new Logtalk user directory by running the \"cplgtdirs\" shell script:"
54        cplgtdirs
55    fi
56elif ! [ -d "$LOGTALKUSER" ]; then
57    echo "Cannot find \$LOGTALKUSER directory! Creating a new Logtalk user directory"
58    echo "by running the \"cplgtdirs\" shell script:"
59    cplgtdirs
60fi
61echo
62
63a4_xsl="$LOGTALKUSER/xml/lgtpdfa4.xsl"
64us_xsl="$LOGTALKUSER/xml/lgtpdfus.xsl"
65
66format=a4
67# format=us
68
69processor=fop
70# processor=xep
71# processor=xinc
72
73directory="."
74
75usage_help()
76{
77    echo
78    echo "This script converts all Logtalk XML documenting files in the"
79    echo "current directory to PDF files"
80    echo
81    echo "Usage:"
82    echo "  $0 -f format -d directory -p processor"
83    echo "  $0 -h"
84    echo
85    echo "Optional arguments:"
86    echo "  -f paper format (either a4 or us; default is $format)"
87    echo "  -d output directory for the PDF files (default is $directory)"
88    echo "  -p XSL-FO processor (either fop, xep, or xinc; default is $processor)"
89    echo "  -h help"
90    echo
91    exit 1
92}
93
94while getopts "f:d:p:h" Option
95do
96    case $Option in
97        f) f_arg="$OPTARG";;
98        d) d_arg="$OPTARG";;
99        p) p_arg="$OPTARG";;
100        h) usage_help;;
101        *) usage_help;;
102    esac
103done
104
105if [ "$f_arg" != "" ] && [ "$f_arg" != "a4" ] && [ "$f_arg" != "us" ] ; then
106    echo "Error! Unsupported output format: $f_arg"
107    usage_help
108    exit 1
109elif [ "$f_arg" != "" ]
110then
111    format=$f_arg
112fi
113
114if [ "$d_arg" != "" ] && [ ! -d "$d_arg" ] ; then
115    echo "Error! directory does not exists: $d_arg"
116    usage_help
117    exit 1
118elif [ "$d_arg" != "" ] ; then
119    directory=$d_arg
120fi
121
122if [ "$p_arg" != "" ] && [ "$p_arg" != "fop" ] && [ "$p_arg" != "xep" ] && [ "$p_arg" != "xinc" ] ; then
123    echo "Error! Unsupported XSL-FO processor: $p_arg"
124    usage_help
125    exit 1
126elif [ "$p_arg" != "" ] ; then
127    processor=$p_arg
128fi
129
130if [ "$format" = "a4" ] ; then
131    xsl=$a4_xsl
132else
133    xsl=$us_xsl
134fi
135
136if ! [ -e "./logtalk.dtd" ] ; then
137    cp "$LOGTALKHOME"/xml/logtalk.dtd .
138fi
139
140if ! [ -e "./custom.ent" ] ; then
141    cp "$LOGTALKUSER"/xml/custom.ent .
142fi
143
144if ! [ -e "./logtalk.xsd" ] ; then
145    cp "$LOGTALKHOME"/xml/logtalk.xsd .
146fi
147
148if [ `(ls *.xml | wc -l) 2> /dev/null` -gt 0 ] ; then
149    echo
150    echo "converting XML files to PDF..."
151    for file in *.xml; do
152        echo "  converting $file"
153        name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`"
154        case $processor in
155            xinc)   eval xinc -xml \"$file\" -xsl \"$xsl\" -pdf \"$directory\"/\"$name.pdf\" 2> /dev/null;;
156            *)      eval $processor -q -xml \"$file\" -xsl \"$xsl\" -pdf \"$directory\"/\"$name.pdf\";;
157        esac
158    done
159    echo "conversion done"
160    echo
161else
162    echo
163    echo "No XML files exist in the current directory!"
164    echo
165fi
166
167rm -f logtalk.dtd
168rm -f logtalk.xsd
169
170exit 0
Note: See TracBrowser for help on using the browser.