root/tags/lgt2311/xml/lgt2xml.sh

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