3 # $Id: dos2unix.pl,v 1.2 2007/04/02 20:29:20 gumpu Exp $
5 # Convert all files to the unix-line-end convention.
6 # This ensures that all files in the ROBODoc package
7 # follow the same convention.
21 if ( !( $file = IO::File->new($path, "r") ) ) {
22 print "Can't open $path to read : $!\n";
24 # Open in binmode otherwise Perl will do the cr/lf for
27 my @file_data = <$file>;
29 if ( !( grep { /\r/ } @file_data ) ) {
30 print "$path is OK\n";
33 print "$path contains CR/LF\n";
34 if ( $mode eq "test" ) {
35 print "$path contains CR/LF\n";
37 print "Fixing: $path\n";
38 map { s/\r//g; } (@file_data);
39 $file = IO::File->new("> $path") or die "Can't open $path to write : $!";
41 print $file @file_data;
54 my $dir = IO::Dir->new($dirname) or die "Can't open $dirname : $!";
55 my @files = $dir->read();
58 foreach my $filename ( sort @files ) {
59 $path = "$dirname/$filename";
65 # Also fix any subdirectories.
66 foreach my $subdirname ( sort @files ) {
67 $path = "$dirname/$subdirname";
69 unless ( $subdirname =~ m/^\.+$/ ) {
70 scan_directory( $path, $mode );
78 my $out = IO::File->new(">fl.txt") or die "can't open fl.txt : $!";
79 scan_directory( ".", "test" );