Merge branch 'dev'
[libcds.git] / tools / brush_cds.pl
1 #!/usr/bin/perl\r
2 \r
3 my $nTabsFound = 0;\r
4 \r
5 brush() ;\r
6 \r
7 print "Tabs found: $nTabsFound\n" ;\r
8 print "Done\n" ;\r
9 \r
10 exit ;\r
11 \r
12 sub brush() \r
13 {\r
14         processDir( "../cds" ) ;\r
15         processDir( "../src" ) ;\r
16         processDir( "../tests/test-hdr" ) ;\r
17         processDir( "../tests/unit" ) ;\r
18         processDir( "../tests/cppunit" ) ;\r
19 }\r
20 \r
21 sub processDir( $ )\r
22 {\r
23         my $dirName = shift ;\r
24         print "Process $dirName directory...\n";\r
25         \r
26         opendir(my $dh, $dirName) || die "can't opendir $dirName: $!";\r
27     my @files = grep { /^[^\.]/ } readdir($dh);\r
28     closedir $dh;\r
29         \r
30         foreach my $file ( @files ) {\r
31                 if ( -d "$dirName/$file" ) {\r
32                         processDir("$dirName/$file")    ;\r
33                 }\r
34                 elsif ( $file =~ /\.(h|cpp)$/ ) {\r
35                         processFile( "$dirName/$file" ) ;\r
36                 }\r
37         }\r
38 }\r
39 \r
40 sub processFile( $ ) \r
41 {\r
42         my $file = shift        ;\r
43 \r
44         \r
45         if ( open( my $fh, $file )) {\r
46                 binmode $fh     ;\r
47                 my $str = ''            ;\r
48                 while (<$fh>) {\r
49                         $nTabsFound += $_ =~ s/\t/    /g;\r
50                         $_ =~ s/\s+$//  ;\r
51                         $_ =~ s/\s+;$/;/;\r
52                         $str .= $_      ;\r
53                         $str .= "\n"    ;\r
54                 }\r
55                 close $fh       ;\r
56                 \r
57                 if ( open( my $fh, ">$file" )) {\r
58                         binmode $fh     ;\r
59                         print $fh $str  ;\r
60                         close $fh               ;\r
61                 }\r
62         }\r
63 }\r
64 \r
65 \r
66 \r