3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 02:49:49 +01:00

Re-instated behavior of code-outside-of-main-goes-into-main

This commit is contained in:
Pragmatic Software 2010-05-13 20:59:43 +00:00
parent af0e1a7969
commit f5be06bd92

View File

@ -137,19 +137,17 @@ if($languages{$lang}{'id'} == 1 or $languages{$lang}{'id'} == 11 or $languages{$
my $prelude = ''; my $prelude = '';
$prelude = "$1$2" if $precode =~ s/^\s*(#.*)(#.*?[>\n])//s; $prelude = "$1$2" if $precode =~ s/^\s*(#.*)(#.*?[>\n])//s;
while($precode =~ s/([ a-zA-Z0-9_*\[\]]+)\s+([a-zA-Z0-9_*]+)\s*\((.*?)\)\s*{//) { while($precode =~ s/([ a-zA-Z0-9_*\[\]]+)\s+([a-zA-Z0-9_*]+)\s*\((.*?)\)\s*({.*)//) {
my ($ret, $ident, $params) = ($1, $2, $3); my ($ret, $ident, $params, $potential_body) = ($1, $2, $3, $4);
$precode = "{$precode"; my @extract = extract_codeblock($potential_body, '{}');
my @extract = extract_codeblock($precode, '{}');
my $body; my $body;
if(not defined $extract[0]) { if(not defined $extract[0]) {
$output .= "error: unmatched brackets for function '$ident';\n"; $output .= "error: unmatched brackets for function '$ident';\n";
$body = $extract[1]; $body = $extract[1];
$precode = '';
} else { } else {
$body = $extract[0]; $body = $extract[0];
$precode = $extract[1]; $precode .= $extract[1];
} }
$code .= "$ret $ident($params) $body\n\n"; $code .= "$ret $ident($params) $body\n\n";
$has_main = 1 if $ident eq 'main'; $has_main = 1 if $ident eq 'main';