#!/usr/local/bin/perl

$INPUTFILE = $ARGV[0];
$TRANSFORM = "$INPUTFILE".".tmp_M";

open(THEOUTPUT,">$TRANSFORM");

$flag_check = 1;

while(<>) {
        # CARRIAGE RETURN
	chop;

        # THE ^M
	$test_M = chop;

        # CHECK TO SEE THAT FILE HAS ^M ON FIRST LINE
        if ($flag_check==1)
        {
	  if (ord($test_M)!=13) 
          {
	   print $INPUTFILE," : Not a \^M file\n";
           system("rm $TRANSFORM");
	   exit(0);
          }
          $flag_check = 0;
        }
	print THEOUTPUT $_, "\n";
}

close(THEOUTPUT);

rename($INPUTFILE,"$INPUTFILE".".orig");
rename($TRANSFORM,$INPUTFILE);