-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecursiveDos2Unix.pl
126 lines (108 loc) · 2.09 KB
/
RecursiveDos2Unix.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
require RecurseWork;
sub Reformat()
{
my $FileName = shift @_;
my $fd;
my $ligne;
my $contenu = '';
print STDERR "$FileName\n";
open( $fd, "<$FileName" ) or die "Could not open '$FileName'\n";
while( $ligne = <$fd> )
{
while( $ligne =~ /^(($ReplaceBy)*)($ToReplace)(.*)$/ )
{
$ligne = $1 . $ReplaceBy . $4;
}
$ligne =~ s/[\r\n\s]+$//g;
$contenu .= $ligne . '_#_#_#_#_';
}
close( $fd );
$contenu =~ s/(_#_#_#_#_)+$//;
if ( $ReverseMode == 0 )
{
$contenu =~ s/(_#_#_#_#_)/\n/g;
}
else
{
$contenu =~ s/(_#_#_#_#_)/\r\n/g;
}
open( $fd, ">$FileName" ) or die "Could not write to '$FileName'\n";
print $fd $contenu;
if ( $ReverseMode == 0 )
{
print $fd "\n";
}
else
{
print $fd "\r\n";
}
close( $fd );
}
sub WorkOnFile()
{
my $FileName = shift @_;
my $UserData = shift @_;
if ( $FileName =~ /\.(cpp|h|txt|xml|xsd|in\.scons)$/ )
{
&Reformat($FileName);
}
if ( $FileName =~ /^SConstruct|LICENCE|README|CHANGES|Doxyfile$/ )
{
&Reformat($FileName);
}
}
sub EnterDirectory()
{
my $DirName = shift @_;
my $UserData = shift @_;
my $TmpDirName;
if ( $DirName =~ /\.svn/ || $DirName =~ /VisualStudio.in|WorkingForOMiSCID|Spec|Xsd/ )
{
return 0;
}
foreach $TmpDirName ( keys %ToExclude )
{
if ( $DirName =~ /^$TmpDirName/ || $DirName =~ /^\.\/$TmpDirName/ )
{
return 0;
}
}
# print STDERR "$DirName is ok\n";
return 1;
}
$ToReplace = "\t";
$ReplaceBy = ' ';
$ReverseMode = 0;
@FolderToWorkOn = ();
$ParamPos = 0;
while ( defined $ARGV[$ParamPos] )
{
if ( $ARGV[$ParamPos] eq '-reverse' )
{
$ToReplace = ' ';
$ReplaceBy = "\t";
$ReverseMode = 1;
$ParamPos++;
next;
}
if ( $ARGV[$ParamPos] =~ /^-exclude\=(.+)$/ )
{
# print STDERR "$1 is excluded\n";
$ToExclude{$1} = 1;
$ParamPos++;
next;
}
push @FoldersToWorkOn, $ARGV[$ParamPos];
$ParamPos++;
}
foreach $item ( @FoldersToWorkOn )
{
if ( -d $item )
{
&RecurseWork::RecurseWork($item,'');
}
else
{
&WorkOnFile( $item );
}
}