-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmlto.in
executable file
·658 lines (585 loc) · 17.8 KB
/
xmlto.in
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
#!@XMLTO_BASH_PATH@
#
# @PACKAGE@ - apply an XSL stylesheet to an XML document
# Copyright (C) 2001, 2002, 2003 Tim Waugh <[email protected]>
# 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; if not, see <http://www.gnu.org/licenses/>.
# Utilities that we need that aren't everywhere
FIND=@FIND@ # This must be GNU find (need -maxdepth)
MKTEMP=@MKTEMP@ # See http://www.mktemp.org if missing on your system
BASH=@XMLTO_BASH_PATH@ # GNU bash, for running the format scripts
GETOPT=@GETOPT@ # a getopt that supports --longoptions
TAIL=@TAIL@ # a tail that supports -n (posix)
GREP=@GREP@ # GNU grep, for searching patterns
SED=@SED@ # GNU sed, for modification of patterns
version () {
echo "@PACKAGE@ version @VERSION@"
}
usage () {
cat << EOF
usage: @PACKAGE@ [OPTION]... FORMAT XML
OPTIONs are:
-v verbose output (-vv for very verbose)
-x stylesheet use the specified stylesheet instead of choosing one
-m fragment use the XSL fragment to customize the stylesheet
-o directory put output in the specified directory instead of
the current working directory
-p postprocopts pass option to postprocessor
--extensions turn on stylesheet extensions for this tool chain
--noautosize do not autodetect paper size via locales or paperconf
--noclean temp files are not deleted automatically
(good for diagnostics)
--noextensions do not use passivetex/fop extensions
--profile use profiling stylesheet
--searchpath colon-separated list of fallback directories
--skip-validation
do not attempt to validate the input before processing
--stringparam paramname=paramvalue
pass a named parameter to the stylesheet from the
command line
--with-fop use fop for formatting (if fop available)
--with-dblatex use dblatex for formatting (if dblatex available)
Available FORMATs depend on the type of the XML file (which is
determined automatically).
EOF
if [ -d "$FORMAT_DIR" ]
then
for source in $(${FIND} "$FORMAT_DIR" -maxdepth 1 -type d)
do
if [ "$source" = "$FORMAT_DIR" ]; then continue; fi
cat << EOF
For documents of type "$(basename "$source")":
EOF
ls "$source"
done
fi
}
# make_temp [-d] filenametag varname [message upon failure]
#
# Wrapper for 'varname=$(mktemp /tmp/xmlto-$filenametag.XXXXXX)'.
# * Remembers the temporary file's name so it can be deleted on exit
# * If the failure message is empty or missing, exits on failure
make_temp () {
local dirflag="" prefix="@PACKAGE@"
[ "$1" = "-d" ] && { dirflag="-d"; shift; }
[ -n "$1" ] && prefix="@PACKAGE@-$1"
if eval $2='$(${MKTEMP} $dirflag "${TMPDIR:-/tmp}/${prefix}.XXXXXX")'
then
CLEANFILES="$CLEANFILES ${!2}"
return 0
elif [ -z "$3" ]
then
echo >&2 "mktemp failed!"
exit 2
else
echo >&2 "mktemp failed. $3"
return 2
fi
}
compute_searchpath () {
local oldIFS="${IFS}"
IFS=":"
for asearchpath in "$1"; do
# wrangle relative paths into absolute ones so that the user
# isn't surprised if he does ``--searchpath .''
case "${asearchpath}" in
/*) ;;
*) asearchpath="${PWD}/${asearchpath}" ;;
esac
SEARCHPATH="${SEARCHPATH}${XML_SEARCHPATH_SEPARATOR}${asearchpath}"
# we only need a colon if more than one path is in the searchpath
# and only after the first iteration.
XML_SEARCHPATH_SEPARATOR=":"
done
IFS="${oldIFS}"
}
# Allow FORMAT_DIR to be over-ridden, so that we can be
# run from the build directory.
prefix=@prefix@
: ${FORMAT_DIR=@datarootdir@/@PACKAGE@/format}
# This can be over-ridden, but really we should detect the source
# document type without needing any help.
: ${SOURCE_FORMAT=docbook}
# Get absolute pathnames for FORMAT_DIR and OUTPUT_DIR.
WD="$(pwd)"
if [ "x${FORMAT_DIR##/*}" != "x" ]
then
FORMAT_DIR="${PWD}/${FORMAT_DIR}"
fi
OUTPUT_DIR="$WD"
# This is an array of XSL fragments specified by the user.
XSL_MODS=
# List of files to remove after exit
CLEANFILES=
trap -- 'cd /; [ -z "$CLEANFILES" ] || rm -rf $CLEANFILES' EXIT
XSLTOPTS=
SEARCHPATH=
PAPERCONF_PATH=@PAPER_CONF@
LOCALE_PATH=@LOCALE@
XMLLINT_PATH=@XMLLINT@
XSLTPROC_PATH=@XSLTPROC@
# Try to setup papersize using libpaper first ...
if type "$PAPERCONF_PATH" >/dev/null 2>&1
then
papername=`"$PAPERCONF_PATH" -n`
paperheight=`"$PAPERCONF_PATH" -mh | sed 's/ //g'`
paperwidth=`"$PAPERCONF_PATH" -mw | sed 's/ //g'`
if [ -n "$paperheight" -a -n "$paperwidth" ]
then
make_temp xsl papersizemod "Using default paper type." &&
cat << EOF > "$papersizemod"
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version='1.0'>
<xsl:param name="page.height">$paperheight</xsl:param>
<xsl:param name="page.width">$paperwidth</xsl:param>
<xsl:template name="root.messages">
<xsl:message>
<xsl:text>Making </xsl:text>
<xsl:value-of select="\$page.orientation"/>
<xsl:text> pages on $papername paper (</xsl:text>
<xsl:value-of select="\$page.width"/>
<xsl:text>x</xsl:text>
<xsl:value-of select="\$page.height"/>
<xsl:text>)</xsl:text>
</xsl:message>
</xsl:template>
</xsl:stylesheet>
EOF
fi
# ... or use magic paper size, based on LC_PAPER
elif type "$LOCALE_PATH" >/dev/null 2>&1
then
# For paper sizes we know about, specify them.
h=$("$LOCALE_PATH" LC_PAPER 2>/dev/null | head -n 1)
if [ "$h" = "297" ]
then
papertype=A4
fi
if [ -n "$papertype" ]
then
make_temp xsl papersizemod "Using default paper type." &&
cat << EOF > "$papersizemod"
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version='1.0'>
<xsl:param name="paper.type" select="'$papertype'"/>
</xsl:stylesheet>
EOF
fi
fi
# Magic encoding, based on locale
if type "$LOCALE_PATH" >/dev/null 2>&1
then
charmap=$("$LOCALE_PATH" charmap 2>/dev/null)
if [ -n "$charmap" ]
then
if make_temp xsl encodingmod "Using default output encoding."
then
cat << EOF > "$encodingmod"
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version='1.0'>
<xsl:param name="chunker.output.encoding" select="'$charmap'"/>
<xsl:param name="man.charmap.use.subset" select="'0'"/>
</xsl:stylesheet>
EOF
XSL_MODS="$XSL_MODS $encodingmod"
fi
fi
fi
# Make verbosity level uniformly available to called scripts
VERBOSE=0
export VERBOSE
# Disable network entities
XSLTOPTS="$XSLTOPTS --nonet"
# The names parameter for the XSLT stylesheet
XSLTPARAMS=""
# Enable XInclude
XSLTOPTS="$XSLTOPTS --xinclude"
SKIP_VALIDATION=0
BACKEND_EXTENSIONS=1
NO_AUTOSIZE=0
PROFILE=0
#actual possibilities DEFAULT(XSL-FO/passivetex), FOP and DBLATEX
USE_BACKEND=@BACKEND@
FOP_PATH=@FOP@
DBLATEX_PATH=@DBLATEX@
XMLTEX_PATH=@XMLTEX@
PDFXMLTEX_PATH=@PDFXMLTEX@
#check if we could use fop/dblatex backend as default(if not, use passivetex)
if [ x"$USE_BACKEND" = xFOP ] && ! type "$FOP_PATH" >/dev/null 2>&1
then
echo >&2 "@PACKAGE@: Warning: fop not found or not executable."
echo >&2 "@PACKAGE@: Using default backend..."
USE_BACKEND=DEFAULT
elif type "$FOP_PATH" >/dev/null 2>&1
then
# we should enable fop.extensions for fop 0_17,0_18 and 0_20*,
# fop1.extensions for the rest
if [ x`$FOP_PATH -v 2>/dev/null | $GREP 0_[12]` = x ]; then
FOPVERSION="fop1"
else
FOPVERSION="fop"
fi
fi
if [ x"$USE_BACKEND" = xDBLATEX ] && \
! type "$DBLATEX_PATH" >/dev/null 2>&1
then
echo >&2 "@PACKAGE@: Warning: dblatex not found or not executable."
echo >&2 "@PACKAGE@: Using default backend..."
USE_BACKEND=DEFAULT
fi
LINKS_PATH=$(command -v elinks || command -v links)
W3M_PATH=$(command -v w3m)
LYNX_PATH=$(command -v lynx)
GCP_PATH=$(command -v cp)
SED_PATH=$(command -v sed)
GREP_PATH=$(command -v grep)
ZIP_PATH=$(command -v zip)
# Process any options
ARGS=$(${GETOPT} \
--longoptions=help,version,extensions,searchpath:,skip-validation,stringparam:,noclean,noautosize,noextensions,profile,with-fop,with-dblatex \
-n xmlto -- x:m:o:p:v "$@")
[ $? != 0 ] && { usage; exit 1; }
eval set -- "$ARGS"
while [ "$#" -gt "0" ]; do
case "$1" in
--help)
usage
exit 0
;;
--version)
version
exit 0
;;
-x)
case "$2" in
-) make_temp stdin-xsl TMP_STYLESHEET
cat /dev/stdin > ${TMP_STYLESHEET}
STYLESHEET=${TMP_STYLESHEET} ;;
/*) STYLESHEET="$2" ;;
*) STYLESHEET="$PWD/$2" ;;
esac
shift 2
;;
-m)
case "$2" in
/* | *:/*) XSL_MODS="$XSL_MODS $2" ;;
*) XSL_MODS="$XSL_MODS $PWD/$2" ;;
esac
shift 2
;;
-o)
OUTPUT_DIR="$2"
if type -p cygpath >/dev/null; then
OUTPUT_DIR=$(cygpath "$OUTPUT_DIR")
fi
case "$OUTPUT_DIR" in
/*) OUTPUT_DIR="$OUTPUT_DIR" ;;
*) OUTPUT_DIR="$WD/$OUTPUT_DIR" ;;
esac
shift 2
;;
-p)
case $POSTARGS in
"") POSTARGS="$2" ;;
*) POSTPOSTARGS="$2" ;;
esac
shift 2
;;
--extensions)
XSLTOPTS="$XSLTOPTS --param use.extensions '1'"
shift
;;
--noextensions)
BACKEND_EXTENSIONS=0
shift
;;
-v)
: ${VERBOSE:-0}
VERBOSE=$((${VERBOSE}+1))
shift
;;
--searchpath)
compute_searchpath "$2"
# This is the cleanest method I can think of, but requires calls to
# xmllint and xsltproc to be run through eval --ohnobinki
[ -n "${SEARCHPATH}" ] && SEARCHPATH_FORMATTED="--path \"${SEARCHPATH}\""
shift 2
;;
--skip-validation)
SKIP_VALIDATION=1
shift
;;
--stringparam)
MYPARAM="$2"
XSLTPARAMS="$XSLTPARAMS --stringparam ${MYPARAM%=*}"
XSLTPARAMS="$XSLTPARAMS ${MYPARAM#*=}"
shift 2
;;
--noclean)
trap -- 'cd /; [ -z "$CLEANFILES" ] || echo "$CLEANFILES"' EXIT
shift
;;
--noautosize)
NO_AUTOSIZE=1
shift
;;
--with-fop)
##use fop instead of passivetex where possible
if ! type "$FOP_PATH" >/dev/null 2>&1
then
echo >&2 Warning: fop not found or not executable.
echo >&2 Using default backend...
else
USE_BACKEND="FOP"
fi
shift
;;
--with-dblatex)
##use dblatex instead of passivetex where possible
if ! type "$DBLATEX_PATH" >/dev/null 2>&1
then
echo >&2 Warning: dblatex not found or not executable.
echo >&2 Using default backend...
else
USE_BACKEND="DBLATEX"
fi
shift
;;
--profile)
PROFILE=1
shift
;;
--)
shift
break
;;
esac
done
if [ "$BACKEND_EXTENSIONS" -eq 1 ]
then
case "$USE_BACKEND" in
FOP)
XSLTOPTS="$XSLTOPTS --param $FOPVERSION.extensions '1'" ;;
DBLATEX)
;;
DEFAULT)
XSLTOPTS="$XSLTOPTS --param passivetex.extensions '1'" ;;
esac
fi
if [ "$#" != "2" ]
then
usage
exit 1
fi
DEST_FORMAT="$1"
case "$2" in
/*) INPUT_FILE="$2" ;;
*) INPUT_FILE="$PWD/$2" ;;
esac
if [ -z "$DEST_FORMAT" -o -z "$INPUT_FILE" ]
then
usage
exit 1
fi
[ ! -e "$INPUT_FILE" ] && echo >&2 Input file "$INPUT_FILE" not found && \
exit 1
# Since we know DEST_FORMAT, we know whether or not to use $papersizemod.
case "$DEST_FORMAT" in
fo | pdf | ps | dvi)
if [ "$NO_AUTOSIZE" -eq 0 ] && [ -n "$papersizemod" ]
then
XSL_MODS="$XSL_MODS $papersizemod"
fi
;;
esac
# Decide what source format this is. Default to DocBook.
#This was failing on Ubuntu 14.04, so changing detection a bit
#rootel=$(echo "xpath *" | "$XMLLINT_PATH" --shell "$INPUT_FILE" 2> /dev/null | head -n 3 |$TAIL -n 1 | cut -f 4 -d " " )
rootel_xpath='concat("{", namespace-uri(/*), "}", local-name(/*))'
rootel="$("$XMLLINT_PATH" --xpath "$rootel_xpath" "$INPUT_FILE" 2>/dev/null)"
case $(echo $rootel) in
"{http://www.w3.org/1999/XSL/Format}root")
SOURCE_FORMAT="fo"
;;
"{http://www.w3.org/1999/xhtml}html")
SOURCE_FORMAT="xhtml1"
;;
esac
[ "$VERBOSE" -ge 1 ] && \
echo >&2 "Source format: ${SOURCE_FORMAT} / root element: ${rootel} "
# If the destination format is an absolute pathname then it's a
# user-defined format script. Otherwise it's one of ours.
case "$DEST_FORMAT" in
/*) FORMAT="$DEST_FORMAT" ;;
*) FORMAT="${FORMAT_DIR}/${SOURCE_FORMAT}/${DEST_FORMAT}" ;;
esac
[ "$VERBOSE" -ge 1 ] && echo >&2 "Format script: ${FORMAT}"
if [ ! -e "$FORMAT" ]
then
echo >&2 "I don't know how to convert ${SOURCE_FORMAT} into ${DEST_FORMAT}."
exit 1
fi
# Ask the format script what stylesheet to use.
XSLT_PROCESSOR="$XSLTPROC_PATH" # We only know about xsltproc right now.
export XSLT_PROCESSOR
export ZIP_PATH
export W3M_PATH
export GCP_PATH
export LINKS_PATH
export LYNX_PATH
export FOP_PATH
export SED_PATH
export GREP_PATH
export DBLATEX_PATH
export XMLTEX_PATH
export PDFXMLTEX_PATH
export USE_BACKEND
if [ -z "$STYLESHEET" ]
then
STYLESHEET="$(${BASH} "$FORMAT" stylesheet)" || exit 1
[ "$VERBOSE" -ge 1 ] && echo >&2 "Stylesheet: ${STYLESHEET}"
fi
# We might need to create a temporary stylesheet if there are
# XSL fragments that need adding.
if [ -n "$XSL_MODS" -a -n "$STYLESHEET" ]
then
REAL_STYLESHEET="$STYLESHEET"
[ "$VERBOSE" -ge 1 ] && echo >&2 "Real stylesheet: ${REAL_STYLESHEET}"
make_temp xsl STYLESHEET
cat << EOF > "$STYLESHEET"
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version='1.0'>
<xsl:import href="${REAL_STYLESHEET}"/>
EOF
i=0
for i in $XSL_MODS
do
cat << EOF >> "$STYLESHEET"
<xsl:include href="$i"/>
EOF
done
cat << EOF >> "$STYLESHEET"
</xsl:stylesheet>
EOF
fi
make_temp -d "" XSLT_PROCESSED_DIR
cd "$XSLT_PROCESSED_DIR"
# Validate the input
if [ "$SKIP_VALIDATION" -eq 0 ] && [ "$SOURCE_FORMAT" != "fo" ]
then
#do we have xmllint validation tool?
if ! type "$XMLLINT_PATH" >/dev/null 2>&1
then
echo >&2 "@PACKAGE@: xmllint validation tool not found or not executable."
echo >&2 "@PACKAGE@: Skipping validation... " \
"Please make sure xmllint is installed."
else
VALIDATION="${XSLT_PROCESSED_DIR}/validation-errors"
[ "$VERBOSE" -ge 1 ] && \
echo >&2 \
"\"${XMLLINT_PATH}\" --noout --nonet --xinclude --postvalid --noent ${SEARCHPATH_FORMATTED} \"${INPUT_FILE}\""
# eval is for SEARCHPATH_FORMATTED's proper expansion
# make sure expansions are protected from eval
eval "\"${XMLLINT_PATH}\" --noout --nonet --xinclude --postvalid --noent ${SEARCHPATH_FORMATTED} \"${INPUT_FILE}\"" 2>"${VALIDATION}"
xmllint_status=$?
if [ $xmllint_status -ne 0 ]
then
echo >&2 "@PACKAGE@: $INPUT_FILE does not validate (status ${xmllint_status})"
echo >&2 "@PACKAGE@: Fix document syntax or use --skip-validation option"
cat >&2 "${VALIDATION}"
exit $(($xmllint_status + 10))
fi
rm -f "${VALIDATION}"
fi
fi
if [ "$VERBOSE" -gt 2 ]
then
XSLTOPTS="$XSLTOPTS -v"
fi
XSLTOPTS="${XSLTPARAMS} ${XSLTOPTS}"
if [ "$PROFILE" -eq 1 ] || [ -n "${STYLESHEET}" ]
then
#do we have xsltproc tool?
if ! type "$XSLTPROC_PATH" >/dev/null 2>&1
then
echo >&2 "@PACKAGE@: Can't continue, xsltproc tool not found or not executable."
exit 3
fi
fi
if [ "$PROFILE" -eq 1 ]
then
PROF_PROCESSED="$XSLT_PROCESSED_DIR/$(basename "${INPUT_FILE%.*}").prof"
PROFILE_STYLESHEET="http://docbook.sourceforge.net/release/xsl/current/profiling/profile.xsl"
[ "$VERBOSE" -ge 1 ] && echo >&2 "Profiling stylesheet: ${PROFILE_STYLESHEET}"
[ "${VERBOSE}" -ge 1 ] && \
printf >&2 "${XSLTPROC_PATH} ${XSLTOPTS} ${SEARCHPATH_FORMATTED} \\\\\n -o \"${PROF_PROCESSED}\" \\\\\n \"${PROFILE_STYLESHEET}\" \"${INPUT_FILE}\"\n"
# eval is for SEARCHPATH_FORMATTED's proper expansion
eval "\"${XSLTPROC_PATH}\" ${XSLTOPTS} ${SEARCHPATH_FORMATTED} -o \"${PROF_PROCESSED}\" \"${PROFILE_STYLESHEET}\" \"${INPUT_FILE}\""
# remember the xsltproc exit code for later checks
xsltproc_status=$?
#xsltproc may return no file on empty input, touch it to have it for sure
touch "$PROF_PROCESSED"
# xsltproc returned an exit code - exit the script
[ ${xsltproc_status} -gt 0 ] && exit ${xsltproc_status}
else
# No profile processing to do.
PROF_PROCESSED="$INPUT_FILE"
fi
if [ -z "${STYLESHEET}" ]
then
# No stylesheet: no XSL-T processing to do.
XSLT_PROCESSED="$PROF_PROCESSED"
else
[ "$VERBOSE" -ge 1 ] && echo >&2 "Stylesheet: ${STYLESHEET}"
XSLT_PROCESSED="$XSLT_PROCESSED_DIR/$(basename "${PROF_PROCESSED%.*}").proc"
[ "${VERBOSE}" -ge 1 ] && \
printf >&2 "${XSLTPROC_PATH} ${XSLTOPTS} ${SEARCHPATH_FORMATTED} \\\\\n -o \"${XSLT_PROCESSED}\" \\\\\n \"${STYLESHEET}\" \\\\\n \"${PROF_PROCESSED}\"\n"
# eval is for SEARCHPATH_FORMATTED's proper expansion
eval "\"${XSLTPROC_PATH}\" ${XSLTOPTS} ${SEARCHPATH_FORMATTED} -o \"${XSLT_PROCESSED}\" \"${STYLESHEET}\" \"${PROF_PROCESSED}\""
# remember the xsltproc exit code for later checks
xsltproc_status=$?
#xsltproc may return no file on empty input, touch it to have it for sure
touch "$XSLT_PROCESSED"
if [ $xsltproc_status = 4 ]
then
XSLTOPTS="${XSLTOPTS} --catalogs"
if [ "$VERBOSE" -ge 1 ]; then
echo >&2 "No XML Catalogs? Trying again with --catalogs:"
printf >&2 "${XSLTPROC_PATH} ${XSLTOPTS} ${SEARCHPATH_FORMATTED}\\\\\n -o \"${XSLT_PROCESSED}\" \\\\\n \"${STYLESHEET}\" \\\\\n \"${PROF_PROCESSED}\"\n"
fi
eval "\"${XSLTPROC_PATH}\"" ${XSLTOPTS} ${SEARCHPATH_FORMATTED} -o "\"${XSLT_PROCESSED}\"" "\"${STYLESHEET}\"" "\"${PROF_PROCESSED}\""
xsltproc_status=$?
fi
# xsltproc returned an exit code - exit the script
[ ${xsltproc_status} -gt 0 ] && exit ${xsltproc_status}
fi
if [ ! -d "$OUTPUT_DIR" ]
then
[ "$VERBOSE" -ge 1 ] && echo >&2 "Creating output directory ${OUTPUT_DIR}"
mkdir -p "$OUTPUT_DIR"
fi
# Run the format script in post-process mode to finish off.
export OUTPUT_DIR
export POSTARGS
export POSTPOSTARGS
export XSLT_PROCESSED
export INPUT_FILE
export SEARCHPATH
if [ "$VERBOSE" -gt 2 ]
then
# Extremely verbose
BASH="${BASH} -x"
fi
${BASH} "$FORMAT" post-process || exit 1