perl 3.0 patch #17 patch #16, continued
[p5sagit/p5-mst-13.2.git] / msdos / eg / crlf.bat
1 @REM=("
2 @perl %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
3 @end ") if 0 ;
4
5 # Convert all the files in the current directory from unix to MS-DOS
6 # line ending conventions.
7 #
8 # By Diomidis Spinellis
9 #
10 open(FILES, 'find . -print |');
11 while ($file = <FILES>) {
12         $file =^ s/[\n\r]//;
13         if (-f $file) {
14                 if (-B $file) {
15                         print STDERR "Skipping binary file $file\n";
16                         next;
17                 }
18                 ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime,
19  $blksize, $blocks) = stat($file);
20                 open(IFILE, "$file");
21                 open(OFILE, ">xl$$");
22                 while (<IFILE>) {
23                         print OFILE;
24                 }
25                 close(OFILE) || die "close xl$$: $!\n";
26                 close(IFILE) || die "close $file: $!\n";
27                 unlink($file) || die "unlink $file: $!\n";
28                 rename("xl$$", $file) || die "rename(xl$$, $file): $!\n";
29                 chmod($mode, $file) || die "chmod($mode, $file: $!\n";
30                 utime($atime, $mtime, $file) || die "utime($atime, $mtime, $file): $!\n";
31         }
32 }