mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-29 23:39:24 +01:00
Improved codepad.pl
This commit is contained in:
parent
efd4ebd5af
commit
617f98ad5c
@ -1,8 +1,5 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
# Initial rough-draft prototype proof of concept
|
|
||||||
# Once working, need to refactor and polish.
|
|
||||||
|
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
@ -23,12 +20,28 @@ my $code = join ' ', @ARGV;
|
|||||||
my $lang = "C";
|
my $lang = "C";
|
||||||
$lang = $1 if $code =~ s/-lang=([^\b\s]+)//i;
|
$lang = $1 if $code =~ s/-lang=([^\b\s]+)//i;
|
||||||
|
|
||||||
|
my @languages = qw/C C++ D Haskell Lua OCaml PHP Perl Python Ruby Scheme Tcl/;
|
||||||
|
|
||||||
|
my $found = 0;
|
||||||
|
foreach my $l (@languages) {
|
||||||
|
if(uc $lang eq uc $l) {
|
||||||
|
$lang = $l;
|
||||||
|
$found = 1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(not $found) {
|
||||||
|
print "$nick: Invalid language '$lang'. Supported languages are: @languages\n";
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
my $ua = LWP::UserAgent->new();
|
my $ua = LWP::UserAgent->new();
|
||||||
|
|
||||||
$ua->agent("Mozilla/5.0");
|
$ua->agent("Mozilla/5.0");
|
||||||
push @{ $ua->requests_redirectable }, 'POST';
|
push @{ $ua->requests_redirectable }, 'POST';
|
||||||
|
|
||||||
if(not $code =~ m/\w+ main\s?\([^)]+\)\s?{/) {
|
if(($lang eq "C" or $lang eq "C++") and not $code =~ m/\w+ main\s?\([^)]+\)\s?{/) {
|
||||||
$code = "int main(void) { $code ; return 0; }";
|
$code = "int main(void) { $code ; return 0; }";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +66,7 @@ $text =~ s/<a style="" name="output-line-\d+">\d+<\/a>//g;
|
|||||||
if($text =~ /<span class="heading">Output:<\/span>.+?<div class="code">(.*)<\/div>.+?<\/table>/si) {
|
if($text =~ /<span class="heading">Output:<\/span>.+?<div class="code">(.*)<\/div>.+?<\/table>/si) {
|
||||||
$output = "$1";
|
$output = "$1";
|
||||||
} else {
|
} else {
|
||||||
$output = "No output.";
|
$output = "<pre>No output.</pre>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = decode_entities($output);
|
$output = decode_entities($output);
|
||||||
|
Loading…
Reference in New Issue
Block a user