Для gfortran вы можете использовать этот perl-скрипт, аргумент "build_log" должен быть выводом gfortran -Wunused (или что-то еще, что вы получаете предупреждения о неиспользуемых переменных):
#!/usr/bin/perl
use strict;
my $build_log = shift;
open my $build_filehandle, "<", $build_log;
my $file;
my $line_to_edit;
my $col_to_edit;
my $word_to_remove;
my @files;
my @line_nums;
my @unused_variables;
my $line;
my $line_number = 0;
while($line = <$build_filehandle>)
{
$line_number++;
chomp($line);
if($line =~ m/([^:]*):(\d+)\.(\d+):/)
{
$file = $1;
$line_to_edit = $2;
$col_to_edit = $3;
}
elsif($line =~ m/Warning: Unused variable '([^']*)'/)
{
$word_to_remove = $1;
push(@files, $file);
push(@line_nums, $line_to_edit);
push(@unused_variables, $word_to_remove);
}
}
close($build_filehandle);
# sort [file, line_num, word_to_remove] by files then line_nums then word_to_remove
my @merged_columns;
for(my $i = 0; $i < scalar(@files); $i++) # loop over all the replacements to be made
{
push(@merged_columns, [$files[$i],$line_nums[$i],$unused_variables[$i]]);
}
# if sort is stable, sort by line_nums, then files
sub by_file_then_line
{
$a->[0] cmp $b->[0] || # by file
$a->[1] <=> $b->[1];
}
my @sorted_by_line_nums = sort by_file_then_line @merged_columns;
for(my $i = 0; $i < scalar(@files); $i++) # loop over all the replacements to be made
{
$files[$i] = $sorted_by_line_nums[$i][0];
$line_nums[$i] = $sorted_by_line_nums[$i][1];
$unused_variables[$i] = $sorted_by_line_nums[$i][2];
}
my $print_line = 0;
my $last_file = 'null';
my $replacement_filehandle;
for(my $i = 0; $i < scalar(@files); $i++) # loop over all the replacements to be made
{
if($files[$i] ne $last_file)
{
if(defined($replacement_filehandle))
{
# dump the line we were working on
if($print_line == 1) # print the line that we were processing
{
print("$line\n");
$print_line = 0;
}
# dump the rest of the file
while($line = <$replacement_filehandle>)
{
chomp($line);
print("$line\n");
}
# then close it
close($replacement_filehandle);
}
open $replacement_filehandle, "+<", $files[$i];
$line_number = 0;
}
$last_file = $files[$i];
# here we are on the right file, but might need to advance to the correct location
while($line_number < $line_nums[$i]) # might not even enter
{
if($print_line == 1) # print the line that we were processing
{
print("$line\n");
$print_line = 0;
}
$line = <$replacement_filehandle>;
$line_number++;
chomp($line);
if($line_number < $line_nums[$i])
{
print("$line\n");
}
}
$print_line = 1;
if($line =~ m/^\s+type/i) # don't bother with types, their naming and form is too messed up to make it worth the effort, and there aren't that many
{
next;
}
$line =~ s/,/, /g; # add spaces after commas
$line =~ s/,\s+/, /g; # collapse double commas
# case followed by stuff in parens
$line =~ s/ ${unused_variables[$i]}\([^\)]*\),?//i;
# case followed by comma
$line =~ s/ ${unused_variables[$i]},//i;
# case end of line
$line =~ s/ ${unused_variables[$i]}\s*$//i;
# remove trailing commas
$line =~ s/,\s*$//;
# collapse double commas
$line =~ s/,\s*,/,/;
# remove empty memory declaration lines
# ie, if it does not have two sets of word characters kill it off
if(! ($line =~ m/\w[^A-Za-z\*]+\w/))
{
$line = '';
}
}
if(defined($replacement_filehandle))
{
# dump the line we were working on
if($print_line == 1) # print the line that we were processing
{
print("$line\n");
$print_line = 0;
}
# dump the rest of the file
while($line = <$replacement_filehandle>)
{
chomp($line);
print("$line\n");
}
# then close it
close($replacement_filehandle);
}
Очевидно, вы должны посмотреть на источник и убедиться, что он делает то, что вы хотите. Но, грубо говоря, он читает выходные данные компилятора и удаляет переменную, на которую компилятор жалуется, в строке, на которую он жалуется.