"Fossies" - the Fresh Open Source Software Archive

Member "xmlto-0.0.28/xmlto.in" (16 Nov 2015, 17963 Bytes) of package /linux/privat/xmlto-0.0.28.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "xmlto.in": 0.0.27_vs_0.0.28.

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