1#!/bin/bash
2# see the README file for usage etc.
3#
4# ------------------------------------------------------------------
5#  This file is part of bzip2/libbzip2, a program and library for
6#  lossless, block-sorting data compression.
7#
8#  bzip2/libbzip2 version 1.0.6 of 6 September 2010
9#  Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
10#
11#  Please read the WARNING, DISCLAIMER and PATENTS sections in the 
12#  README file.
13#
14#  This program is released under the terms of the license contained
15#  in the file LICENSE.
16# ----------------------------------------------------------------
17
18
19usage() {
20  echo '';
21  echo 'Usage: xmlproc.sh -[option] <filename.xml>';
22  echo 'Specify a target from:';
23  echo '-v      verify xml file conforms to dtd';
24  echo '-html   output in html format (single file)';
25  echo '-ps     output in postscript format';
26  echo '-pdf    output in pdf format';
27  exit;
28}
29
30if test $# -ne 2; then
31  usage
32fi
33# assign the variable for the output type
34action=$1; shift
35# assign the output filename
36xmlfile=$1; shift
37# and check user input it correct
38if !(test -f $xmlfile); then
39  echo "No such file: $xmlfile";
40  exit;
41fi
42# some other stuff we will use
43OUT=output
44xsl_fo=bz-fo.xsl
45xsl_html=bz-html.xsl
46
47basename=$xmlfile
48basename=${basename//'.xml'/''}
49
50fofile="${basename}.fo"
51htmlfile="${basename}.html"
52pdffile="${basename}.pdf"
53psfile="${basename}.ps"
54xmlfmtfile="${basename}.fmt"
55
56# first process the xmlfile with CDATA tags
57./format.pl $xmlfile $xmlfmtfile
58# so the shell knows where the catalogs live
59export XML_CATALOG_FILES=/etc/xml/catalog
60
61# post-processing tidy up
62cleanup() {
63  echo "Cleaning up: $@" 
64  while [ $# != 0 ]
65  do
66    arg=$1; shift;
67    echo "  deleting $arg";
68    rm $arg
69  done
70}
71
72case $action in
73  -v)
74   flags='--noout --xinclude --noblanks --postvalid'
75   dtd='--dtdvalid http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd'
76   xmllint $flags $dtd $xmlfmtfile 2> $OUT 
77   egrep 'error' $OUT 
78   rm $OUT
79  ;;
80
81  -html)
82   echo "Creating $htmlfile ..."
83   xsltproc --nonet --xinclude  -o $htmlfile $xsl_html $xmlfmtfile
84   cleanup $xmlfmtfile
85  ;;
86
87  -pdf)
88   echo "Creating $pdffile ..."
89   xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
90   pdfxmltex $fofile >$OUT </dev/null
91   pdfxmltex $fofile >$OUT </dev/null
92   pdfxmltex $fofile >$OUT </dev/null
93   cleanup $OUT $xmlfmtfile *.aux *.fo *.log *.out
94  ;;
95
96  -ps)
97   echo "Creating $psfile ..."
98   xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
99   pdfxmltex $fofile >$OUT </dev/null
100   pdfxmltex $fofile >$OUT </dev/null
101   pdfxmltex $fofile >$OUT </dev/null
102   pdftops $pdffile $psfile
103   cleanup $OUT $xmlfmtfile $pdffile *.aux *.fo *.log *.out
104#  passivetex is broken, so we can't go this route yet.
105#   xmltex $fofile >$OUT </dev/null
106#   xmltex $fofile >$OUT </dev/null
107#   xmltex $fofile >$OUT </dev/null
108#   dvips -R -q -o bzip-manual.ps *.dvi
109  ;;
110
111  *)
112  usage
113  ;;
114esac
115