\n";
$ret .= "
S2 Compiler Output at " . scalar(localtime) . "\n";
my $error;
$POST{'s2code'} =~ s/\r//g; # just in case
unless (LJ::S2::layer_compile($lay, \$error, { 's2ref' => \$POST{'s2code'} })) {
$error =~ s/LJ::S2,.+//s;
$error =~ s!, .+?(src/s2|cgi-bin)/!, !g;
$ret .= "Error compiling layer:\n
$error
";
# display error with helpful context
if ($error =~ /^compile error: line (\d+)/i) {
my $errline = $1;
my $kill = $errline - 5 < 0 ? 0 : $errline - 5;
my $prehilite = $errline - 1 > 4 ? 4: $errline - 1;
my $snippet = $s2code;
# make sure there's a newlilne at the end
chomp $snippet;
$snippet .= "\n";
# and now, fun with regular expressions
my $ct = 0;
$snippet =~ s!(.*?)\n!sprintf("%3d", ++$ct) . ": " .
$1 . "\n"!ge; # add line breaks and numbering
$snippet = LJ::ehtml($snippet);
$snippet =~ s!^((?:.*?\n){$kill,$kill}) # kill before relevant lines
((?:.*?\n){$prehilite,$prehilite}) # capture context before error
(.*?\n){0,1} # capture error
((?:.*?\n){0,4}) # capture context after error
.* # kill after relevant lines
!$2
$3$4!sx;
$ret .= "
Context$snippet
\n";
}
} else {
$ret .= "No errors\n";
}
$ret .= "
\n\n";
}
$ret .= LJ::html_hidden("action", "compile") . "\n";
$ret .= "" . LJ::html_submit('submit', 'Compile', {
'style' => 'float: right; margin-bottom: 2px',
'accesskey' => 'c',
'title' => 'alt-C: compile',
} ) . "\n";
$ret .= "Edit layer source\n";
$ret .= LJ::html_textarea({ 'name' => 's2code', 'class' => 's2code', 'wrap' => 'off',
'cols' => '50', 'rows' => '40', 'value' => $s2code }) . "\n";
$ret .= LJ::html_submit('submit', 'Compile') . "\n";
$ret .= "