| 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 | |
|---|
| 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 | xslt="$LOGTALKUSER/xml/lgttxt.xsl" |
|---|
| 64 | |
|---|
| 65 | processor=xsltproc |
|---|
| 66 | # processor=xalan |
|---|
| 67 | # processor=sabcmd |
|---|
| 68 | |
|---|
| 69 | directory="." |
|---|
| 70 | |
|---|
| 71 | usage_help() |
|---|
| 72 | { |
|---|
| 73 | echo |
|---|
| 74 | echo "This script converts all Logtalk XML documenting files in the" |
|---|
| 75 | echo "current directory to text files" |
|---|
| 76 | echo |
|---|
| 77 | echo "Usage:" |
|---|
| 78 | echo " $0 -d directory -p processor" |
|---|
| 79 | echo " $0 -h" |
|---|
| 80 | echo |
|---|
| 81 | echo "Optional arguments:" |
|---|
| 82 | echo " -d output directory for the text files (default is $directory)" |
|---|
| 83 | echo " -p XSLT processor (xsltproc, xalan, or sabcmd; default is $processor)" |
|---|
| 84 | echo " -h help" |
|---|
| 85 | echo |
|---|
| 86 | exit 1 |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | while getopts "d:p:h" Option |
|---|
| 90 | do |
|---|
| 91 | case $Option in |
|---|
| 92 | d) d_arg="$OPTARG";; |
|---|
| 93 | p) p_arg="$OPTARG";; |
|---|
| 94 | h) usage_help;; |
|---|
| 95 | *) usage_help;; |
|---|
| 96 | esac |
|---|
| 97 | done |
|---|
| 98 | |
|---|
| 99 | if [ "$d_arg" != "" ] && [ ! -d "$d_arg" ] ; then |
|---|
| 100 | echo "Error! directory does not exists: $d_arg" |
|---|
| 101 | usage_help |
|---|
| 102 | exit 1 |
|---|
| 103 | elif [ "$d_arg" != "" ] ; then |
|---|
| 104 | directory=$d_arg |
|---|
| 105 | fi |
|---|
| 106 | |
|---|
| 107 | if [ "$p_arg" != "" ] && [ "$p_arg" != "fop" ] && [ "$p_arg" != "xep" ] && [ "$p_arg" != "xinc" ] ; then |
|---|
| 108 | echo "Error! Unsupported XSL-FO processor: $p_arg" |
|---|
| 109 | usage_help |
|---|
| 110 | exit 1 |
|---|
| 111 | elif [ "$p_arg" != "" ] ; then |
|---|
| 112 | processor=$p_arg |
|---|
| 113 | fi |
|---|
| 114 | |
|---|
| 115 | if ! [ -e "./logtalk.dtd" ] ; then |
|---|
| 116 | cp "$LOGTALKHOME"/xml/logtalk.dtd . |
|---|
| 117 | fi |
|---|
| 118 | |
|---|
| 119 | if ! [ -e "./custom.ent" ] ; then |
|---|
| 120 | cp "$LOGTALKUSER"/xml/custom.ent . |
|---|
| 121 | fi |
|---|
| 122 | |
|---|
| 123 | if ! [ -e "./logtalk.xsd" ] ; then |
|---|
| 124 | cp "$LOGTALKHOME"/xml/logtalk.xsd . |
|---|
| 125 | fi |
|---|
| 126 | |
|---|
| 127 | if [ `(ls *.xml | wc -l) 2> /dev/null` -gt 0 ] ; then |
|---|
| 128 | echo |
|---|
| 129 | echo "converting XML files to text files..." |
|---|
| 130 | for file in *.xml; do |
|---|
| 131 | echo " converting $file" |
|---|
| 132 | name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`" |
|---|
| 133 | case "$processor" in |
|---|
| 134 | xsltproc) eval xsltproc -o \"$directory\"/\"$name.txt\" \"$xslt\" \"$file\";; |
|---|
| 135 | xalan) eval xalan -o \"$directory\"/\"$name.txt\" \"$file\" \"$xslt\";; |
|---|
| 136 | sabcmd) eval sabcmd \"$xslt\" \"$file\" \"$directory\"/\"$name.txt\";; |
|---|
| 137 | esac |
|---|
| 138 | done |
|---|
| 139 | echo "conversion done" |
|---|
| 140 | echo |
|---|
| 141 | else |
|---|
| 142 | echo |
|---|
| 143 | echo "No XML files exist in the current directory!" |
|---|
| 144 | echo |
|---|
| 145 | fi |
|---|
| 146 | |
|---|
| 147 | rm -f logtalk.dtd |
|---|
| 148 | rm -f logtalk.xsd |
|---|
| 149 | |
|---|
| 150 | exit 0 |
|---|