root/tags/lgt2305/xml/lgt2html.sh

Revision 3824, 6.6 KB (checked in by pmoura, 17 months ago)

Updated Logtalk release number to 2.30.5.

  • 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.30.5
6##
7## Copyright (c) 1998-2007 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
60html_xslt="$LOGTALKUSER/xml/lgthtml.xsl"
61xhtml_xslt="$LOGTALKUSER/xml/lgtxhtml.xsl"
62
63format=xhtml
64
65directory="."
66
67index_file=index.html
68index_title="Entity documentation index"
69
70processor=xsltproc
71# processor=xalan
72# processor=sabcmd
73
74usage_help()
75{
76    echo
77    echo "This script converts all Logtalk XML files documenting files in the"
78    echo "current directory to XHTML or HTML files"
79    echo
80    echo "Usage:"
81    echo "  $0 -f format -d directory -i index -t title -p processor"
82    echo "  $0 -h"
83    echo
84    echo "Optional arguments:"
85    echo "  -f output file format (either xhtml or html; default is $format)"
86    echo "  -d output directory for the generated files (default is $directory)"
87    echo "  -i name of the index file (default is $index_file)"
88    echo "  -t title to be used on the index file (default is $index_title)"
89    echo "  -p XSLT processor (xsltproc, xalan, or sabcmd; default is $processor)"
90    echo "  -h help"
91    echo
92    exit 1
93}
94
95create_index_file()
96{
97    echo "" > "$index_file"
98
99    case "$format" in
100        xhtml)
101            echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>" >> "$index_file"
102            echo "<?xml-stylesheet href=\"logtalk.css\" type=\"text/css\"?>" >> "$index_file"
103            echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" >> "$index_file"
104            echo "<html lang=\"en\" xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">" >> "$index_file"
105            ;;
106        html)
107            echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">" >> "$index_file"
108            echo "<html>" >> "$index_file"
109            ;;
110    esac
111
112    echo "<head>" >> "$index_file"
113    echo "    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>" >> "$index_file"
114    echo "    <title>"$index_title"</title>" >> "$index_file"
115    echo "    <link rel=\"stylesheet\" href=\"logtalk.css\" type=\"text/css\"/>" >> "$index_file"
116    echo "</head>" >> "$index_file"
117    echo "<body>" >> "$index_file"
118    echo "<h1>"$index_title"</h1>" >> "$index_file"
119    echo "<ul>" >> "$index_file"
120
121    for file in *.xml; do
122        name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`"
123        entity=${name%_*}
124        pars=${name##*_}
125        echo "  indexing $name.html"
126        if [ $pars -gt 0 ]
127        then
128            echo "    <li><a href=\""$name".html\">"$entity"/"$pars"</a></li>" >> "$index_file"
129        else
130            echo "    <li><a href=\""$name".html\">"$entity"</a></li>" >> "$index_file"
131        fi
132    done
133
134    echo "</ul>" >> "$index_file"
135
136    date="`eval date`"
137
138    echo "<p>Generated on "$date"</p>" >> "$index_file"
139    echo "</body>" >> "$index_file"
140    echo "</html>" >> "$index_file"
141}
142
143while getopts "f:d:i:t:p:h" Option
144do
145    case $Option in
146        f) f_arg="$OPTARG";;
147        d) d_arg="$OPTARG";;
148        i) i_arg="$OPTARG";;
149        t) t_arg="$OPTARG";;
150        p) p_arg="$OPTARG";;
151        h) usage_help;;
152        *) usage_help;;
153    esac
154done
155
156if [[ "$f_arg" != "" && "$f_arg" != "xhtml" && "$f_arg" != "html" ]]
157then
158    echo "Error! Unsupported output format: $f_arg"
159    usage_help
160    exit 1
161elif [ "$f_arg" != "" ]
162then
163    format=$f_arg
164fi
165
166if [[ "$d_arg" != "" && ! -d "$d_arg" ]]
167then
168    echo "Error! directory does not exists: $d_arg"
169    usage_help
170    exit 1
171elif [ "$d_arg" != "" ]
172then
173    directory=$d_arg
174fi
175
176if [[ "$i_arg" != "" ]]
177then
178    index_file=$i_arg
179fi
180
181if [[ "$t_arg" != "" ]]
182then
183    index_title=$t_arg
184fi
185
186if [[ "$p_arg" != "" && "$p_arg" != "xsltproc" && "$p_arg" != "xalan" && "$p_arg" != "sabcmd" ]]
187then
188    echo "Error! Unsupported XSLT processor: $p_arg"
189    usage_help
190    exit 1
191elif [ "$p_arg" != "" ]
192then
193    processor=$p_arg
194fi
195
196if [ "$format" = "xhtml" ]
197then
198    xslt=$xhtml_xslt
199else
200    xslt=$html_xslt
201fi
202
203if ! [[ -a "./logtalk.dtd" ]]
204then
205    cp "$LOGTALKHOME"/xml/logtalk.dtd .
206fi
207
208if ! [[ -a "./custom.ent" ]]
209then
210    cp "$LOGTALKUSER"/xml/custom.ent .
211fi
212
213if ! [[ -a "./logtalk.xsd" ]]
214then
215    cp "$LOGTALKHOME"/xml/logtalk.xsd .
216fi
217
218if ! [[ -a "$directory/logtalk.css" ]]
219then
220    cp "$LOGTALKUSER"/xml/logtalk.css "$directory"
221fi
222
223if [[ `(ls *.xml | wc -l) 2> /dev/null` -gt 0 ]]
224then
225    echo
226    echo "converting XML files..."
227    for file in *.xml; do
228        echo "  converting $file"
229        name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`"
230        case "$processor" in
231            xsltproc)   eval xsltproc -o \"$directory\"/\"$name.html\" \"$xslt\" \"$file\";;
232            xalan)      eval xalan -o \"$directory\"/\"$name.html\" \"$file\" \"$xslt\";;
233            sabcmd)     eval sabcmd \"$xslt\" \"$file\" \"$directory\"/\"$name.html\";;
234        esac
235    done
236    echo "conversion done"
237    echo
238    echo "generating index file..."
239    index_file="$directory/$index_file"
240    create_index_file
241    echo "index file generated"
242    echo
243else
244    echo
245    echo "No XML files exist in the current directory!"
246    echo
247fi
248
249exit 0
Note: See TracBrowser for help on using the browser.