40 Remove Non-API Text

This Perl script comments out non-documentation lines. (It is not (yet) in use.)

539aglobal variables 298a+   (297 478b 507 539b)  512a  540a
@LineBuffer=();
539b* 21+   537a  542
#------------------------------------------------------------------
#---
#--- ALLPROSE
#--- Copyright (C) Ralf Hemmecke (ralf@hemmecke.de)
#--- http://www.hemmecke.de/aldor
#---
#------------------------------------------------------------------

global variables 298a
my($lineNumber, $line);
while (<>) {chomp; push @LineBuffer, $_;}
for($lineNumber = 0; $lineNumber < scalar(@LineBuffer); $lineNumber++) {
    do something for one line 479a
}
for $line (@LineBuffer) {print $line, "\n";}

Now, depending on the line that is currently considered, several things have to be done. First of all, to shorten the following code, the current line is remembered.

539cdo something for one line 479a+   (478b 539b)  479c  540b
$line = @LineBuffer[$lineNumber];

The script remembers also in which state it currently is. In particular, whether it is inside a +++ environment or inside a code chunk. The line number of the \begin{+++} is remembered in the variable beginDocIndex in order to be able to add information there when it is found in the lines that follow.

540aglobal variables 298a+   (297 478b 507 539b)  539a
my($inDocEnvironment)=0;
my($inCodeChunk)=0;
540bdo something for one line 479a+   (478b 539b)  539c
if ($line =~ /^\\begin{\+\+\+}/) {
    $inDocEnvironment=1;
} elsif ($inDocEnvironment) {
    if ($line =~ /^\\end{\+\+\+}/) {
        $inDocEnvironment=0;
    }
} elsif ($line =~ /^<<.*>>=/) {
    $inCodeChunk=1;
} elsif ($inCodeChunk) {
    if ($line =~ /^\@(\s*$|\s+%def)/) {
        $inCodeChunk=0;
    }
} else { # we are not in a code chunk and not in a DocEnvironment.
    @LineBuffer[$lineNumber] = ’%’.$line;
}

Uses code 436.