xmlproc.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. usage() {
  18. echo '';
  19. echo 'Usage: xmlproc.sh -[option] <filename.xml>';
  20. echo 'Specify a target from:';
  21. echo '-v verify xml file conforms to dtd';
  22. echo '-html output in html format (single file)';
  23. echo '-ps output in postscript format';
  24. echo '-pdf output in pdf format';
  25. exit;
  26. }
  27. if test $# -ne 2; then
  28. usage
  29. fi
  30. # assign the variable for the output type
  31. action=$1; shift
  32. # assign the output filename
  33. xmlfile=$1; shift
  34. # and check user input it correct
  35. if !(test -f $xmlfile); then
  36. echo "No such file: $xmlfile";
  37. exit;
  38. fi
  39. # some other stuff we will use
  40. OUT=output
  41. xsl_fo=bz-fo.xsl
  42. xsl_html=bz-html.xsl
  43. basename=$xmlfile
  44. basename=${basename//'.xml'/''}
  45. fofile="${basename}.fo"
  46. htmlfile="${basename}.html"
  47. pdffile="${basename}.pdf"
  48. psfile="${basename}.ps"
  49. xmlfmtfile="${basename}.fmt"
  50. # first process the xmlfile with CDATA tags
  51. ./format.pl $xmlfile $xmlfmtfile
  52. # so the shell knows where the catalogs live
  53. export XML_CATALOG_FILES=/etc/xml/catalog
  54. # post-processing tidy up
  55. cleanup() {
  56. echo "Cleaning up: $@"
  57. while [ $# != 0 ]
  58. do
  59. arg=$1; shift;
  60. echo " deleting $arg";
  61. rm $arg
  62. done
  63. }
  64. case $action in
  65. -v)
  66. flags='--noout --xinclude --noblanks --postvalid'
  67. dtd='--dtdvalid http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd'
  68. xmllint $flags $dtd $xmlfmtfile 2> $OUT
  69. egrep 'error' $OUT
  70. rm $OUT
  71. ;;
  72. -html)
  73. echo "Creating $htmlfile ..."
  74. xsltproc --nonet --xinclude -o $htmlfile $xsl_html $xmlfmtfile
  75. cleanup $xmlfmtfile
  76. ;;
  77. -pdf)
  78. echo "Creating $pdffile ..."
  79. xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
  80. pdfxmltex $fofile >$OUT </dev/null
  81. pdfxmltex $fofile >$OUT </dev/null
  82. pdfxmltex $fofile >$OUT </dev/null
  83. cleanup $OUT $xmlfmtfile *.aux *.fo *.log *.out
  84. ;;
  85. -ps)
  86. echo "Creating $psfile ..."
  87. xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
  88. pdfxmltex $fofile >$OUT </dev/null
  89. pdfxmltex $fofile >$OUT </dev/null
  90. pdfxmltex $fofile >$OUT </dev/null
  91. pdftops $pdffile $psfile
  92. cleanup $OUT $xmlfmtfile $pdffile *.aux *.fo *.log *.out
  93. # passivetex is broken, so we can't go this route yet.
  94. # xmltex $fofile >$OUT </dev/null
  95. # xmltex $fofile >$OUT </dev/null
  96. # xmltex $fofile >$OUT </dev/null
  97. # dvips -R -q -o bzip-manual.ps *.dvi
  98. ;;
  99. *)
  100. usage
  101. ;;
  102. esac