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
|
#!/usr/bin/perl
use strict;
use warnings;
if ( $#ARGV + 1 < 1 ) {
print STDERR "usage: check-python-format.pl <filename>\n";
exit 1;
}
open(FILE, "<". $ARGV[0]);
my $line_nr=0;
my $line;
while ( <FILE> ){
$line = $_;
$line_nr++;
if ( $line =~ m!, python-brace-format! && $line !~ m!, fuzzy! ){
$line_nr += 2;
my $line1 = <FILE>;
my $line2_read = <FILE>;
my $line2 = "";
while ( $line2_read !~ m!^$! ){
$line2_read =~ s!\s*$!!;
$line2 .= $line2_read;
$line2_read = <FILE>;
$line_nr++;
}
#print "$line2\n";
if ( $line2 =~ m!^msgstr\s*""\s*$! ){
next;
}
while ( $line1 =~ m!\{([^}]+)\}!g ){
my $format = $1;
#print "$format\n";
if ( $line2 !~ m/\{$format\}/ ){
print "Problems in line $line_nr.\n";
}
}
}
}
close(FILE)
|