# Convert Mac CR to Windows CRLF for a single specified file in a directory.
#
# Notes:
# 1. This script reads in the entire file in one gulp, so it's not appropriate
# for use with very large files.
#
# 2. Be sure you only specify a TEXT file. If you specify a binary, the script
# may well decide it needs converting, which can corrupt the binary.

use strict;

my $fixFile = 'C:\Astell-THQ\wikitest\license.txt';                # This is the file to fix.

if ( not -e $fixFile )
{
   print "ERROR: $fixFile could not be found! Check out what's wrong. \n";
} elsif ( not -f $fixFile )
{
   print "ERROR: $fixFile says it is not a file! Check out what's wrong. \n";
} else
{
   open( IN, "$fixFile" );
   my $content = ;
   close( IN );

   unless( $content =~ /\n/ )
   {
      print "Converting Mac CR to Windows CRLF in $fixFile \n";

      $content =~ s/\r/\n/g ;                     # Convert only if native \n not found.

      open( OUT, ">$fixFile" ) or die( "Could not open $fixFile for writing: $!" );
      print OUT "$content";
      close( OUT );
      print "$fixFile converted \n";
   } else
   {
      print "No Mac CR found in file. No conversion done. \n";
   }
}