Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 45 lines (34 sloc) 0.727 kb
878da09 Lewin Bormann Init
authored
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use utf8;
6 use File::Copy;
7
9844c72 Lewin Bormann Possibility for more than one file
authored
8 die("Usage: whitespace.pl <FILE>\n") if scalar @ARGV == 0;
878da09 Lewin Bormann Init
authored
9
b11e19e Lewin Bormann Improved recognizing patterns and some whitespace errors
authored
10 my $pat_emptyline = qr/^(\t| )+$/;
11 my $pat_endofline = qr/^(.+?)( |\t)+$/;
878da09 Lewin Bormann Init
authored
12
9844c72 Lewin Bormann Possibility for more than one file
authored
13 foreach my $actual_file (@ARGV)
878da09 Lewin Bormann Init
authored
14 {
b2805a0 Lewin Bormann New indentation (4 spaces) and check for directory
authored
15 next if -d $actual_file;
16 open(my $tempfile,">",".white_tmp");
17 open(my $file,"<",$actual_file);
878da09 Lewin Bormann Init
authored
18
b2805a0 Lewin Bormann New indentation (4 spaces) and check for directory
authored
19 my $i = 0;
9844c72 Lewin Bormann Possibility for more than one file
authored
20
b2805a0 Lewin Bormann New indentation (4 spaces) and check for directory
authored
21 while ( my $line = <$file> )
22 {
23 $i++;
24
25 if ( $line =~ $pat_emptyline )
26 {
27 #print $i." ".$line;
28 print $tempfile "\n";
29 } elsif ( $line =~ $pat_endofline )
30 {
31 print $tempfile $1 . "\n";
32 } else
878da09 Lewin Bormann Init
authored
33 {
b2805a0 Lewin Bormann New indentation (4 spaces) and check for directory
authored
34 print $tempfile $line;
878da09 Lewin Bormann Init
authored
35 }
b2805a0 Lewin Bormann New indentation (4 spaces) and check for directory
authored
36 }
878da09 Lewin Bormann Init
authored
37
b2805a0 Lewin Bormann New indentation (4 spaces) and check for directory
authored
38 close($file);
39 close($tempfile);
878da09 Lewin Bormann Init
authored
40
b2805a0 Lewin Bormann New indentation (4 spaces) and check for directory
authored
41 copy(".white_tmp",$actual_file);
878da09 Lewin Bormann Init
authored
42
b2805a0 Lewin Bormann New indentation (4 spaces) and check for directory
authored
43 unlink(".white_tmp");
9844c72 Lewin Bormann Possibility for more than one file
authored
44 }
Something went wrong with that request. Please try again.