root/trunk/xml/lgt2xml.sh

Revision 4572, 5.6 KB (checked in by pmoura, 13 days ago)

Updated the Logtalk version number to 2.33.3 in preparation for the next release.

  • 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.33.3
6##
7## Copyright (c) 1998-2008 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
63format=xhtml
64index_file=index.html
65index_title="Entity documentation index"
66
67usage_help()
68{
69    echo
70    echo "This script generates an index for all the Logtalk XML files"
71    echo "documenting files in the current directory"
72    echo
73    echo "Usage:"
74    echo "  $0 -f format -i index -t title"
75    echo "  $0 -h"
76    echo
77    echo "Optional arguments:"
78    echo "  -f format of the index file (either xhtml or html; default is $format)"
79    echo "  -i name of the index file (default is $index_file)"
80    echo "  -t title to be used on the index file (default is $index_title)"
81    echo "  -h help"
82    echo
83    exit 1
84}
85
86create_index_file()
87{
88    echo "" > "$index_file"
89
90    case "$format" in
91        xhtml)
92            echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>" >> "$index_file"
93            echo "<?xml-stylesheet href=\"logtalk.css\" type=\"text/css\"?>" >> "$index_file"
94            echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" >> "$index_file"
95            echo "<html lang=\"en\" xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">" >> "$index_file"
96            ;;
97        html)
98            echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">" >> "$index_file"
99            echo "<html>" >> "$index_file"
100            ;;
101    esac
102
103    echo "<head>" >> "$index_file"
104    echo "    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>" >> "$index_file"
105    echo "    <title>"$index_title"</title>" >> "$index_file"
106    echo "    <link rel=\"stylesheet\" href=\"logtalk.css\" type=\"text/css\"/>" >> "$index_file"
107    echo "</head>" >> "$index_file"
108    echo "<body>" >> "$index_file"
109    echo "<h1>"$index_title"</h1>" >> "$index_file"
110    echo "<ul>" >> "$index_file"
111
112    for file in *.xml; do
113        name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`"
114        entity=${name%_*}
115        pars=${name##*_}
116        echo "  indexing $file"
117        if [ $pars -gt 0 ]
118        then
119            echo "    <li><a href=\""$file"\">"$entity"/"$pars"</a></li>" >> "$index_file"
120        else
121            echo "    <li><a href=\""$file"\">"$entity"</a></li>" >> "$index_file"
122        fi
123    done
124
125    echo "</ul>" >> "$index_file"
126
127    date="`eval date`"
128
129    echo "<p>Generated on "$date"</p>" >> "$index_file"
130    echo "</body>" >> "$index_file"
131    echo "</html>" >> "$index_file"
132}
133
134while getopts "f:i:t:h" Option
135do
136    case $Option in
137        f) f_arg="$OPTARG";;
138        i) i_arg="$OPTARG";;
139        t) t_arg="$OPTARG";;
140        h) usage_help;;
141        *) usage_help;;
142    esac
143done
144
145if [ "$f_arg" != "" ] && [ "$f_arg" != "xhtml" ] && [ "$f_arg" != "html" ] ; then
146    echo "Error! Unsupported output format: $f_arg"
147    usage_help
148    exit 1
149elif [ "$f_arg" != "" ] ; then
150    format=$f_arg
151fi
152
153if [ "$i_arg" != "" ] ; then
154    index_file=$i_arg
155fi
156
157if [ "$t_arg" != "" ] ; then
158    index_title=$t_arg
159fi
160
161if ! [ -e "./logtalk.dtd" ] ; then
162    cp "$LOGTALKHOME"/xml/logtalk.dtd .
163fi
164
165if ! [ -e "./custom.ent" ] ; then
166    cp "$LOGTALKUSER"/xml/custom.ent .
167fi
168
169if ! [ -e "./logtalk.xsd" ] ; then
170    cp "$LOGTALKHOME"/xml/logtalk.xsd .
171fi
172
173if ! [ -e "./logtalk.css" ] ; then
174    cp "$LOGTALKUSER"/xml/logtalk.css .
175fi
176
177if ! [ -e "./lgtxml.xsl" ] ; then
178    cp "$LOGTALKUSER"/xml/lgtxml.xsl .
179fi
180
181if [ `(ls *.xml | wc -l) 2> /dev/null` -gt 0 ] ; then
182    echo
183    echo "generating index file..."
184    create_index_file
185    echo "index file generated"
186    echo
187else
188    echo
189    echo "No XML files exist in the current directory!"
190    echo
191fi
192
193exit 0
Note: See TracBrowser for help on using the browser.