__EOF__
# Create plaintext source file (without semlit commands)
if (! open($src_outfd, ">", "$plain_src_filename")) {
err("could not open output src '$plain_src_filename', skipping");
close($slsrc_infd);
close($src_html_outfd);
return "";
}
my ($save_doc_filename, $save_doc_linenum) = ($cur_file_name, $cur_file_linenum);
($cur_file_name, $cur_file_linenum) = ($src_filename, 0);
my $src_linenum = 0; # separate variable to track source output file
$src_lines_td = "";
$src_content_td = " | ";
my $iline;
while (defined($iline = <$slsrc_infd>)) {
chomp($iline); # remove line delim
$iline .= "\n"; # add newline
$iline =~ s/\r//gs; # remove carriage returns, if any
$cur_file_linenum ++;
# check for semlit commands
if ($iline =~ /$o_delim\s*semlit\s*$o_fs\s*([^$o_delim]+)$o_delim/i) {
semlit_cmd($1);
# discard command line
}
else {
$src_linenum ++; # don't count semlit command lines
print $src_outfd $iline;
# fix up source for html rendering (tab expansion, special char encoding)
$iline = expand($iline); # expand tabs according to $tabstop.
$iline =~ s/\&/\&/g; $iline =~ s/\</g; $iline =~ s/>/\>/g;
# if we are in at least one block, link the source to the earliest block's first doc reference
if (scalar(keys(%active_srcblocks)) > 0) {
# descending sort so that elemet 0 is largest
my @active_blocks = sort { $active_srcblocks{$b} cmp $active_srcblocks{$a} } keys(%active_srcblocks);
my $targ = $active_blocks[0] . "_ref_1";
$src_lines_td .= sprintf("%05d<\/a>\n", $src_linenum);
if ($global_src_buffer) {
$src_content_td .= sprintf("%s %s", $global_src_buffer, $iline);
$global_src_buffer = "";
}
else {
$src_content_td .= sprintf(" %s", $iline);
}
# for each open source block on this line of source, link the doc block to the that source block
foreach my $block_name (keys(%active_srcblocks)) {
my $a = sprintf("%05d<\/a> %s", $src_linenum, $iline);
$srcblocks{$block_name} .= $a;
}
} else {
# no active blocks
my $a = sprintf("%05d\n", $src_linenum);
my $c = sprintf(" %s", $iline);
$src_lines_td .= $a;
$src_content_td .= $c;
}
}
} # while
# if the global buffer is still full, dump it here
if ($global_src_buffer) {
$src_content_td .= sprintf("%s %s", $global_src_buffer, $iline);
$global_src_buffer = "";
}
$src_lines_td .= "<\/td>";
$src_content_td .= "<\/td>";
print $src_html_outfd $src_lines_td;
print $src_html_outfd $src_content_td;
close($slsrc_infd);
close($src_outfd);
print $src_html_outfd " |
\n";
print $src_html_outfd "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
print $src_html_outfd "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
print $src_html_outfd "
\n";
close($src_html_outfd);
# if the source file started a block but reached eof without ending it, end it here.
foreach (keys(%active_srcblocks)) {
err("block named '$_' started but not ended");
semlit_cmd("endblock$o_fs$_"); # end it for the user
}
# the semlit.srcfile command writes a link to the plaintext source file
($cur_file_name, $cur_file_linenum) = ($save_doc_filename, $save_doc_linenum);
return "