xref: /netbsd-src/external/bsd/bzip2/dist/xmlproc.sh (revision c12ab3f1404d3e6320413d6099c78880423d6a49)
14f9a1459Swiz#!/bin/bash
24f9a1459Swiz# see the README file for usage etc.
34f9a1459Swiz#
44f9a1459Swiz# ------------------------------------------------------------------
54f9a1459Swiz#  This file is part of bzip2/libbzip2, a program and library for
64f9a1459Swiz#  lossless, block-sorting data compression.
74f9a1459Swiz#
8*c12ab3f1Smaya#  bzip2/libbzip2 version 1.0.8 of 13 July 2019
9*c12ab3f1Smaya#  Copyright (C) 1996-2019 Julian Seward <jseward@acm.org>
104f9a1459Swiz#
114f9a1459Swiz#  Please read the WARNING, DISCLAIMER and PATENTS sections in the
124f9a1459Swiz#  README file.
134f9a1459Swiz#
144f9a1459Swiz#  This program is released under the terms of the license contained
154f9a1459Swiz#  in the file LICENSE.
164f9a1459Swiz# ----------------------------------------------------------------
174f9a1459Swiz
184f9a1459Swiz
194f9a1459Swizusage() {
204f9a1459Swiz  echo '';
214f9a1459Swiz  echo 'Usage: xmlproc.sh -[option] <filename.xml>';
224f9a1459Swiz  echo 'Specify a target from:';
234f9a1459Swiz  echo '-v      verify xml file conforms to dtd';
244f9a1459Swiz  echo '-html   output in html format (single file)';
254f9a1459Swiz  echo '-ps     output in postscript format';
264f9a1459Swiz  echo '-pdf    output in pdf format';
274f9a1459Swiz  exit;
284f9a1459Swiz}
294f9a1459Swiz
304f9a1459Swizif test $# -ne 2; then
314f9a1459Swiz  usage
324f9a1459Swizfi
334f9a1459Swiz# assign the variable for the output type
344f9a1459Swizaction=$1; shift
354f9a1459Swiz# assign the output filename
364f9a1459Swizxmlfile=$1; shift
374f9a1459Swiz# and check user input it correct
384f9a1459Swizif !(test -f $xmlfile); then
394f9a1459Swiz  echo "No such file: $xmlfile";
404f9a1459Swiz  exit;
414f9a1459Swizfi
424f9a1459Swiz# some other stuff we will use
434f9a1459SwizOUT=output
444f9a1459Swizxsl_fo=bz-fo.xsl
454f9a1459Swizxsl_html=bz-html.xsl
464f9a1459Swiz
474f9a1459Swizbasename=$xmlfile
484f9a1459Swizbasename=${basename//'.xml'/''}
494f9a1459Swiz
504f9a1459Swizfofile="${basename}.fo"
514f9a1459Swizhtmlfile="${basename}.html"
524f9a1459Swizpdffile="${basename}.pdf"
534f9a1459Swizpsfile="${basename}.ps"
544f9a1459Swizxmlfmtfile="${basename}.fmt"
554f9a1459Swiz
564f9a1459Swiz# first process the xmlfile with CDATA tags
574f9a1459Swiz./format.pl $xmlfile $xmlfmtfile
584f9a1459Swiz# so the shell knows where the catalogs live
594f9a1459Swizexport XML_CATALOG_FILES=/etc/xml/catalog
604f9a1459Swiz
614f9a1459Swiz# post-processing tidy up
624f9a1459Swizcleanup() {
634f9a1459Swiz  echo "Cleaning up: $@"
644f9a1459Swiz  while [ $# != 0 ]
654f9a1459Swiz  do
664f9a1459Swiz    arg=$1; shift;
674f9a1459Swiz    echo "  deleting $arg";
684f9a1459Swiz    rm $arg
694f9a1459Swiz  done
704f9a1459Swiz}
714f9a1459Swiz
724f9a1459Swizcase $action in
734f9a1459Swiz  -v)
744f9a1459Swiz   flags='--noout --xinclude --noblanks --postvalid'
754f9a1459Swiz   dtd='--dtdvalid http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd'
764f9a1459Swiz   xmllint $flags $dtd $xmlfmtfile 2> $OUT
774f9a1459Swiz   egrep 'error' $OUT
784f9a1459Swiz   rm $OUT
794f9a1459Swiz  ;;
804f9a1459Swiz
814f9a1459Swiz  -html)
824f9a1459Swiz   echo "Creating $htmlfile ..."
834f9a1459Swiz   xsltproc --nonet --xinclude  -o $htmlfile $xsl_html $xmlfmtfile
844f9a1459Swiz   cleanup $xmlfmtfile
854f9a1459Swiz  ;;
864f9a1459Swiz
874f9a1459Swiz  -pdf)
884f9a1459Swiz   echo "Creating $pdffile ..."
894f9a1459Swiz   xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
904f9a1459Swiz   pdfxmltex $fofile >$OUT </dev/null
914f9a1459Swiz   pdfxmltex $fofile >$OUT </dev/null
924f9a1459Swiz   pdfxmltex $fofile >$OUT </dev/null
934f9a1459Swiz   cleanup $OUT $xmlfmtfile *.aux *.fo *.log *.out
944f9a1459Swiz  ;;
954f9a1459Swiz
964f9a1459Swiz  -ps)
974f9a1459Swiz   echo "Creating $psfile ..."
984f9a1459Swiz   xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
994f9a1459Swiz   pdfxmltex $fofile >$OUT </dev/null
1004f9a1459Swiz   pdfxmltex $fofile >$OUT </dev/null
1014f9a1459Swiz   pdfxmltex $fofile >$OUT </dev/null
1024f9a1459Swiz   pdftops $pdffile $psfile
1034f9a1459Swiz   cleanup $OUT $xmlfmtfile $pdffile *.aux *.fo *.log *.out
1044f9a1459Swiz#  passivetex is broken, so we can't go this route yet.
1054f9a1459Swiz#   xmltex $fofile >$OUT </dev/null
1064f9a1459Swiz#   xmltex $fofile >$OUT </dev/null
1074f9a1459Swiz#   xmltex $fofile >$OUT </dev/null
1084f9a1459Swiz#   dvips -R -q -o bzip-manual.ps *.dvi
1094f9a1459Swiz  ;;
1104f9a1459Swiz
1114f9a1459Swiz  *)
1124f9a1459Swiz  usage
1134f9a1459Swiz  ;;
1144f9a1459Swizesac
115