2007-08-21 [wwp] 2.10.0cvs140
[claws.git] / manual / xml2pdf
index 56946335a9579290b0b2f3c6f46d5b3687475d0d..d30fa0aa1213745e90fe9454f37c17ea5a24a2f2 100644 (file)
@@ -7,30 +7,74 @@
 if [ $# -ne 2 ]
 then
        echo "usage: ${0##*/} <file.xsl> <file.xml>"
+       exit 1
 fi
 
-test -n "$XML_CATALOG_FILES" && \
-       CATALOG_FILES=$XML_CATALOG_FILES || \
-       CATALOG_FILES="/usr/local/etc/xml/catalog /etc/xml/catalog $HOME/xml/catalog"
+test -z "$JAVA" && \
+       JAVA=`which java`
+test -z "$JAVA" && \
+       JAVA="$JAVA_HOME/bin/java"
+if [ ! -x "$JAVA" ]
+then
+       echo 'error: java not found in your $PATH or in $JAVA_HOME/bin'
+       exit 1
+fi
+
+test -z "$SAXON" && \
+       SAXON=`which saxon`
+if [ -z "$SAXON" ]
+then
+       test -z "$SAXONJAR" && \
+               SAXONJAR='/usr/share/java/saxon.jar'
+       if [ ! -f "$SAXONJAR" ]
+       then
+               SAXONJAR='/usr/local/share/java/saxon.jar'
+               if [ ! -f "$SAXONJAR" ]
+               then
+                       echo "error: neither saxon nor saxon.jar were found"
+                       exit 1
+               fi
+       fi
+       SAXON="$JAVA -jar $SAXONJAR"
+fi
+
+
+if [ -n "$XML_CATALOG_FILES" ]
+then
+       CATALOG_FILES=$XML_CATALOG_FILES
+else
+       echo "warning: XML_CATALOG_FILES is not set or empty"
+       CATALOG_FILES="/usr/local/etc/xml/catalog /etc/xml/catalog
+                       /usr/local/share/xml/catalog $HOME/xml/catalog"
+fi
 KEY="http://docbook.sourceforge.net/release/xsl/current"
 
+# manual base name
+SCM=claws-mail-manual
+
 for CATALOG in $CATALOG_FILES
 do
        if [ -s "$CATALOG" ]
        then
                DOCBOOKXSLPATH=$(xmlcatalog "$CATALOG" "$KEY/")
                # second chance
-               test $? -ne 0 -o -z "$DOCBOOKXSLPATH" && \
+               if [ $? -ne 0 -o -z "$DOCBOOKXSLPATH" ]
+               then
                        DOCBOOKXSLPATH=$(xmlcatalog "$CATALOG" "$KEY")
+                       # still not found
+                       test $? -ne 0 -o -z "$DOCBOOKXSLPATH" && \
+                               continue
+               fi
 
-               test "${DOCBOOKXSLPATH:0:7}" == "file://" && \
-                       DOCBOOKXSLPATH=${DOCBOOKXSLPATH:7}
+               test "`echo ${DOCBOOKXSLPATH} | cut -c 1-7`" = "file://" && \
+                       DOCBOOKXSLPATH=`echo ${DOCBOOKXSLPATH} | cut -c 8-`
                if [ -n "$DOCBOOKXSLPATH" ]
                then
                        echo "docbook-xsl path found: $DOCBOOKXSLPATH"
-                       sed "s|@DOCBOOK_XSL_PATH@|$DOCBOOKXSLPATH|g" "$1" > sylpheed-claws-manual.xsl && \
-                               saxon -o sylpheed-claws-manual.fo "$2" sylpheed-claws-manual.xsl && \
-                               fop -fo sylpheed-claws-manual.fo -pdf sylpheed-claws-manual.pdf
+                       sed "s|@DOCBOOK_XSL_PATH@|$DOCBOOKXSLPATH|g" "$1" \
+                           > ${SCM}.xsl && \
+                               $SAXON -o ${SCM}.fo "$2" ${SCM}.xsl && \
+                               fop -fo ${SCM}.fo -pdf ${SCM}.pdf
                        exit $?
                fi
        fi