mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-23 11:12:42 +01:00
compiler_vm: Pass host date to guest
Replace "Killed" with "[Killed]" Don't print empty '' after unprintable char values Set default language in compiler_client.pl to C11
This commit is contained in:
parent
7f8b39d20a
commit
4602c3b732
@ -13,8 +13,8 @@ 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 => 387,
|
BUILD_REVISION => 388,
|
||||||
BUILD_DATE => "2012-10-07",
|
BUILD_DATE => "2012-10-24",
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -23,7 +23,7 @@ if(not defined $sock) {
|
|||||||
my $nick = shift @ARGV;
|
my $nick = shift @ARGV;
|
||||||
my $code = join ' ', @ARGV;
|
my $code = join ' ', @ARGV;
|
||||||
|
|
||||||
my $lang = "C99";
|
my $lang = "C11";
|
||||||
|
|
||||||
if($code =~ s/-lang=([^ ]+)//) {
|
if($code =~ s/-lang=([^ ]+)//) {
|
||||||
$lang = uc $1;
|
$lang = uc $1;
|
||||||
|
@ -154,7 +154,7 @@ sub compiler_server {
|
|||||||
$result =~ s/\s+$//;
|
$result =~ s/\s+$//;
|
||||||
print "Ret: $ret; result: [$result]\n";
|
print "Ret: $ret; result: [$result]\n";
|
||||||
|
|
||||||
if($result =~ m/Killed$/) {
|
if($result =~ m/\[Killed\]$/) {
|
||||||
print "Processed was killed\n";
|
print "Processed was killed\n";
|
||||||
$killed = 1;
|
$killed = 1;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,9 @@ sub compile {
|
|||||||
$compiler_output = $compiler;
|
$compiler_output = $compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
print $compiler "compile:$lang:$args:$input\n";
|
my $date = time;
|
||||||
|
|
||||||
|
print $compiler "compile:$lang:$args:$input:$date\n";
|
||||||
print $compiler "$code\n";
|
print $compiler "$code\n";
|
||||||
print $compiler "compile:end\n";
|
print $compiler "compile:end\n";
|
||||||
|
|
||||||
@ -576,7 +578,8 @@ 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(" %-30s => %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;
|
||||||
$found = 1;
|
$found = 1;
|
||||||
@ -584,7 +587,7 @@ foreach my $l (sort { uc $a cmp uc $b } keys %languages) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(not $found) {
|
if(not $found) {
|
||||||
print "$nick: Invalid language '$lang'. Supported languages are:\n", (join ",\n", @langs), "\n";
|
print "$nick: Invalid language '$lang'. Supported languages are:\n", (join ",\n", @langs), "\n; For additional languages try the cc2 command.";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -731,7 +734,7 @@ if($lang eq 'C' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') {
|
|||||||
print "*** prelude: [$prelude]\n precode: [$precode]\n" if $debug;
|
print "*** prelude: [$prelude]\n precode: [$precode]\n" if $debug;
|
||||||
|
|
||||||
# strip C and C++ style comments
|
# strip C and C++ style comments
|
||||||
$precode =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $3 ? $3 : ""#gse;
|
$precode =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $3 ? $3 : " "#gse;
|
||||||
|
|
||||||
print " precode: [$precode]\n" if $debug;
|
print " precode: [$precode]\n" if $debug;
|
||||||
|
|
||||||
@ -786,6 +789,7 @@ if($lang eq 'C' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') {
|
|||||||
my $body;
|
my $body;
|
||||||
if(not defined $extract[0]) {
|
if(not defined $extract[0]) {
|
||||||
print "error: unmatched brackets for function '$ident';\n";
|
print "error: unmatched brackets for function '$ident';\n";
|
||||||
|
print "body: [$potential_body]\n";
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
$body = $extract[0];
|
$body = $extract[0];
|
||||||
@ -892,6 +896,7 @@ if($output =~ m/^\s*$/) {
|
|||||||
$output =~ s/\/home\/compiler\///g;
|
$output =~ s/\/home\/compiler\///g;
|
||||||
$output =~ s/compilation terminated.//;
|
$output =~ s/compilation terminated.//;
|
||||||
$output =~ s/<'(.)' = char>/<'$1' = int>/g;
|
$output =~ s/<'(.)' = char>/<'$1' = int>/g;
|
||||||
|
$output =~ s/= (-?\d+) ''/= $1/g;
|
||||||
$output =~ s/, <incomplete sequence >//g;
|
$output =~ s/, <incomplete sequence >//g;
|
||||||
$output =~ s/\s*warning: shadowed declaration is here \[-Wshadow\]//g;
|
$output =~ s/\s*warning: shadowed declaration is here \[-Wshadow\]//g;
|
||||||
$output =~ s/preprocessor macro>\s+<at\s+>/preprocessor macro>/g;
|
$output =~ s/preprocessor macro>\s+<at\s+>/preprocessor macro>/g;
|
||||||
|
@ -39,6 +39,7 @@ sub runserver {
|
|||||||
open($output, '>', "/dev/stdout") or die $!;
|
open($output, '>', "/dev/stdout") or die $!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $date;
|
||||||
my $lang;
|
my $lang;
|
||||||
my $code;
|
my $code;
|
||||||
my $user_args;
|
my $user_args;
|
||||||
@ -57,7 +58,7 @@ sub runserver {
|
|||||||
|
|
||||||
print "Attempting compile [$lang] ...\n";
|
print "Attempting compile [$lang] ...\n";
|
||||||
|
|
||||||
my $result = interpret($lang, $code, $user_args, $user_input);
|
my $result = interpret($lang, $code, $user_args, $user_input, $date);
|
||||||
|
|
||||||
print "Done compiling; result: [$result]\n";
|
print "Done compiling; result: [$result]\n";
|
||||||
print $output "result:$result\n";
|
print $output "result:$result\n";
|
||||||
@ -79,14 +80,14 @@ sub runserver {
|
|||||||
$user_input = undef;
|
$user_input = undef;
|
||||||
$lang = undef;
|
$lang = undef;
|
||||||
|
|
||||||
($lang, $user_args, $user_input) = split /:/, $options;
|
($lang, $user_args, $user_input, $date) = split /:/, $options;
|
||||||
|
|
||||||
$code = "";
|
$code = "";
|
||||||
$lang = "C11" if not defined $lang;
|
$lang = "C11" if not defined $lang;
|
||||||
$user_args = "" if not defined $user_args;
|
$user_args = "" if not defined $user_args;
|
||||||
$user_input = "" if not defined $user_input;
|
$user_input = "" if not defined $user_input;
|
||||||
|
|
||||||
print "Setting lang [$lang]; [$user_args]; [$user_input]\n";
|
print "Setting lang [$lang]; [$user_args]; [$user_input]; [$date]\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,9 +99,9 @@ sub runserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub interpret {
|
sub interpret {
|
||||||
my ($lang, $code, $user_args, $user_input) = @_;
|
my ($lang, $code, $user_args, $user_input, $date) = @_;
|
||||||
|
|
||||||
print "lang: [$lang], code: [$code], user_args: [$user_args], input: [$user_input]\n";
|
print "lang: [$lang], code: [$code], user_args: [$user_args], input: [$user_input], date: [$date]\n";
|
||||||
|
|
||||||
$lang = uc $lang;
|
$lang = uc $lang;
|
||||||
|
|
||||||
@ -146,7 +147,7 @@ sub interpret {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $user_input_quoted = quotemeta $user_input;
|
my $user_input_quoted = quotemeta $user_input;
|
||||||
($ret, $result) = execute(60, "bash -c 'ulimit -t 1; compiler_watchdog.pl $user_input_quoted > .output'");
|
($ret, $result) = execute(60, "bash -c 'date -s \@$date; ulimit -t 1; compiler_watchdog.pl $user_input_quoted > .output'");
|
||||||
|
|
||||||
$result = "";
|
$result = "";
|
||||||
|
|
||||||
|
@ -359,7 +359,7 @@ sub execute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($line =~ m/Program terminated with signal SIGKILL/) {
|
if($line =~ m/Program terminated with signal SIGKILL/) {
|
||||||
print "Killed\n";
|
print "[Killed]\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user