From b03a7eb18c436d56e11d4fc14f5b260da013794f Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 13 May 2010 21:02:53 +0000 Subject: [PATCH] Re-instated behavior of code-outside-of-main-goes-into-main --- modules/codepad.pl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/codepad.pl b/modules/codepad.pl index 4a2dacf4..d9127fd8 100755 --- a/modules/codepad.pl +++ b/modules/codepad.pl @@ -67,19 +67,17 @@ if($lang eq "C" or $lang eq "C++") { my $prelude = ''; $prelude = "$1$2" if $precode =~ s/^\s*(#.*)(#.*?[>\n])//s; - while($precode =~ s/([ a-zA-Z0-9_*\[\]]+)\s+([a-zA-Z0-9_*]+)\s*\((.*?)\)\s*{//) { - my ($ret, $ident, $params) = ($1, $2, $3); - - $precode = "{$precode"; - my @extract = extract_codeblock($precode, '{}'); + while($precode =~ s/([ a-zA-Z0-9_*\[\]]+)\s+([a-zA-Z0-9_*]+)\s*\((.*?)\)\s*({.*)//) { + my ($ret, $ident, $params, $potential_body) = ($1, $2, $3, $4); + + my @extract = extract_codeblock($potential_body, '{}'); my $body; if(not defined $extract[0]) { $output .= "
error: unmatched brackets for function '$ident'; 
"; $body = $extract[1]; - $precode = ''; } else { $body = $extract[0]; - $precode = $extract[1]; + $precode .= $extract[1]; } $code .= "$ret $ident($params) $body\n\n"; $has_main = 1 if $ident eq 'main';