Skip to content

Instantly share code, notes, and snippets.

@zbyhoo
Created February 3, 2011 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbyhoo/809353 to your computer and use it in GitHub Desktop.
Save zbyhoo/809353 to your computer and use it in GitHub Desktop.
Script converting gcc output (warning and errors) to "some kind" of xml format.
#!/usr/bin/perl -w
use strict;
my $tag_main = "gcc_issues";
my $tag_total = "total";
my $tag_issue = "issue";
my $tag_count = "count";
my $tag_file = "file";
my $tag_line = "line";
my $tag_type = "type";
my $tag_msg = "message";
if (@ARGV != 2)
{
print "Wrong number of arguments.\n";
print "Usage: warnings.pl <build_file> <xml_file>\n";
print " build_file - file containg output from build process\n";
print " xml_file - output file\n";
exit 1;
}
my $build_out_file = $ARGV[0];
my $xml_out_file = $ARGV[1];
my $output = `cat $build_out_file | grep "warning:" | sort | uniq -c | sort -nr | awk '{print \$0}{total+=1}END{print total}'`;
my @lines = split(/\n/, $output);
my $total = pop @lines;
open my $xml_file, "> $xml_out_file" or die "unable to create file: $xml_out_file";
print $xml_file "<$tag_main $tag_total=\"$total\">\n";
foreach my $line (@lines)
{
if ($line =~ /^\s+(\d+)\s+(\S+):(\d+):\s+(\S+):\s+(.*)/)
{
&print_xml($4, $1, $2, $3, $5);
}
elsif ($line =~ /^\s+(\d+)\s+(\S+):\s+(\S+):\s+(.*)/)
{
&print_xml($3, $1, $2, "", $4);
}
}
print $xml_file "</$tag_main>\n";
close $xml_file;
sub print_xml
{
my ($type, $count, $file, $line, $msg) = @_;
print $xml_file " <$tag_issue $tag_type=\"$type\" $tag_count=\"$count\" $tag_file=\"$file\" $tag_line=\"$line\" $tag_msg=\"$msg\" />\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment