3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 03:02:47 +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:
Pragmatic Software 2012-10-24 12:26:18 +00:00
parent 7f8b39d20a
commit 4602c3b732
6 changed files with 21 additions and 15 deletions

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 387,
BUILD_DATE => "2012-10-07",
BUILD_REVISION => 388,
BUILD_DATE => "2012-10-24",
};
1;

View File

@ -23,7 +23,7 @@ if(not defined $sock) {
my $nick = shift @ARGV;
my $code = join ' ', @ARGV;
my $lang = "C99";
my $lang = "C11";
if($code =~ s/-lang=([^ ]+)//) {
$lang = uc $1;

View File

@ -154,7 +154,7 @@ sub compiler_server {
$result =~ s/\s+$//;
print "Ret: $ret; result: [$result]\n";
if($result =~ m/Killed$/) {
if($result =~ m/\[Killed\]$/) {
print "Processed was killed\n";
$killed = 1;
}

View File

@ -102,7 +102,9 @@ sub compile {
$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 "compile:end\n";
@ -576,7 +578,8 @@ unless($got_run) {
my $found = 0;
my @langs;
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) {
$lang = $l;
$found = 1;
@ -584,7 +587,7 @@ foreach my $l (sort { uc $a cmp uc $b } keys %languages) {
}
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;
}
@ -786,6 +789,7 @@ if($lang eq 'C' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') {
my $body;
if(not defined $extract[0]) {
print "error: unmatched brackets for function '$ident';\n";
print "body: [$potential_body]\n";
exit;
} else {
$body = $extract[0];
@ -892,6 +896,7 @@ if($output =~ m/^\s*$/) {
$output =~ s/\/home\/compiler\///g;
$output =~ s/compilation terminated.//;
$output =~ s/<'(.)' = char>/<'$1' = int>/g;
$output =~ s/= (-?\d+) ''/= $1/g;
$output =~ s/, <incomplete sequence >//g;
$output =~ s/\s*warning: shadowed declaration is here \[-Wshadow\]//g;
$output =~ s/preprocessor macro>\s+<at\s+>/preprocessor macro>/g;

View File

@ -39,6 +39,7 @@ sub runserver {
open($output, '>', "/dev/stdout") or die $!;
}
my $date;
my $lang;
my $code;
my $user_args;
@ -57,7 +58,7 @@ sub runserver {
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 $output "result:$result\n";
@ -79,14 +80,14 @@ sub runserver {
$user_input = undef;
$lang = undef;
($lang, $user_args, $user_input) = split /:/, $options;
($lang, $user_args, $user_input, $date) = split /:/, $options;
$code = "";
$lang = "C11" if not defined $lang;
$user_args = "" if not defined $user_args;
$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;
}
@ -98,9 +99,9 @@ sub runserver {
}
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;
@ -146,7 +147,7 @@ sub interpret {
}
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 = "";

View File

@ -359,7 +359,7 @@ sub execute {
}
if($line =~ m/Program terminated with signal SIGKILL/) {
print "Killed\n";
print "[Killed]\n";
return 0;
}