3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-30 07:59:42 +01:00

compiler-vm: use astyle with file instead of stdin to avoid astyle bug; add lorem ipsum default -input text

This commit is contained in:
Pragmatic Software 2012-02-15 22:00:58 +00:00
parent 4e52d77f61
commit 58a592c86f
2 changed files with 32 additions and 24 deletions

View File

@ -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 => 361, BUILD_REVISION => 362,
BUILD_DATE => "2012-02-10", BUILD_DATE => "2012-02-15",
}; };
1; 1;

View File

@ -33,18 +33,19 @@ sub pretty {
my $code = join '', @_; my $code = join '', @_;
my $result; my $result;
my $pid = open2(\*IN, \*OUT, 'astyle -Ujpf'); open my $fh, ">prog.c" or die "Couldn't write prog.c: $!";
print OUT "$code\n"; print $fh $code;
close OUT; close $fh;
while(my $line = <IN>) {
$result .= $line; system("astyle", "-Ujpfnq", "prog.c");
}
close IN; open $fh, "<prog.c" or die "Couldn't read prog.c: $!";
waitpid($pid, 0); $result = join '', <$fh>;
close $fh;
return $result; return $result;
} }
=cut
sub paste_codepad { sub paste_codepad {
my $text = join(' ', @_); my $text = join(' ', @_);
@ -57,15 +58,14 @@ sub paste_codepad {
my %post = ( 'lang' => 'C', 'code' => $text, 'private' => 'True', 'submit' => 'Submit' ); my %post = ( 'lang' => 'C', 'code' => $text, 'private' => 'True', 'submit' => 'Submit' );
my $response = $ua->post("http://codepad.org", \%post); my $response = $ua->post("http://codepad.org", \%post);
if(not $response->is_success) { if(not $response->is_success) {
return $response->status_line; return $response->status_line;
}
return $response->request->uri;
} }
return $response->request->uri; sub paste_sprunge {
}
=cut
sub paste_codepad {
my $text = join(' ', @_); my $text = join(' ', @_);
$text =~ s/(.{120})\s/$1\n/g; $text =~ s/(.{120})\s/$1\n/g;
@ -722,8 +722,10 @@ while($code =~ m/(.)/msg) {
$parens--; $parens--;
$parens = 0 if $parens < 0; $parens = 0 if $parens < 0;
} elsif($ch eq ';' and not $single_quote and not $double_quote and $parens == 0) { } elsif($ch eq ';' and not $single_quote and not $double_quote and $parens == 0) {
substr ($code, $pos, 0) = "\n"; if(not substr($code, $pos, 1) =~ m/[\n\r]/) {
pos $code = $pos + 1; substr ($code, $pos, 0) = "\n";
pos $code = $pos + 1;
}
} elsif($ch eq "'") { } elsif($ch eq "'") {
$single_quote = not $single_quote unless $escaped; $single_quote = not $single_quote unless $escaped;
$escaped = 0; $escaped = 0;
@ -731,11 +733,15 @@ while($code =~ m/(.)/msg) {
substr ($code, $pos - 2, 2) = "\n" and pos $code = $pos unless $single_quote or $double_quote; substr ($code, $pos - 2, 2) = "\n" and pos $code = $pos unless $single_quote or $double_quote;
$escaped = 0; $escaped = 0;
} elsif($ch eq '{' and not $single_quote and not $double_quote) { } elsif($ch eq '{' and not $single_quote and not $double_quote) {
substr ($code, $pos, 0) = "\n"; if(not substr($code, $pos, 1) =~ m/[\n\r]/) {
pos $code = $pos + 1; substr ($code, $pos, 0) = "\n";
pos $code = $pos + 1;
}
} elsif($ch eq '}' and not $single_quote and not $double_quote) { } elsif($ch eq '}' and not $single_quote and not $double_quote) {
substr ($code, $pos, 0) = "\n"; if(not substr($code, $pos, 1) =~ m/[\n\r;]/) {
pos $code = $pos + 1; substr ($code, $pos, 0) = "\n";
pos $code = $pos + 1;
}
} else { } else {
$escaped = 0; $escaped = 0;
} }
@ -753,6 +759,8 @@ if(defined $got_run and $got_run eq "paste") {
print FILE "$nick: [lang:$lang][args:$args][input:$input]\n", pretty($code), "\n"; print FILE "$nick: [lang:$lang][args:$args][input:$input]\n", pretty($code), "\n";
$input = "Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet." if not length $input;
$output = compile($lang, pretty($code), $args, $input, $USE_LOCAL); $output = compile($lang, pretty($code), $args, $input, $USE_LOCAL);
if($output =~ m/^\s*$/) { if($output =~ m/^\s*$/) {