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