| 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 | |
|---|
| 13 | if ! [ "$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 |
|---|
| 35 | elif ! [ -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 |
|---|
| 41 | fi |
|---|
| 42 | export LOGTALKHOME |
|---|
| 43 | |
|---|
| 44 | if ! [ "$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 |
|---|
| 56 | elif ! [ -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 |
|---|
| 60 | fi |
|---|
| 61 | echo |
|---|
| 62 | |
|---|
| 63 | format=xhtml |
|---|
| 64 | index_file=index.html |
|---|
| 65 | index_title="Entity documentation index" |
|---|
| 66 | |
|---|
| 67 | usage_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 | |
|---|
| 86 | create_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 | |
|---|
| 134 | while getopts "f:i:t:h" Option |
|---|
| 135 | do |
|---|
| 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 |
|---|
| 143 | done |
|---|
| 144 | |
|---|
| 145 | if [ "$f_arg" != "" ] && [ "$f_arg" != "xhtml" ] && [ "$f_arg" != "html" ] ; then |
|---|
| 146 | echo "Error! Unsupported output format: $f_arg" |
|---|
| 147 | usage_help |
|---|
| 148 | exit 1 |
|---|
| 149 | elif [ "$f_arg" != "" ] ; then |
|---|
| 150 | format=$f_arg |
|---|
| 151 | fi |
|---|
| 152 | |
|---|
| 153 | if [ "$i_arg" != "" ] ; then |
|---|
| 154 | index_file=$i_arg |
|---|
| 155 | fi |
|---|
| 156 | |
|---|
| 157 | if [ "$t_arg" != "" ] ; then |
|---|
| 158 | index_title=$t_arg |
|---|
| 159 | fi |
|---|
| 160 | |
|---|
| 161 | if ! [ -e "./logtalk.dtd" ] ; then |
|---|
| 162 | cp "$LOGTALKHOME"/xml/logtalk.dtd . |
|---|
| 163 | fi |
|---|
| 164 | |
|---|
| 165 | if ! [ -e "./custom.ent" ] ; then |
|---|
| 166 | cp "$LOGTALKUSER"/xml/custom.ent . |
|---|
| 167 | fi |
|---|
| 168 | |
|---|
| 169 | if ! [ -e "./logtalk.xsd" ] ; then |
|---|
| 170 | cp "$LOGTALKHOME"/xml/logtalk.xsd . |
|---|
| 171 | fi |
|---|
| 172 | |
|---|
| 173 | if ! [ -e "./logtalk.css" ] ; then |
|---|
| 174 | cp "$LOGTALKUSER"/xml/logtalk.css . |
|---|
| 175 | fi |
|---|
| 176 | |
|---|
| 177 | if ! [ -e "./lgtxml.xsl" ] ; then |
|---|
| 178 | cp "$LOGTALKUSER"/xml/lgtxml.xsl . |
|---|
| 179 | fi |
|---|
| 180 | |
|---|
| 181 | if [ `(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 |
|---|
| 187 | else |
|---|
| 188 | echo |
|---|
| 189 | echo "No XML files exist in the current directory!" |
|---|
| 190 | echo |
|---|
| 191 | fi |
|---|
| 192 | |
|---|
| 193 | exit 0 |
|---|