1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#! /bin/sh -e
# $Id: lr_xml2pdf.in,v 1.40 2001/11/22 18:10:16 flacoste Exp $
#
# Copyright (C) 2000-2001 Stichting LogReport Foundation LogReport@LogReport.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see COPYING); if not, check with
# http://www.gnu.org/copyleft/gpl.html or write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
#
PROGRAM=lr_xml2pdf
# dereference sysconfdir's prefix dependency
prefix="@prefix@"
etcdir="@sysconfdir@/@PACKAGE@"
. $etcdir/profile_lean
tag="all all ${LR_ID:-UNSET} $PROGRAM"
echo >&2 "$tag info started with $*"
if test $# -lt 1
then
echo >&2 "$tag err expecting argument. syntax: $PROGRAM [-i] report.xml"
exit 1
fi
images=
while getopts :i a
do
case $a in
i)
images="-i"
;;
*)
echo >&2 "$tag err usage $PROGRAM [-i] report.xml"
exit 1
;;
esac
done
shift `expr $OPTIND - 1 || true`
file="$1"
if test ! -r "$file"
then
echo >&2 "$tag err file '$file' is not readable."
exit 1
fi
lr_check_prereq $images pdf || exit 1
# get global vars
prefix="@prefix@"
datadir="@datadir@/@PACKAGE@"
etcdir="@sysconfdir@/@PACKAGE@"
exec_prefix="@exec_prefix@"
libexecdir="@libexecdir@/@PACKAGE@"
PACKAGE="@PACKAGE@"
. $etcdir/defaults
XML_DCL="$datadir/sgml/xml.dcl"
if test ! -d "$TMPDIR"
then
echo >&2 "$tag notice dir $TMPDIR does not exist, creating it"
if mkdir "$TMPDIR"
then
:
else
echo >&2 "$tag err cannot create $TMPDIR, exiting!"
exit 1
fi
fi
tmpreportdir="$TMPDIR/$PROGRAM.$$"
echo >&2 "$tag debug creating temporary report dir $tmpreportdir"
if mkdir $tmpreportdir
then
:
else
echo >&2 "$tag err failed to create $tmpreportdir"
exit 1
fi
xmlfile="$TMPDIR/$PROGRAM.all.$$.xml"
if test -n "$images"
then
lr_xml2png -o $tmpreportdir < $file > $xmlfile
else
cp $file $xmlfile
fi
dbxfile="$tmpreportdir/$PROGRAM.all.$$.dbx"
echo >&2 "$tag info running lr_xml2dbx to convert $xmlfile to DocBook XML $dbxfile..."
lr_xml2dbx $xmlfile > $dbxfile
oldpwd="`pwd`"
cd $tmpreportdir
# Create needed catalog file
cat > "$tmpreportdir/catalog" <<EOF
SYSTEM "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" "$DBK_XML_DTD"
EOF
# now convert that dbx file to PDF
tmptex="$tmpreportdir/$PROGRAM.all.$$.tex"
tmppdf="$tmpreportdir/$PROGRAM.all.$$.pdf"
echo >&2 "$tag info converting $dbxfile to $tmptex..."
# tweak jade's stderr
exec 3>&1
$JADE -t tex -d $DBK_PRINT_STYLESHEET $XML_DCL $dbxfile 2>&1 1>&3 3>&- |
while read s; do echo >&2 "$tag info $JADE says $s"; done 1>&2 3>&-
echo >&2 "$tag info converting $tmptex to $tmppdf..."
# This could take up to three iterations
for i in 1 2 3; do
$PDFJADETEX $tmptex > /dev/null 2>&1
# TODO : check exit code, and deal with it. this:
# ! TeX capacity exceeded, sorry [main memory size=348001].
# ! ==> Fatal error occurred, the output PDF file not finished!
# might very well happen.
done
# clean up jade and pdfjadetex tmpfiles (we never wanna keep them, even
# when KEEP is set we wanna get rid of them)
rm $PROGRAM.all.$$.out $PROGRAM.all.$$.log $PROGRAM.all.$$.aux catalog
# give output
cat $tmppdf
cd $oldpwd
# clean temp
if test -n "$KEEP"
then
echo >&2 "$tag notice keeping temporary files in $tmpreportdir on your request. remove manually"
else
rm -fr $tmpreportdir $xmlfile
fi
echo >&2 "$tag info stopped"
|