From 58a592c86f8868623786cfba93bcd36084e7c0c7 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 15 Feb 2012 22:00:58 +0000 Subject: [PATCH] compiler-vm: use astyle with file instead of stdin to avoid astyle bug; add lorem ipsum default -input text --- PBot/VERSION.pm | 4 +- modules/compiler_vm/compiler_vm_client.pl | 52 +++++++++++++---------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 2ceda8a4..2a0c4b30 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 361, - BUILD_DATE => "2012-02-10", + BUILD_REVISION => 362, + BUILD_DATE => "2012-02-15", }; 1; diff --git a/modules/compiler_vm/compiler_vm_client.pl b/modules/compiler_vm/compiler_vm_client.pl index 58a15181..1914c67b 100755 --- a/modules/compiler_vm/compiler_vm_client.pl +++ b/modules/compiler_vm/compiler_vm_client.pl @@ -33,18 +33,19 @@ sub pretty { my $code = join '', @_; my $result; - my $pid = open2(\*IN, \*OUT, 'astyle -Ujpf'); - print OUT "$code\n"; - close OUT; - while(my $line = ) { - $result .= $line; - } - close IN; - waitpid($pid, 0); + open my $fh, ">prog.c" or die "Couldn't write prog.c: $!"; + print $fh $code; + close $fh; + + system("astyle", "-Ujpfnq", "prog.c"); + + open $fh, "; + close $fh; + return $result; } -=cut sub paste_codepad { my $text = join(' ', @_); @@ -57,15 +58,14 @@ sub paste_codepad { my %post = ( 'lang' => 'C', 'code' => $text, 'private' => 'True', 'submit' => 'Submit' ); my $response = $ua->post("http://codepad.org", \%post); -if(not $response->is_success) { - return $response->status_line; + if(not $response->is_success) { + return $response->status_line; + } + + return $response->request->uri; } -return $response->request->uri; -} -=cut - -sub paste_codepad { +sub paste_sprunge { my $text = join(' ', @_); $text =~ s/(.{120})\s/$1\n/g; @@ -722,8 +722,10 @@ while($code =~ m/(.)/msg) { $parens--; $parens = 0 if $parens < 0; } elsif($ch eq ';' and not $single_quote and not $double_quote and $parens == 0) { - substr ($code, $pos, 0) = "\n"; - pos $code = $pos + 1; + if(not substr($code, $pos, 1) =~ m/[\n\r]/) { + substr ($code, $pos, 0) = "\n"; + pos $code = $pos + 1; + } } elsif($ch eq "'") { $single_quote = not $single_quote unless $escaped; $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; $escaped = 0; } elsif($ch eq '{' and not $single_quote and not $double_quote) { - substr ($code, $pos, 0) = "\n"; - pos $code = $pos + 1; + if(not substr($code, $pos, 1) =~ m/[\n\r]/) { + substr ($code, $pos, 0) = "\n"; + pos $code = $pos + 1; + } } elsif($ch eq '}' and not $single_quote and not $double_quote) { - substr ($code, $pos, 0) = "\n"; - pos $code = $pos + 1; + if(not substr($code, $pos, 1) =~ m/[\n\r;]/) { + substr ($code, $pos, 0) = "\n"; + pos $code = $pos + 1; + } } else { $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"; +$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); if($output =~ m/^\s*$/) {