#!/bin/sh
exec ${PERL-perl} -wSx $0 ${1+"$@"}
#!perl

# $Id: stripcr,v 1.2 2000/12/03 11:17:23 friedman Exp $

# TODO: make numbered backup files of original.

use Symbol;

sub main
{
  my $file;
  my $fh = gensym;
  foreach $file (@ARGV)
    {
      print $file, "\n";
      open ($fh, "+<" . $file) || die "open: $file: $!";
      my @statinfo = stat $fh;
      my $buf = "";
      sysread ($fh, $buf, $statinfo[7]);
      $buf =~ s/\r$//mgo;
      seek $fh, 0, 0;
      truncate $fh, 0;
      syswrite ($fh, $buf, $statinfo[7]);
      close ($fh);
      utime $statinfo[8], $statinfo[9], $file;
    }
}

main ();

# local variables:
# mode: perl
# eval: (auto-fill-mode 1)
# end:
