| 1 | #!/bin/bash |
|---|
| 2 | |
|---|
| 3 | ## ================================================================ |
|---|
| 4 | ## Logtalk - Open source object-oriented logic programming language |
|---|
| 5 | ## Release 2.31.0 |
|---|
| 6 | ## |
|---|
| 7 | ## Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved. |
|---|
| 8 | ## ================================================================ |
|---|
| 9 | |
|---|
| 10 | if ! [ "$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 |
|---|
| 32 | elif ! [ -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 |
|---|
| 38 | fi |
|---|
| 39 | export LOGTALKHOME |
|---|
| 40 | |
|---|
| 41 | if ! [ "$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 |
|---|
| 53 | elif ! [ -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 |
|---|
| 57 | fi |
|---|
| 58 | echo |
|---|
| 59 | |
|---|
| 60 | a4_xsl="$LOGTALKUSER/xml/lgtpdfa4.xsl" |
|---|
| 61 | us_xsl="$LOGTALKUSER/xml/lgtpdfus.xsl" |
|---|
| 62 | |
|---|
| 63 | format=a4 |
|---|
| 64 | # format=us |
|---|
| 65 | |
|---|
| 66 | processor=fop |
|---|
| 67 | # processor=xep |
|---|
| 68 | # processor=xinc |
|---|
| 69 | |
|---|
| 70 | directory="." |
|---|
| 71 | |
|---|
| 72 | usage_help() |
|---|
| 73 | { |
|---|
| 74 | echo |
|---|
| 75 | echo "This script converts all Logtalk XML documenting files in the" |
|---|
| 76 | echo "current directory to PDF files" |
|---|
| 77 | echo |
|---|
| 78 | echo "Usage:" |
|---|
| 79 | echo " $0 -f format -d directory -p processor" |
|---|
| 80 | echo " $0 -h" |
|---|
| 81 | echo |
|---|
| 82 | echo "Optional arguments:" |
|---|
| 83 | echo " -f paper format (either a4 or us; default is $format)" |
|---|
| 84 | echo " -d output directory for the PDF files (default is $directory)" |
|---|
| 85 | echo " -p XSL-FO processor (either fop, xep, or xinc; default is $processor)" |
|---|
| 86 | echo " -h help" |
|---|
| 87 | echo |
|---|
| 88 | exit 1 |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | while getopts "f:d:p:h" Option |
|---|
| 92 | do |
|---|
| 93 | case $Option in |
|---|
| 94 | f) f_arg="$OPTARG";; |
|---|
| 95 | d) d_arg="$OPTARG";; |
|---|
| 96 | p) p_arg="$OPTARG";; |
|---|
| 97 | h) usage_help;; |
|---|
| 98 | *) usage_help;; |
|---|
| 99 | esac |
|---|
| 100 | done |
|---|
| 101 | |
|---|
| 102 | if [[ "$f_arg" != "" && "$f_arg" != "a4" && "$f_arg" != "us" ]] |
|---|
| 103 | then |
|---|
| 104 | echo "Error! Unsupported output format: $f_arg" |
|---|
| 105 | usage_help |
|---|
| 106 | exit 1 |
|---|
| 107 | elif [ "$f_arg" != "" ] |
|---|
| 108 | then |
|---|
| 109 | format=$f_arg |
|---|
| 110 | fi |
|---|
| 111 | |
|---|
| 112 | if [[ "$d_arg" != "" && ! -d "$d_arg" ]] |
|---|
| 113 | then |
|---|
| 114 | echo "Error! directory does not exists: $d_arg" |
|---|
| 115 | usage_help |
|---|
| 116 | exit 1 |
|---|
| 117 | elif [ "$d_arg" != "" ] |
|---|
| 118 | then |
|---|
| 119 | directory=$d_arg |
|---|
| 120 | fi |
|---|
| 121 | |
|---|
| 122 | if [[ "$p_arg" != "" && "$p_arg" != "fop" && "$p_arg" != "xep" && "$p_arg" != "xinc" ]] |
|---|
| 123 | then |
|---|
| 124 | echo "Error! Unsupported XSL-FO processor: $p_arg" |
|---|
| 125 | usage_help |
|---|
| 126 | exit 1 |
|---|
| 127 | elif [ "$p_arg" != "" ] |
|---|
| 128 | then |
|---|
| 129 | processor=$p_arg |
|---|
| 130 | fi |
|---|
| 131 | |
|---|
| 132 | if [ "$format" = "a4" ] |
|---|
| 133 | then |
|---|
| 134 | xsl=$a4_xsl |
|---|
| 135 | else |
|---|
| 136 | xsl=$us_xsl |
|---|
| 137 | fi |
|---|
| 138 | |
|---|
| 139 | if ! [[ -a "./logtalk.dtd" ]] |
|---|
| 140 | then |
|---|
| 141 | cp "$LOGTALKHOME"/xml/logtalk.dtd . |
|---|
| 142 | fi |
|---|
| 143 | |
|---|
| 144 | if ! [[ -a "./custom.ent" ]] |
|---|
| 145 | then |
|---|
| 146 | cp "$LOGTALKUSER"/xml/custom.ent . |
|---|
| 147 | fi |
|---|
| 148 | |
|---|
| 149 | if ! [[ -a "./logtalk.xsd" ]] |
|---|
| 150 | then |
|---|
| 151 | cp "$LOGTALKHOME"/xml/logtalk.xsd . |
|---|
| 152 | fi |
|---|
| 153 | |
|---|
| 154 | if [[ `(ls *.xml | wc -l) 2> /dev/null` -gt 0 ]] |
|---|
| 155 | then |
|---|
| 156 | echo |
|---|
| 157 | echo "converting XML files to PDF..." |
|---|
| 158 | for file in *.xml; do |
|---|
| 159 | echo " converting $file" |
|---|
| 160 | name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`" |
|---|
| 161 | case $processor in |
|---|
| 162 | xinc) eval xinc -xml \"$file\" -xsl \"$xsl\" -pdf \"$directory\"/\"$name.pdf\" 2> /dev/null;; |
|---|
| 163 | *) eval $processor -q -xml \"$file\" -xsl \"$xsl\" -pdf \"$directory\"/\"$name.pdf\";; |
|---|
| 164 | esac |
|---|
| 165 | done |
|---|
| 166 | echo "conversion done" |
|---|
| 167 | echo |
|---|
| 168 | else |
|---|
| 169 | echo |
|---|
| 170 | echo "No XML files exist in the current directory!" |
|---|
| 171 | echo |
|---|
| 172 | fi |
|---|
| 173 | |
|---|
| 174 | rm -f logtalk.dtd |
|---|
| 175 | rm -f logtalk.xsd |
|---|
| 176 | |
|---|
| 177 | exit 0 |
|---|