3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-05-05 22:27:25 +02: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 # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 238, BUILD_REVISION => 239,
BUILD_DATE => "2011-01-19", BUILD_DATE => "2011-01-19",
}; };

View File

@ -24,6 +24,7 @@ my %languages = (
'Ada' => { 'id' => '7', 'name' => 'Ada (gnat-4.3.2)' }, 'Ada' => { 'id' => '7', 'name' => 'Ada (gnat-4.3.2)' },
'asm' => { 'id' => '13', 'name' => 'Assembler (nasm-2.07)' }, 'asm' => { 'id' => '13', 'name' => 'Assembler (nasm-2.07)' },
'nasm' => { '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)' },
'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)' }, 'gawk' => { 'id' => '104', 'name' => 'AWK (gawk) (gawk-3.1.6)' },
@ -118,11 +119,22 @@ if($code =~ m/^\s*show\s*$/i) {
exit 0; exit 0;
} }
my $subcode = $code; my $got_run;
my $got_undo = 0;
my $got_sub = 0;
while($subcode =~ s/^\s*(and)?\s*undo//) { 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;
while($subcode =~ s/^\s*(and)?\s*undo//) {
splice @last_code, 0, 1; splice @last_code, 0, 1;
if(not defined $last_code[0]) { if(not defined $last_code[0]) {
print "$nick: No more undos remaining.\n"; print "$nick: No more undos remaining.\n";
@ -131,13 +143,13 @@ while($subcode =~ s/^\s*(and)?\s*undo//) {
$code = $last_code[0]; $code = $last_code[0];
$got_undo = 1; $got_undo = 1;
} }
} }
my @replacements; my @replacements;
my $prevchange = $last_code[0]; my $prevchange = $last_code[0];
my $got_changes = 0; my $got_changes = 0;
while(1) { while(1) {
$got_sub = 0; $got_sub = 0;
$got_changes = 0; $got_changes = 0;
@ -405,9 +417,9 @@ while(1) {
} }
last; last;
} }
if($#replacements > -1) { if($#replacements > -1) {
@replacements = sort { $a->{'from'} cmp $b->{'from'} or $a->{'modifier'} <=> $b->{'modifier'} } @replacements; @replacements = sort { $a->{'from'} cmp $b->{'from'} or $a->{'modifier'} <=> $b->{'modifier'} } @replacements;
my ($previous_from, $previous_modifier); my ($previous_from, $previous_modifier);
@ -487,28 +499,31 @@ if($#replacements > -1) {
print "$nick: No replacements made.\n"; print "$nick: No replacements made.\n";
exit 0; exit 0;
} }
} }
open FILE, "> ideone_last_code.txt"; open FILE, "> ideone_last_code.txt";
unless ($got_undo and not $got_sub) { unless ($got_undo and not $got_sub) {
unshift @last_code, $code; unshift @last_code, $code;
} }
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);
print FILE "$line\n"; print FILE "$line\n";
} }
close FILE; close FILE;
if($got_undo and not $got_sub) { if($got_undo and not $got_sub) {
print "$nick: $code\n"; print "$nick: $code\n";
exit 0; exit 0;
}
} }
open FILE, ">> ideone_log.txt"; unless($got_run) {
print FILE "$nick: $code\n"; open FILE, ">> ideone_log.txt";
print FILE "$nick: $code\n";
}
my $lang = "C99"; my $lang = "C99";
$lang = $1 if $code =~ s/-lang=([^\b\s]+)//i; $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 = pretty($code)
} }
$code =~ s/\\n/\n/g if $languages{$lang}{'id'} == 13 or $languages{$lang}{'id'} == 101; $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; $code =~ s/;/\n/g if $languages{$lang}{'id'} == 13 or $languages{$lang}{'id'} == 45;
$code =~ s/\|n/\n/g; $code =~ s/\|n/\n/g;
$code =~ s/^\s+//; $code =~ s/^\s+//;
$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/ Line \d+ ://g;
$output =~ s/ \(first use in this function\)//g; $output =~ s/ \(first use in this function\)//g;
$output =~ s/error: \(Each undeclared identifier is reported only once.*?\)//msg; $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/ld: warning: cannot find entry symbol _start; defaulting to [^ ]+//;
$output =~ s/error: (.*?) error/error: $1; error/msg; $output =~ s/error: (.*?) error/error: $1; error/msg;
@ -735,9 +750,11 @@ $output =~ s/$right_quote/'/g;
$output = $nooutput if $output =~ m/^\s+$/; $output = $nooutput if $output =~ m/^\s+$/;
print FILE localtime() . "\n"; unless($got_run) {
print FILE "$nick: [ http://ideone.com/$url ] $output\n\n"; print FILE localtime() . "\n";
close FILE; print FILE "$nick: [ http://ideone.com/$url ] $output\n\n";
close FILE;
}
if($show_link) { if($show_link) {
print "$nick: [ http://ideone.com/$url ] $output\n"; print "$nick: [ http://ideone.com/$url ] $output\n";
@ -750,12 +767,15 @@ if($show_link) {
sub get_result { sub get_result {
my $result = shift @_; my $result = shift @_;
use Data::Dumper;
if($result->fault) { if($result->fault) {
print join ', ', $result->faultcode, $result->faultstring, $result->faultdetail; print join ', ', $result->faultcode, $result->faultstring, $result->faultdetail;
exit 0; exit 0;
} else { } else {
if($result->result->{error} ne "OK") { if($result->result->{error} ne "OK") {
print $result->result->{error}; print "error\n";
print Dumper($result->result->{error});
exit 0; exit 0;
} else { } else {
return $result->result; return $result->result;
@ -767,7 +787,7 @@ sub pretty {
my $code = join '', @_; my $code = join '', @_;
my $result; my $result;
my $pid = open2(\*IN, \*OUT, 'astyle -Upf'); my $pid = open2(\*IN, \*OUT, 'astyle -xUpf');
print OUT "$code\n"; print OUT "$code\n";
close OUT; close OUT;
while(my $line = <IN>) { while(my $line = <IN>) {