#!/usr/bin/perl
#use warnings;

print "\n"."="x79;
print "\nminiprogram: Zawgyi test program (Zawgyi 1.01)";
print "\n"."="x79;

print "\n\nDIR WITH BURMESE (eg. country/burma): ";
$dir = <STDIN>;
chomp($dir);
opendir(DIR, $dir) or die "Cannot open dir: $dir";

print "\nSAVE THE RESULTS INTO A FILE? (Y/N): ";
$save = <STDIN>;
chomp($save);

if ($save eq "y" or $save eq "Y" ) {

      print "\nRESULTS INTO (eg. local/export.txt): ";
      $export = <STDIN>;
      chomp($export);
      open(INFO,">:utf8",$export) or die "Cannot open file $export.";

      print INFO "="x50;
      print INFO "\nTESTING FOR ZAWGYI IN: \n$dir";
      print INFO "\n"."="x50;
      
      print INFO "\n"."-"x50;
      print INFO "\nFILE\tZAWGYI (NO/YES)";
      print INFO "\n"."-"x50;
      
}

print "\n"."-"x79;
print "\nFILE\tZAWGYI (NO/YES)";
print "\n"."-"x79;


while (my $file = readdir(DIR)) { #open directory
       next unless ($file =~ m/\.txt$/); #open each file.txt

       open(INPUT,"<:utf8",$dir."/".$file) or die "Cannot open file $file.";
       my $f=0;
       
       while(<INPUT>) {   
          chomp($_);                
          
          if ($f == 0){
            if ($_ =~/[\x{105A}-\x{1097}]/) {
                if ($save eq "y" or $save eq "Y" ) {
                  print INFO "\n$file\tYES";
                }
                print "\n$file\tYES";
                $f=1;
                }
          }
                
       }
       
       if ($f == 0) {
                if ($save eq "y" or $save eq "Y" ) {
                  print INFO "\n$file\tNO";
                }
                print "\n$file\tNO";
       }
       
       close INPUT;
    }
    
closedir DIR;
close INFO;

print "\n"."-"x79;
print "\n\n";

if ($save eq "y" or $save eq "Y" ) {
  print "FILE EXPORTED\n";
}
print "DONE (press ENTER to close)\n";
<STDIN>;
