#!/usr/bin/perl -w

use strict;
use Getopt::Std;
use MARC::Charset; # version 0.6
#use MARC::Charset 'marc8_to_utf8'; # version 1.33
use Unicode::Normalize;

my %options = ();
getopts("i:o:",\%options);
my $in = $options{i};
my $out = $options{o};
if (!$in || !$out) {
    print "Usage: $0 -i INPUT_FILE -o OUTPUT_FILE\n";
    exit 1;
}
elsif (! -f $in) {
    print "File not found: $in\n";
    exit 2;
}

$| = 1;
# Codes start...

my $cs = MARC::Charset->new();

open IN, "<$in";
open OUT, ">:utf8", "$out";

while (<IN>) {
    chomp;
    print OUT NFC($cs->to_utf8($_)), "\n";
    #print OUT NFC(marc8_to_utf8($_)), "\n";
}

close OUT;
close IN;

# Codes end.

exit 0;
