6. QefDoc

6.1. qtangle


6.1.1
#! /bin/env perl

6.1.2

Strip out the documentation from a qefdoc file to produce just the code.


6.1.3

Check the command line arguments. There can be upto 2, to specify the input and output files, but they are both optional.

my $nargs = scalar @ARGV;
if ($nargs > 2)
{
   print "Usage: qtangle [input `.qef' file] [output file]\n".
         "The input and output files default to `stdin' and `stdout'".
         " respectively.\n";
   exit 1;
}

open INPFILE, ($nargs >= 1 ? "<$ARGV[0]" : "<-") or
   die "Error opening input file `$ARGV[0]'.\n";

open OUTFILE, ($nargs >= 2 ? ">$ARGV[1]" : ">-") or
   die "Error opening output file `$ARGV[1]'.\n";

6.1.4

Read the whole of the input file into a string variable.

my $file = "";
while (<INPFILE>)
{
   $file .= $_;
}

6.1.5

These substitutions strip out the docstrings. TODO: make this next line extract the info from the header line.

my $pants = "pants pants pants!";
$file =~ s/^qefdoc(:[^\n]*)?$//m;
$file =~ s/^\n(#![^\n]*\n)/$1\n/s;        # Make sure the #!/ is the first line
$file =~ s/\@\@/<QTangle $pants AT twice>/g;
while ($file =~ s/@<([^\n]*)\n(.*)@>/\n@<$1$2@>/s) {}
$file =~ s/@<[^\n]*@>//sg;
$file =~ s/^[\a\b\t\v\f\r ]*@[^\n]*$//mg;
$file =~ s/<QTangle $pants AT twice>/\@/g;
#$file =~ s/\@\@/@/g;

6.1.6

Print out the source code sans qefdoc stuff.

print OUTFILE $file;