35 Code File Filter: Add +++ description

This Perl script takes an ALLPROSE Noweb form of an Aldor source as standard input and transforms environments of the form

\begin{+++}  
line 1  
...  
line n  
\end{+++}  
% empty lines or LaTeX comment lines  
<<some code chunk>>=  
...  
@

into

<<some code chunk>>=  
+++ line 1  
+++ ...  
+++ line n  
@  
% empty lines or LaTeX comment lines  
<<some code chunk>>=  
...  
@

Note that both code chunks will have the same name so that the documentation in the tangled file comes immediately before the corresponding code.

Additionally note that the n-th input line corresponds to the n-th output line. Such a correspondence is important for the -L option that is given to NOTANGLE.

486* 21+   474b  495
#------------------------------------------------------------------
#---
#--- ALLPROSE
#--- Copyright (C) Ralf Hemmecke (ralf@hemmecke.de)
#--- http://www.hemmecke.de/aldor
#---
#------------------------------------------------------------------

@LineBuffer=();   # the container for all lines from stdin
# read standard input into LineBuffer (remove \n at end of line)
while (<>) {chomp; push @LineBuffer, $_;}
transform +++ environments 489
for $line (@LineBuffer) {print $line, "\n";}

Uses all 346.

Now we run through the line. If we find

\begin{+++}

then the curresponding line number is remembered until the following code chunk. If we reach the beginning of a code chunk, the last

\begin{+++}

line is replaced by the current code-chunk-opening line and the corresponding

\end{+++}

is replaced by @. The lines inside the +++ environment are prepended by "+++ ".

489transform +++ environments 489  (486)
my($beginDocIndex)=-1; # -1 means invalid
for($lineNumber = 0; $lineNumber < scalar(@LineBuffer); $lineNumber++) {
    $line = @LineBuffer[$lineNumber];
    if ($line =~ /^\\begin{\+\+\+}/) {
        $beginDocIndex=$lineNumber;
    } elsif ($line =~ /^<<.*>>=/) {
        if ($beginDocIndex >=0) {
            $LineBuffer[$beginDocIndex]=$line;
            my($i)=$beginDocIndex+1;
            while (!($LineBuffer[$i] =~ /^\\end{\+\+\+}/)) {
                $LineBuffer[$i] = ’+++ ’ . $LineBuffer[$i];
                $i++;
            }
            $LineBuffer[$i] = ’@’;
            $beginDocIndex=-1;
        }
    }
}