[plug] Save a soul from scripting insanity...
ryan at is.as.geeky.as
ryan at is.as.geeky.as
Tue Aug 13 21:40:56 WST 2002
Slight revision as the last one didn't handle more than 2 occurances on the
one line - this new one handles as many as you can throw at is - pity i
didn't also fix all the other errors i haven't noticed yet :)
NEW ONE ===================================
#!/usr/bin/perl
use strict;
use File::Find;
if ($ARGV[0] eq '') {
print "Must specify directory to search as arguement\n";
exit;
}
my @files;
sub eachFile {
if (-e $_) { push @files, $File::Find::name; }
}
find (\&eachFile, $ARGV[0]);
my @lines;
my @found;
my $line_open = 0;
my $split_line;
foreach my $file (@files) {
open(INFILE,"<$file") or die "Can't open input file $file - $!";
@lines = <INFILE>;
for (0..scalar(@lines)) {
# catch normal and broken lines
if ($lines[$_] =~ /\s{0,}Translator\.translate\(/) {
# split line?
if ($lines[$_] =~ /.+\"\s{0,}\+\s{0,}\n$/ && !$line_open) {
$line_open = 1;
$split_line = $lines[$_];
} else {
# not a split line, is it a multiple call line ?
if ($lines[$_] =~
/(Translator\.translate\(\".+\)[\;|\,]\s{0,}Translator\.translate\(){1,}/) {
$lines[$_] =~ s/\n//g;
$lines[$_] =~ s/^\s{0,}//;
my @temp = split(/Translator\.translate/,
$lines[$_]);
splice(@found,scalar(@found),scalar(@temp), at temp);
} else {
# not a multiple line call
$lines[$_] =~ s/\n//g;
$lines[$_] =~ s/^\s{0,}.{0,}Translator\.translate//;
splice(@found,scalar(@found),0,$lines[$_]);
}
}
}
if ($line_open && $lines[$_] !~ /\s{0,}Translator\.translate\(/) {
$split_line .= $lines[$_];
if ($lines[$_] =~ /\)\;/) {
$line_open = 0;
$split_line =~ s/\"\s{0,}\+\s{0,}\n\s+\"//g;
$split_line =~ s/\n//g;
$split_line =~ s/^\s{0,}Translator\.translate//;
splice(@found,scalar(@found),1,$split_line);
};
}
}
}
foreach my $output (@found) {
if ($output =~ /^\(\"/) {
$output =~ s/\("((?:\\["\\]|[^"])*)".{0,}\)+([;|,])/$1/;
$output =~ s/(\,\d{0,}){0,}$//g;
print "$output\n";
}
}
=============================================================
Ryan
More information about the plug
mailing list