mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 22:09:26 +01:00
compiler_vm:
Add compiler flags section to web-pasted output Clean up output section in web-pasted output Save cc-specific flags (-paste, -nomain, etc) to last-code
This commit is contained in:
parent
8d882a4240
commit
2720071dbd
@ -13,7 +13,7 @@ use warnings;
|
|||||||
# These are set automatically by the build/commit script
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 428,
|
BUILD_REVISION => 429,
|
||||||
BUILD_DATE => "2013-09-13",
|
BUILD_DATE => "2013-09-13",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,11 +18,12 @@ my $output = "";
|
|||||||
my $nooutput = 'No output.';
|
my $nooutput = 'No output.';
|
||||||
|
|
||||||
my $warn_unterminated_define = 0;
|
my $warn_unterminated_define = 0;
|
||||||
|
my $save_last_code = 0;
|
||||||
|
|
||||||
my %languages = (
|
my %languages = (
|
||||||
'C11' => "gcc -std=c11 -pedantic -Wall -Wextra (default)",
|
'C11' => "gcc -std=c11 -pedantic -Wall -Wextra -Wno-unused -Wfloat-equal -Wfatal_errors",
|
||||||
'C99' => "gcc -std=c99 -pedantic -Wall -Wextra",
|
'C99' => "gcc -std=c99 -pedantic -Wall -Wextra -Wno-unused -Wfloat-equal -Wfatal_errors",
|
||||||
'C89' => "gcc -std=c89 -pedantic -Wall -Wextra",
|
'C89' => "gcc -std=c89 -pedantic -Wall -Wextra -Wno-unused -Wfatal_errors",
|
||||||
);
|
);
|
||||||
|
|
||||||
my %preludes = (
|
my %preludes = (
|
||||||
@ -147,22 +148,6 @@ my @last_code;
|
|||||||
|
|
||||||
print " code: [$code]\n" if $debug;
|
print " code: [$code]\n" if $debug;
|
||||||
|
|
||||||
my $lang = "C11";
|
|
||||||
$lang = uc $1 if $code =~ s/-lang=([^\b\s]+)//i;
|
|
||||||
|
|
||||||
my $input = "";
|
|
||||||
$input = $1 if $code =~ s/-(?:input|stdin)=(.*)$//i;
|
|
||||||
|
|
||||||
my $got_paste = undef;
|
|
||||||
$got_paste = 1 if $code =~ s/(?<=\s)*-paste\s*//i;
|
|
||||||
|
|
||||||
my $got_nomain = undef;
|
|
||||||
$got_nomain = 1 if $code =~ s/(?<=\s)*-nomain\s*//i;
|
|
||||||
|
|
||||||
my $args = "";
|
|
||||||
$args .= "$1 " while $code =~ s/^\s*(-[^ ]+)\s*//;
|
|
||||||
$args =~ s/\s+$//;
|
|
||||||
|
|
||||||
if(open FILE, "< last_code.txt") {
|
if(open FILE, "< last_code.txt") {
|
||||||
while(my $line = <FILE>) {
|
while(my $line = <FILE>) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
@ -575,12 +560,38 @@ if($code =~ m/^\s*(run|paste)\s*$/i) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open FILE, "> last_code.txt";
|
|
||||||
|
|
||||||
unless ($got_undo and not $got_changes) {
|
unless ($got_undo and not $got_changes) {
|
||||||
unshift @last_code, length $args ? $args . ' ' . $code : $code;
|
$save_last_code = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($got_undo and not $got_changes) {
|
||||||
|
print "$nick: $code\n";
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
my $lang = "C11";
|
||||||
|
$lang = uc $1 if $code =~ s/-lang=([^\b\s]+)//i;
|
||||||
|
|
||||||
|
my $input = "";
|
||||||
|
$input = $1 if $code =~ s/-(?:input|stdin)=(.*)$//i;
|
||||||
|
|
||||||
|
my $extracted_args = '';
|
||||||
|
|
||||||
|
my $got_paste = undef;
|
||||||
|
$got_paste = 1 and $extracted_args .= "-paste " if $code =~ s/(?<=\s)*-paste\s*//i;
|
||||||
|
|
||||||
|
my $got_nomain = undef;
|
||||||
|
$got_nomain = 1 and $extracted_args .= "-nomain " if $code =~ s/(?<=\s)*-nomain\s*//i;
|
||||||
|
|
||||||
|
my $args = "";
|
||||||
|
$args .= "$1 " while $code =~ s/^\s*(-[^ ]+)\s*//;
|
||||||
|
$args =~ s/\s+$//;
|
||||||
|
|
||||||
|
if($save_last_code) {
|
||||||
|
unshift @last_code, $extracted_args . (length $args ? $args . ' ' . $code : $code);
|
||||||
|
open FILE, "> last_code.txt";
|
||||||
|
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
foreach my $line (@last_code) {
|
foreach my $line (@last_code) {
|
||||||
last if(++$i > $MAX_UNDO_HISTORY);
|
last if(++$i > $MAX_UNDO_HISTORY);
|
||||||
@ -588,19 +599,8 @@ if($code =~ m/^\s*(run|paste)\s*$/i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
close FILE;
|
close FILE;
|
||||||
|
|
||||||
if($got_undo and not $got_changes) {
|
|
||||||
print "$nick: $code\n";
|
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# check to see if -flags were added by replacements
|
|
||||||
$lang = uc $1 if $code =~ s/-lang=([^\b\s]+)//i;
|
|
||||||
$input = $1 if $code =~ s/-(?:input|stdin)=(.*)$//i;
|
|
||||||
$args .= "$1 " while $code =~ s/^\s*(-[^ ]+)\s*//;
|
|
||||||
$args =~ s/\s+$//;
|
|
||||||
|
|
||||||
unless($got_run) {
|
unless($got_run) {
|
||||||
open FILE, ">> log.txt";
|
open FILE, ">> log.txt";
|
||||||
print FILE "------------------------------------------------------------------------\n";
|
print FILE "------------------------------------------------------------------------\n";
|
||||||
@ -611,7 +611,6 @@ unless($got_run) {
|
|||||||
my $found = 0;
|
my $found = 0;
|
||||||
my @langs;
|
my @langs;
|
||||||
foreach my $l (sort { uc $a cmp uc $b } keys %languages) {
|
foreach my $l (sort { uc $a cmp uc $b } keys %languages) {
|
||||||
#push @langs, sprintf(" %-30s => %s", $l, $languages{$l});
|
|
||||||
push @langs, sprintf("%s => %s", $l, $languages{$l});
|
push @langs, sprintf("%s => %s", $l, $languages{$l});
|
||||||
if(uc $lang eq uc $l) {
|
if(uc $lang eq uc $l) {
|
||||||
$lang = $l;
|
$lang = $l;
|
||||||
@ -760,7 +759,7 @@ if($lang eq 'C89' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') {
|
|||||||
my $has_main = 0;
|
my $has_main = 0;
|
||||||
|
|
||||||
my $prelude = '';
|
my $prelude = '';
|
||||||
while($precode =~ s/^\s*(#.*\n)//g) {
|
while($precode =~ s/^\s*(#.*\n{1,2})//g) {
|
||||||
$prelude .= $1;
|
$prelude .= $1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -908,30 +907,30 @@ if($output =~ m/^\s*$/) {
|
|||||||
$output =~ s/prog\.c://g;
|
$output =~ s/prog\.c://g;
|
||||||
}
|
}
|
||||||
|
|
||||||
$output =~ s/cc1: warnings being treated as errors//;
|
$output =~ s/(\d+:\d+:\s*)*cc1: warnings being treated as errors//;
|
||||||
$output =~ s/ \(first use in this function\)//g;
|
$output =~ s/(\d+:\d+:\s*)* \(first use in this function\)//g;
|
||||||
$output =~ s/error: \(Each undeclared identifier is reported only once.*?\)//msg;
|
$output =~ s/(\d+:\d+:\s*)*error: \(Each undeclared identifier is reported only once.*?\)//msg;
|
||||||
$output =~ s/ld: warning: cannot find entry symbol _start; defaulting to [^ ]+//;
|
$output =~ s/(\d+:\d+:\s*)*ld: warning: cannot find entry symbol _start; defaulting to [^ ]+//;
|
||||||
$output =~ s/error: (.*?) error/error: $1; error/msg;
|
$output =~ s/(\d+:\d+:\s*)*error: (.*?) error/error: $1; error/msg;
|
||||||
$output =~ s/\/tmp\/.*\.o://g;
|
$output =~ s/(\d+:\d+:\s*)*\/tmp\/.*\.o://g;
|
||||||
$output =~ s/collect2: ld returned \d+ exit status//g;
|
$output =~ s/(\d+:\d+:\s*)*collect2: ld returned \d+ exit status//g;
|
||||||
$output =~ s/\(\.text\+[^)]+\)://g;
|
$output =~ s/\(\.text\+[^)]+\)://g;
|
||||||
$output =~ s/\[ In/[In/;
|
$output =~ s/\[ In/[In/;
|
||||||
$output =~ s/warning: Can't read pathname for load map: Input.output error.//g;
|
$output =~ s/(\d+:\d+:\s*)*warning: Can't read pathname for load map: Input.output error.//g;
|
||||||
my $left_quote = chr(226) . chr(128) . chr(152);
|
my $left_quote = chr(226) . chr(128) . chr(152);
|
||||||
my $right_quote = chr(226) . chr(128) . chr(153);
|
my $right_quote = chr(226) . chr(128) . chr(153);
|
||||||
$output =~ s/$left_quote/'/msg;
|
$output =~ s/$left_quote/'/msg;
|
||||||
$output =~ s/$right_quote/'/msg;
|
$output =~ s/$right_quote/'/msg;
|
||||||
$output =~ s/`/'/msg;
|
$output =~ s/`/'/msg;
|
||||||
$output =~ s/\t/ /g;
|
$output =~ s/\t/ /g;
|
||||||
$output =~ s/\s*In function .main.:\s*//g;
|
$output =~ s/(\d+:\d+:\s*)*\s*In function .main.:\s*//g;
|
||||||
$output =~ s/warning: unknown conversion type character 'b' in format \[-Wformat\]\s+warning: too many arguments for format \[-Wformat-extra-args\]/info: %b is a candide extension/g;
|
$output =~ s/(\d+:\d+:\s*)*warning: unknown conversion type character 'b' in format \[-Wformat\]\s+(\d+:\d+:\s*)*warning: too many arguments for format \[-Wformat-extra-args\]/info: %b is a candide extension/g;
|
||||||
$output =~ s/warning: unknown conversion type character 'b' in format \[-Wformat\]//g;
|
$output =~ s/(\d+:\d+:\s*)*warning: unknown conversion type character 'b' in format \[-Wformat\]//g;
|
||||||
$output =~ s/\s\(core dumped\)/./;
|
$output =~ s/\s\(core dumped\)/./;
|
||||||
# $output =~ s/\[\s+/[/g;
|
# $output =~ s/\[\s+/[/g;
|
||||||
$output =~ s/ \[enabled by default\]//g;
|
$output =~ s/ \[enabled by default\]//g;
|
||||||
$output =~ s/initializer\s+warning: \(near/initializer (near/g;
|
$output =~ s/initializer\s+warning: \(near/initializer (near/g;
|
||||||
$output =~ s/note: each undeclared identifier is reported only once for each function it appears in//g;
|
$output =~ s/(\d+:\d+:\s*)*note: each undeclared identifier is reported only once for each function it appears in//g;
|
||||||
$output =~ s/\(gdb\)//g;
|
$output =~ s/\(gdb\)//g;
|
||||||
$output =~ s/", '\\(\d{3})' <repeats \d+ times>,? ?"/\\$1/g;
|
$output =~ s/", '\\(\d{3})' <repeats \d+ times>,? ?"/\\$1/g;
|
||||||
$output =~ s/, '\\(\d{3})' <repeats \d+ times>\s*//g;
|
$output =~ s/, '\\(\d{3})' <repeats \d+ times>\s*//g;
|
||||||
@ -1016,9 +1015,28 @@ unless($got_run) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(defined $got_paste or (defined $got_run and $got_run eq "paste")) {
|
if(defined $got_paste or (defined $got_run and $got_run eq "paste")) {
|
||||||
$output =~ s/[\r\n]+$//;
|
my $flags = "";
|
||||||
$code .= "\n\n/************* OUTPUT *************\n$output\n************** OUTPUT *************/\n";
|
|
||||||
|
$extracted_args =~ s/-paste //g;
|
||||||
|
if(length $extracted_args) {
|
||||||
|
$extracted_args =~ s/\s*$//;
|
||||||
|
$flags .= '[' . $extracted_args . '] ';
|
||||||
|
}
|
||||||
|
|
||||||
|
if(length $args) {
|
||||||
|
$flags .= "gcc " . $args . " -o prog prog.c";
|
||||||
|
} else {
|
||||||
|
$flags .= $languages{$lang} . " -o prog prog.c";
|
||||||
|
}
|
||||||
|
$code .= "\n\n/************* COMPILER FLAGS *************\n$flags\n************** COMPILER FLAGS *************/\n";
|
||||||
|
|
||||||
|
$output =~ s/^\s+//;
|
||||||
|
$output =~ s/\s+$//;
|
||||||
|
$output =~ s/[\r\n]+/\n/g;
|
||||||
|
$code .= "\n/************* OUTPUT *************\n$output\n************** OUTPUT *************/\n";
|
||||||
|
|
||||||
my $uri = paste_sprunge(pretty($code));
|
my $uri = paste_sprunge(pretty($code));
|
||||||
|
|
||||||
print "$nick: $uri\n";
|
print "$nick: $uri\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user