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