3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-23 04:19:27 +01:00

ideone compiler: added run command to interactive editor

This commit is contained in:
Pragmatic Software 2011-01-20 00:55:45 +00:00
parent 0d5bf85f46
commit 023dd4bd09
2 changed files with 360 additions and 340 deletions

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 238,
BUILD_REVISION => 239,
BUILD_DATE => "2011-01-19",
};

View File

@ -24,6 +24,7 @@ my %languages = (
'Ada' => { 'id' => '7', 'name' => 'Ada (gnat-4.3.2)' },
'asm' => { 'id' => '13', 'name' => 'Assembler (nasm-2.07)' },
'nasm' => { 'id' => '13', 'name' => 'Assembler (nasm-2.07)' },
'gas' => { 'id' => '45', 'name' => 'Assembler (gcc-4.3.4)' },
'Assembler' => { 'id' => '13', 'name' => 'Assembler (nasm-2.07)' },
'Assembler' => { 'id' => '13', 'name' => 'Assembler (nasm-2.07)' },
'gawk' => { 'id' => '104', 'name' => 'AWK (gawk) (gawk-3.1.6)' },
@ -118,6 +119,17 @@ if($code =~ m/^\s*show\s*$/i) {
exit 0;
}
my $got_run;
if($code =~ m/^\s*run\s*$/i) {
if(defined $last_code[0]) {
$code = $last_code[0];
$got_run = 1;
} else {
print "$nick: No recent code to run.\n";
exit 0;
}
} else {
my $subcode = $code;
my $got_undo = 0;
my $got_sub = 0;
@ -506,9 +518,12 @@ if($got_undo and not $got_sub) {
print "$nick: $code\n";
exit 0;
}
}
unless($got_run) {
open FILE, ">> ideone_log.txt";
print FILE "$nick: $code\n";
}
my $lang = "C99";
$lang = $1 if $code =~ s/-lang=([^\b\s]+)//i;
@ -584,8 +599,8 @@ if($languages{$lang}{'id'} == 1 or $languages{$lang}{'id'} == 11 or $languages{$
$code = pretty($code)
}
$code =~ s/\\n/\n/g if $languages{$lang}{'id'} == 13 or $languages{$lang}{'id'} == 101;
$code =~ s/;/\n/g if $languages{$lang}{'id'} == 13;
$code =~ s/\\n/\n/g if $languages{$lang}{'id'} == 13 or $languages{$lang}{'id'} == 101 or $languages{$lang}{'id'} == 45;
$code =~ s/;/\n/g if $languages{$lang}{'id'} == 13 or $languages{$lang}{'id'} == 45;
$code =~ s/\|n/\n/g;
$code =~ s/^\s+//;
$code =~ s/\s+$//;
@ -724,7 +739,7 @@ $output =~ s/cc1: warnings being treated as errors//;
$output =~ s/ Line \d+ ://g;
$output =~ s/ \(first use in this function\)//g;
$output =~ s/error: \(Each undeclared identifier is reported only once.*?\)//msg;
$output =~ s/prog\.c[:\d\s]*//g;
$output =~ s/prog\.c:[:\s\d]*//g;
$output =~ s/ld: warning: cannot find entry symbol _start; defaulting to [^ ]+//;
$output =~ s/error: (.*?) error/error: $1; error/msg;
@ -735,9 +750,11 @@ $output =~ s/$right_quote/'/g;
$output = $nooutput if $output =~ m/^\s+$/;
unless($got_run) {
print FILE localtime() . "\n";
print FILE "$nick: [ http://ideone.com/$url ] $output\n\n";
close FILE;
}
if($show_link) {
print "$nick: [ http://ideone.com/$url ] $output\n";
@ -750,12 +767,15 @@ if($show_link) {
sub get_result {
my $result = shift @_;
use Data::Dumper;
if($result->fault) {
print join ', ', $result->faultcode, $result->faultstring, $result->faultdetail;
exit 0;
} else {
if($result->result->{error} ne "OK") {
print $result->result->{error};
print "error\n";
print Dumper($result->result->{error});
exit 0;
} else {
return $result->result;
@ -767,7 +787,7 @@ sub pretty {
my $code = join '', @_;
my $result;
my $pid = open2(\*IN, \*OUT, 'astyle -Upf');
my $pid = open2(\*IN, \*OUT, 'astyle -xUpf');
print OUT "$code\n";
close OUT;
while(my $line = <IN>) {