root/trunk/xml/lgt2html.sh

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