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:
parent
0d5bf85f46
commit
023dd4bd09
@ -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",
|
||||
};
|
||||
|
||||
|
@ -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,11 +119,22 @@ if($code =~ m/^\s*show\s*$/i) {
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my $subcode = $code;
|
||||
my $got_undo = 0;
|
||||
my $got_sub = 0;
|
||||
my $got_run;
|
||||
|
||||
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;
|
||||
if(not defined $last_code[0]) {
|
||||
print "$nick: No more undos remaining.\n";
|
||||
@ -131,13 +143,13 @@ while($subcode =~ s/^\s*(and)?\s*undo//) {
|
||||
$code = $last_code[0];
|
||||
$got_undo = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my @replacements;
|
||||
my $prevchange = $last_code[0];
|
||||
my $got_changes = 0;
|
||||
my @replacements;
|
||||
my $prevchange = $last_code[0];
|
||||
my $got_changes = 0;
|
||||
|
||||
while(1) {
|
||||
while(1) {
|
||||
$got_sub = 0;
|
||||
$got_changes = 0;
|
||||
|
||||
@ -405,9 +417,9 @@ while(1) {
|
||||
}
|
||||
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
if($#replacements > -1) {
|
||||
if($#replacements > -1) {
|
||||
@replacements = sort { $a->{'from'} cmp $b->{'from'} or $a->{'modifier'} <=> $b->{'modifier'} } @replacements;
|
||||
|
||||
my ($previous_from, $previous_modifier);
|
||||
@ -487,28 +499,31 @@ if($#replacements > -1) {
|
||||
print "$nick: No replacements made.\n";
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
my $i = 0;
|
||||
foreach my $line (@last_code) {
|
||||
my $i = 0;
|
||||
foreach my $line (@last_code) {
|
||||
last if(++$i > $MAX_UNDO_HISTORY);
|
||||
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";
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
|
||||
open FILE, ">> ideone_log.txt";
|
||||
print FILE "$nick: $code\n";
|
||||
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+$/;
|
||||
|
||||
print FILE localtime() . "\n";
|
||||
print FILE "$nick: [ http://ideone.com/$url ] $output\n\n";
|
||||
close FILE;
|
||||
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>) {
|
||||
|
Loading…
Reference in New Issue
Block a user