format.pl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/perl -w
  2. #
  3. # ------------------------------------------------------------------
  4. # This file is part of bzip2/libbzip2, a program and library for
  5. # lossless, block-sorting data compression.
  6. #
  7. # bzip2/libbzip2 version 1.0.6 of 6 September 2010
  8. # Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
  9. #
  10. # Please read the WARNING, DISCLAIMER and PATENTS sections in the
  11. # README file.
  12. #
  13. # This program is released under the terms of the license contained
  14. # in the file LICENSE.
  15. # ------------------------------------------------------------------
  16. #
  17. use strict;
  18. # get command line values:
  19. if ( $#ARGV !=1 ) {
  20. die "Usage: $0 xml_infile xml_outfile\n";
  21. }
  22. my $infile = shift;
  23. # check infile exists
  24. die "Can't find file \"$infile\""
  25. unless -f $infile;
  26. # check we can read infile
  27. if (! -r $infile) {
  28. die "Can't read input $infile\n";
  29. }
  30. # check we can open infile
  31. open( INFILE,"<$infile" ) or
  32. die "Can't input $infile $!";
  33. #my $outfile = 'fmt-manual.xml';
  34. my $outfile = shift;
  35. #print "Infile: $infile, Outfile: $outfile\n";
  36. # check we can write to outfile
  37. open( OUTFILE,">$outfile" ) or
  38. die "Can't output $outfile $! for writing";
  39. my ($prev, $curr, $str);
  40. $prev = ''; $curr = '';
  41. while ( <INFILE> ) {
  42. print OUTFILE $prev;
  43. $prev = $curr;
  44. $curr = $_;
  45. $str = '';
  46. if ( $prev =~ /<programlisting>$|<screen>$/ ) {
  47. chomp $prev;
  48. $curr = join( '', $prev, "<![CDATA[", $curr );
  49. $prev = '';
  50. next;
  51. }
  52. elsif ( $curr =~ /<\/programlisting>|<\/screen>/ ) {
  53. chomp $prev;
  54. $curr = join( '', $prev, "]]>", $curr );
  55. $prev = '';
  56. next;
  57. }
  58. }
  59. print OUTFILE $curr;
  60. close INFILE;
  61. close OUTFILE;
  62. exit;