From 29316b23ba8cca3d6c562bfd5951112fe3fa7385 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 5 Feb 2014 01:13:16 +0000 Subject: [PATCH] Update c2english with -f force option, and hide certain errors --- PBot/VERSION.pm | 2 +- modules/c2english.pl | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 913fc166..968403d1 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,7 +13,7 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 478, + BUILD_REVISION => 479, BUILD_DATE => "2014-02-04", }; diff --git a/modules/c2english.pl b/modules/c2english.pl index bad92f57..65459f96 100755 --- a/modules/c2english.pl +++ b/modules/c2english.pl @@ -8,6 +8,11 @@ use Text::Balanced qw(extract_codeblock extract_delimited); my $code = join ' ', @ARGV; my $output; +my $force; +if($code =~ s/^-f\s+//) { + $force = 1; +} + $code =~ s/#include <([^>]+)>/\n#include <$1>\n/g; $code =~ s/#([^ ]+) (.*?)\\n/\n#$1 $2\n/g; $code =~ s/#([\w\d_]+)\\n/\n#$1\n/g; @@ -74,7 +79,7 @@ close $fh; my ($ret, $result) = execute(10, "gcc -std=c89 -pedantic -Werror -Wno-unused -fsyntax-only -fno-diagnostics-show-option code.c"); -if($ret != 0) { +if(not $force and $ret != 0) { $output = $result; $output =~ s/code\.c:\d+:\d+://g; @@ -129,9 +134,19 @@ if($ret != 0) { $output =~ s/= (-?\d+) ''/= $1/g; $output =~ s/, //g; $output =~ s/\s*error: expected ';' before 'return'//g; + $output =~ s/^\s+//; + $output =~ s/\s+$//; + $output =~ s/error: ISO C forbids nested functions\s+//g; - print "$output\n"; - exit 0; + # don't error about undeclared objects + $output =~ s/error: '[^']+' undeclared\s*//g; + + if(length $output) { + print "$output\n"; + exit 0; + } else { + $output = undef; + } } $output = `./c2e 2>/dev/null code.c` if not defined $output;