| 1 | #!/bin/bash |
|---|
| 2 | |
|---|
| 3 | ## ================================================================= |
|---|
| 4 | ## Logtalk - Object oriented extension to Prolog |
|---|
| 5 | ## Release 2.21.1 |
|---|
| 6 | ## |
|---|
| 7 | ## Copyright (c) 1998-2004 Paulo Moura. All Rights Reserved. |
|---|
| 8 | ## ================================================================= |
|---|
| 9 | |
|---|
| 10 | html_xslt="$LOGTALKHOME/xml/lgthtml.xsl" |
|---|
| 11 | xhtml_xslt="$LOGTALKHOME/xml/lgtxhtml.xsl" |
|---|
| 12 | |
|---|
| 13 | format=xhtml |
|---|
| 14 | |
|---|
| 15 | directory="." |
|---|
| 16 | |
|---|
| 17 | index_file=index.html |
|---|
| 18 | index_title="Entity documentation index" |
|---|
| 19 | |
|---|
| 20 | processor=xsltproc |
|---|
| 21 | # processor=xalan |
|---|
| 22 | # processor=sabcmd |
|---|
| 23 | |
|---|
| 24 | usage_help() |
|---|
| 25 | { |
|---|
| 26 | echo |
|---|
| 27 | echo "This script converts all Logtalk XML files documenting files in the" |
|---|
| 28 | echo "current directory to XHTML or HTML files" |
|---|
| 29 | echo |
|---|
| 30 | echo "Usage:" |
|---|
| 31 | echo " $0 -f format -d directory -i index -t title -p processor" |
|---|
| 32 | echo " $0 -h" |
|---|
| 33 | echo |
|---|
| 34 | echo "Optional arguments:" |
|---|
| 35 | echo " -f output file format (either xhtml or html; default is $format)" |
|---|
| 36 | echo " -d output directory for the generated files (default is $directory)" |
|---|
| 37 | echo " -i name of the index file (default is $index_file)" |
|---|
| 38 | echo " -t title to be used on the index file (default is $index_title)" |
|---|
| 39 | echo " -p XSLT processor (xsltproc, xalan, or sabcmd; default is $processor)" |
|---|
| 40 | echo " -h help" |
|---|
| 41 | echo |
|---|
| 42 | exit 1 |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | create_index_file() |
|---|
| 46 | { |
|---|
| 47 | echo "" > $index_file |
|---|
| 48 | |
|---|
| 49 | case "$format" in |
|---|
| 50 | xhtml) |
|---|
| 51 | echo "<?xml version=\"1.0\"?>" >> $index_file |
|---|
| 52 | echo "<?xml-stylesheet href=\"logtalk.css\" type=\"text/css\"?>" >> $index_file |
|---|
| 53 | echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" >> $index_file |
|---|
| 54 | echo "<html lang=\"en\" xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">" >> $index_file |
|---|
| 55 | ;; |
|---|
| 56 | html) |
|---|
| 57 | echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">" >> $index_file |
|---|
| 58 | echo "<html>" >> $index_file |
|---|
| 59 | ;; |
|---|
| 60 | esac |
|---|
| 61 | |
|---|
| 62 | echo "<head>" >> $index_file |
|---|
| 63 | echo " <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>" >> $index_file |
|---|
| 64 | echo " <title>"$index_title"</title>" >> $index_file |
|---|
| 65 | echo " <link rel=\"stylesheet\" href=\"logtalk.css\" type=\"text/css\"/>" >> $index_file |
|---|
| 66 | echo "</head>" >> $index_file |
|---|
| 67 | echo "<body>" >> $index_file |
|---|
| 68 | echo "<h1>"$index_title"</h1>" >> $index_file |
|---|
| 69 | echo "<ul>" >> $index_file |
|---|
| 70 | |
|---|
| 71 | for file in *.xml; do |
|---|
| 72 | name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`" |
|---|
| 73 | echo " indexing $name.html" |
|---|
| 74 | echo " <li><a href=\""$name.html"\">"$name"</a></li>" >> $index_file |
|---|
| 75 | done |
|---|
| 76 | |
|---|
| 77 | echo "</ul>" >> $index_file |
|---|
| 78 | |
|---|
| 79 | date="`eval date`" |
|---|
| 80 | |
|---|
| 81 | echo "<p>Generated on "$date"</p>" >> $index_file |
|---|
| 82 | echo "</body>" >> $index_file |
|---|
| 83 | echo "</html>" >> $index_file |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | if ! [ $LOGTALKHOME ] |
|---|
| 88 | then |
|---|
| 89 | echo "Error! The environment variable LOGTALKHOME must be defined first!" |
|---|
| 90 | exit 1 |
|---|
| 91 | else |
|---|
| 92 | |
|---|
| 93 | while getopts "f:d:i:t:p:h" Option |
|---|
| 94 | do |
|---|
| 95 | case $Option in |
|---|
| 96 | f) f_arg="$OPTARG";; |
|---|
| 97 | d) d_arg="$OPTARG";; |
|---|
| 98 | i) i_arg="$OPTARG";; |
|---|
| 99 | t) t_arg="$OPTARG";; |
|---|
| 100 | p) p_arg="$OPTARG";; |
|---|
| 101 | h) usage_help;; |
|---|
| 102 | *) usage_help;; |
|---|
| 103 | esac |
|---|
| 104 | done |
|---|
| 105 | |
|---|
| 106 | if [[ "$f_arg" != "" && "$f_arg" != "xhtml" && "$f_arg" != "html" ]] |
|---|
| 107 | then |
|---|
| 108 | echo "Error! Unsupported output format: $f_arg" |
|---|
| 109 | usage_help |
|---|
| 110 | exit 1 |
|---|
| 111 | elif [ "$f_arg" != "" ] |
|---|
| 112 | then |
|---|
| 113 | format=$f_arg |
|---|
| 114 | fi |
|---|
| 115 | |
|---|
| 116 | if [[ "$d_arg" != "" && ! -d "$d_arg" ]] |
|---|
| 117 | then |
|---|
| 118 | echo "Error! directory does not exists: $d_arg" |
|---|
| 119 | usage_help |
|---|
| 120 | exit 1 |
|---|
| 121 | elif [ "$d_arg" != "" ] |
|---|
| 122 | then |
|---|
| 123 | directory=$d_arg |
|---|
| 124 | fi |
|---|
| 125 | |
|---|
| 126 | if [[ "$i_arg" != "" ]] |
|---|
| 127 | then |
|---|
| 128 | index_file=$i_arg |
|---|
| 129 | fi |
|---|
| 130 | |
|---|
| 131 | if [[ "$t_arg" != "" ]] |
|---|
| 132 | then |
|---|
| 133 | index_title=$t_arg |
|---|
| 134 | fi |
|---|
| 135 | |
|---|
| 136 | if [[ "$p_arg" != "" && "$p_arg" != "xsltproc" && "$p_arg" != "xalan" && "$p_arg" != "sabcmd" ]] |
|---|
| 137 | then |
|---|
| 138 | echo "Error! Unsupported XSLT processor: $p_arg" |
|---|
| 139 | usage_help |
|---|
| 140 | exit 1 |
|---|
| 141 | elif [ "$p_arg" != "" ] |
|---|
| 142 | then |
|---|
| 143 | processor=$p_arg |
|---|
| 144 | fi |
|---|
| 145 | |
|---|
| 146 | if [ "$format" = "xhtml" ] |
|---|
| 147 | then |
|---|
| 148 | xslt=$xhtml_xslt |
|---|
| 149 | else |
|---|
| 150 | xslt=$html_xslt |
|---|
| 151 | fi |
|---|
| 152 | |
|---|
| 153 | cp $LOGTALKHOME/xml/logtalk.dtd . |
|---|
| 154 | cp $LOGTALKHOME/xml/logtalk.xsd . |
|---|
| 155 | cp $LOGTALKHOME/xml/logtalk.css $directory |
|---|
| 156 | |
|---|
| 157 | echo |
|---|
| 158 | echo "converting XML files..." |
|---|
| 159 | |
|---|
| 160 | for file in *.xml; do |
|---|
| 161 | echo " converting $file" |
|---|
| 162 | name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`" |
|---|
| 163 | case "$processor" in |
|---|
| 164 | xsltproc) eval xsltproc -o $directory/$name.html $xslt $file;; |
|---|
| 165 | xalan) eval xalan -o $directory/$name.html $file $xslt;; |
|---|
| 166 | sabcmd) eval sabcmd $xslt $file $directory/$name.html;; |
|---|
| 167 | esac |
|---|
| 168 | done |
|---|
| 169 | |
|---|
| 170 | echo "conversion done" |
|---|
| 171 | echo |
|---|
| 172 | echo "generating index file..." |
|---|
| 173 | |
|---|
| 174 | index_file=$directory/$index_file |
|---|
| 175 | create_index_file |
|---|
| 176 | |
|---|
| 177 | echo "index file generated" |
|---|
| 178 | echo |
|---|
| 179 | |
|---|
| 180 | rm logtalk.dtd |
|---|
| 181 | rm logtalk.xsd |
|---|
| 182 | |
|---|
| 183 | exit 0 |
|---|
| 184 | |
|---|
| 185 | fi |
|---|