root/tags/lgt2311/xml/lgt2pdf.sh

Revision 4000, 4.4 KB (checked in by pmoura, 12 months ago)

Updated copyright string.

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