3 # This file was originally written by Peter Keller (psilord@cs.wisc.edu)
4 # and this code is released under the same license as IOLib.
6 # The purpose of this program is to parse out the ex-NNNb / ex-NNNe sections
7 # from all of the ex*.lisp files, and then shove them into the template
8 # tutorial file at <example location:example> lines. This greatly simplifies
9 # changing the codes and keeping it current to the tutorial.
11 # This script is a simple hack and can be fooled by incorrect sentinel markers
12 # in the codebase or by out of bounds example numbers in the tutorial.tmpl
13 # file. My advice is: don't do that.
22 $exref = load_examples
();
30 my @files = `ls ex*.lisp`;
32 my ($line, $location, $example, $edge);
36 map {chomp $_;} @files;
38 foreach $file (@files) {
39 # print "Processing file: $file\n";
41 # open each file in turn, each file's prefix is the key to a hash of
42 # examples found in the file, and each example is keyed by ex-NNN as
43 # dictated in the file.
45 open(FIN
, "<$file") or die "Can't open file $file: $!";
46 ($location) = ($file =~ m/^(.*)\.lisp$/);
48 # read the examples out of the source itself.
50 while(defined($line = <FIN
>)) {
52 if ($line =~ /;\s*ex-/) {
53 # we either start recording an example, or are just finishing
55 ($example, $edge) = ($line =~ /(ex-\d+)(.)/);
58 die "Premature EOF!" if (!defined($line = <FIN
>));
65 if ($recording == 1) {
66 push @
{$ex{$location}{$example}}, $line;
67 # print "Recorded: $location:$example <- $line\n";
80 my $tmpl = "tutorial.tmpl";
83 my ($location, $example);
86 open(FIN
, "<$tmpl") or die "Can't open tutorial template $tmpl: $!";
87 open(FOUT
, ">$out") or die "Can't open generated tutorial $out: $!";
89 # read each line of the template, and if I see the magical
90 # <example location:example> format, then shove in the example code lines
91 # from the hash table.
92 while(defined($line = <FIN
>)) {
93 if ($line =~ m/<example\s+.*>/) {
96 # if I asked for an example, then shove the block into the tutorial
98 ($location, $example) = ($line =~ m/<example\s*(.*):(.*)>/);
99 if (!exists($exref->{$location}{$example})) {
102 die "Tried to include nonexistant example: $location:$example";
104 print FOUT
"+" . "-" x
78 . "+\n";
105 print FOUT
"|" . " " x
78 . "|\n";
106 foreach $exline (@
{$exref->{$location}{$example}}) {
107 print FOUT
"$exline\n";
109 print FOUT
"|" . " " x
78 . "|\n";
110 print FOUT
"+" . "-" x
78 . "+\n";
112 # otherwise just copy the line over.