From aaa6b2782dd02d84967553865cfa717da2ea252e Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 28 Mar 2010 18:37:53 +0000 Subject: [PATCH] Allow #including --- modules/codepad.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/codepad.pl b/modules/codepad.pl index c4bc29f1..123b6e71 100755 --- a/modules/codepad.pl +++ b/modules/codepad.pl @@ -41,11 +41,15 @@ my $ua = LWP::UserAgent->new(); $ua->agent("Mozilla/5.0"); push @{ $ua->requests_redirectable }, 'POST'; -if(($lang eq "C" or $lang eq "C++") and not $code =~ m/\w+ main\s?\([^)]+\)\s?{/) { - $code = "int main(void) { $code ; return 0; }"; +$code =~ s/#include <([^>]+)>/#include <$1>\n/g; + +if(($lang eq "C" or $lang eq "C++") and not $code =~ m/\w+ main\s?\([^)]*\)\s?{/) { + my $includes = ''; + $includes = $1 if $code =~ s/^(#include.*>)//; + $code = "$includes\n int main(int argc, char **argv) { $code ; return 0; }"; } -my $escaped_code = uri_escape($code, "\0-\377"); +# my $escaped_code = uri_escape($code, "\0-\377"); my %post = ( 'lang' => $lang, 'code' => $code, 'private' => 'True', 'run' => 'True', 'submit' => 'Submit' );