use strict;
use utf8;

my $infilename = shift;
my $outfilename = shift;
my $lang = shift; # optional

open(my $infile,  "<:utf8", $infilename) or die("Cannot read " . $infilename . "\n");
open(my $outfile,  ">:utf8", $outfilename) or die("Cannot write " . $outfilename . "\n");
while (my $line = <$infile>) {


if ($lang eq "eo") { # Esperanto x-convention

	$line =~ s/Ĉ/Cx/g;
	$line =~ s/Ĝ/Gx/g;
	$line =~ s/Ĥ/Hx/g;
	$line =~ s/Ĵ/Jx/g;
	$line =~ s/Ŝ/Sx/g;
	$line =~ s/Ŭ/Ux/g;

	$line =~ s/ĉ/cx/g;
	$line =~ s/ĝ/gx/g;
	$line =~ s/ĥ/hx/g;
	$line =~ s/ĵ/jx/g;
	$line =~ s/ŝ/sx/g;
	$line =~ s/ŭ/ux/g;

}


# Removing accent marks


#	$line =~ s/Á/A/g;
#	$line =~ s/Ä/A/g;
	$line =~ s/Č/C/g;
	$line =~ s/Ď/D/g;
#	$line =~ s/É/E/g;
	$line =~ s/Ě/E/g;
#	$line =~ s/Í/I/g;
	$line =~ s/Ĺ/L/g;
	$line =~ s/Ľ/L/g;
	$line =~ s/Ň/N/g;
#	$line =~ s/Ó/O/g;
#	$line =~ s/Ö/O/g;
	$line =~ s/Ő/O/g;
#	$line =~ s/Ô/O/g;
	$line =~ s/Ŕ/R/g;
	$line =~ s/Ř/R/g;
	$line =~ s/Š/S/g;
	$line =~ s/Ť/T/g;
#	$line =~ s/Ú/U/g;
#	$line =~ s/Ü/U/g;
	$line =~ s/Ű/U/g;
	$line =~ s/Ů/U/g;
#	$line =~ s/Ý/Y/g;
	$line =~ s/Ž/Z/g;

#	$line =~ s/á/a/g;
#	$line =~ s/ä/a/g;
	$line =~ s/č/c/g;
	$line =~ s/ď/d/g;
#	$line =~ s/é/e/g;
	$line =~ s/ě/e/g;
#	$line =~ s/í/i/g;
	$line =~ s/ĺ/l/g;
	$line =~ s/ľ/l/g;
	$line =~ s/ň/n/g;
#	$line =~ s/ó/o/g;
#	$line =~ s/ö/o/g;
	$line =~ s/ő/o/g;
#	$line =~ s/ô/o/g;
	$line =~ s/ŕ/r/g;
	$line =~ s/ř/ř/g;
	$line =~ s/š/s/g;
	$line =~ s/ť/t/g;
#	$line =~ s/ú/u/g;
#	$line =~ s/ü/u/g;
	$line =~ s/ű/u/g;
	$line =~ s/ů/u/g;
#	$line =~ s/ý/y/g;
	$line =~ s/ž/z/g;


print $outfile $line;
}
