# manip pour imprimer des vers

use strict;
use warnings;

sub markItal($){ #arg. txt
my ($txt) = @_;

	my $erd = '<hi rend=\"I\">(.*? \d{4} : )<\/hi><\/p>';
	$txt =~ s/$erd/<date>$1<\/date><\/p>/g;

	my $eri = '<hi rend=\"I\">(.*?)<\/hi>';
	$txt =~ s/$eri/XXX$1YYY/g;
	
	return $txt;
}#mark

sub demarkItal($){ #arg. txt
my ($txt) = @_;

	my $eri = 'XXX(.*?)YYY';
	$txt =~ s/$eri/<hi rend=\"I\">$1<\/hi>/g;
	
	my $erl = '<ligne>\n(.*?)<\/ligne>';
	$txt =~ s/$erl/<ligne>$1<\/ligne>/g;
	
	return $txt;
}#demark

open(ENTREE1, "<:utf8", "$ARGV[0]");
my @tabl = <ENTREE1>;
my $txt = join ('', @tabl);
close(ENTREE1);

open(SORTIE1, ">:utf8", "$ARGV[1]");
print(SORTIE1 markItal($txt));
close(SORTIE1);

`xsltproc lignes.xsl $ARGV[1] > $ARGV[2]`;

open(ENTREE2, "<:utf8", "$ARGV[2]");
@tabl = <ENTREE2>;
$txt = join ('', @tabl);
close(ENTREE2);

open(SORTIE2, ">:utf8", "$ARGV[3]");
print(SORTIE2 demarkItal($txt));
close(SORTIE2);
