Skip to content
Snippets Groups Projects
Commit 7b2e8ec2 authored by Andre Maroneze's avatar Andre Maroneze
Browse files

[Dev] move and improve word duplicates detection script

parent 4728577a
No related branches found
No related tags found
No related merge requests found
...@@ -14,21 +14,21 @@ if (!@ARGV) { ...@@ -14,21 +14,21 @@ if (!@ARGV) {
while (1) { while (1) {
my $FileName = shift @ARGV ; my $FileName = shift @ARGV ;
# Exit code = number of duplicates found. # Exit code = number of duplicates found.
exit $DupCount if (!$FileName) ; exit $DupCount if (!$FileName) ;
open FILE, $FileName or die $!; open FILE, $FileName or die $!;
my $LastWord = "" ; my $LastWord = "" ;
my $LineNum = 0 ; my $LineNum = 0 ;
while (<FILE>) { while (<FILE>) {
chomp ; chomp ;
$LineNum ++ ; $LineNum ++ ;
my @words = split (/(\W+)/) ; my @words = split (/(\W+)/) ;
foreach my $word (@words) { foreach my $word (@words) {
# Skip spaces: # Skip spaces:
next if $word =~ /^\s*$/ ; next if $word =~ /^\s*$/ ;
...@@ -38,9 +38,25 @@ while (1) { ...@@ -38,9 +38,25 @@ while (1) {
$LastWord = "" ; $LastWord = "" ;
next ; next ;
} }
# Found a dup? # Skip numbers
if (lc($word) eq lc($LastWord)) { if ($word =~ /^\d+$/) {
$LastWord = "" ;
next ;
}
# Found a dup?
# note: some words are ignored, such as "long long",
# or some variable/field names
if ($word eq $LastWord && length($word) >= 3 &&
!($word eq "lexbuf") &&
!($word eq "ofs") &&
!($word eq "addr") &&
!($word eq "ros") &&
!($word eq "end") &&
!($word eq "args") &&
!($word eq "pos") &&
!($word eq "long")) {
print "$FileName:$LineNum $word\n" ; print "$FileName:$LineNum $word\n" ;
$DupCount ++ ; $DupCount ++ ;
} # Thanks to Sean Cronin for tip on case. } # Thanks to Sean Cronin for tip on case.
...@@ -49,7 +65,6 @@ while (1) { ...@@ -49,7 +65,6 @@ while (1) {
$LastWord = $word ; $LastWord = $word ;
} }
} }
close FILE ; close FILE ;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment