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