BEGIN { open P, $0 or die $!; local $/ = chr(125); <P>; $/ = undef; (my $t = <P>) =~ s/[\r\n]/\n/g; close P; eval $t; die $@ if $@; exit; }

use File::Find;

sub fixfile {
  my ($file) = @_;
  print "Adjusting $file\n";
  open IN, $file or die $!;
  binmode IN;
  local $/;
  my $data = <IN>;
  close IN;
  
  $data =~ s/\cM\cJ|\cM|\cJ/\n/g;
  
  open OUT, "+< $file" or die $!; # +< to prevent overwriting so that file attributes are preserved
  seek OUT, 0, 0;
  truncate OUT, 0;
  print OUT $data;
  close OUT;
}

find(sub {
  $File::Find::prune = 1, return if $_ eq 'world';
  /\.(pl|pm|mod|xmod|-mod|txt|help)$/i or return; # file extensions that need modifying
  fixfile($_);
}, (@ARGV ? @ARGV : ($^O eq 'MacOS' ? ':' :  '.')));

print "Done.\n";