#!/usr/bin/perl -w @A = ( [ "01", "drawingLines", "Drawing Lines", 1, "" ], [ "02", "drawingOtherStuff", "Drawing Other Stuff", 1, "" ], [ "03", "color", "Color", 2, "introduces arrays" ], [ "04", "mouseInput", "Mouse Input", 2, "introduces showStatus( ) and Vector" ], [ "05", "keyboardInput", "Keyboard Input", 2, "" ], [ "06", "threads", "Threads and Animation", 1, "introduces System.out.println( )" ], [ "07", "backbuffer", "Backbuffers", 1, "introduces Math.random( ) and Graphics.drawImage( )" ], [ "08", "painting", "Painting", 2, "" ], [ "09", "clocks", "Clocks", 1, "" ], [ "10", "text", "Playing with Text", 0, "introduces 2D arrays and hyperlinks" ], [ "11", "3d", "3D Graphics", 1, "introduces classes" ], [ "12", "miscellaneous", "Odds and Ends", 1, "" ], ); $index = ""; # used to be "index.html" $lenA = @A; for ( $j = 0; $j < $lenA; $j++ ) { $j2 = $j + 1; # generate an entry in the table of contents # # print " $j2 : " . # "$A[$j][2]"; # if ( $A[$j][4] ne "" ) { # print "\n - $A[$j][4]"; # } # print "
\n"; print " $j2 \n" . " $A[$j][2]\n"; if ( $A[$j][4] ne "" ) { print " - $A[$j][4]\n"; } chdir( $A[$j][0] . "-" . $A[$j][1] ) # the . operator concatenates strings or die "Can't chdir to $A[$j][0]-$A[$j][1]\n"; open( INPUT, $A[$j][1].".source" ) or die "Can't open file $A[$j][1].source\n"; open( OUTPUT, ">index.html" ) # the > opens for writing or die "Can't open file index.html for writing\n"; print OUTPUT "Applet Tutorial: $A[$j][2]\n"; print OUTPUT "\n"; print OUTPUT "
[ Home\n"; for ( $k = 0; $k < $lenA; $k++ ) { $k2 = $k + 1; if ( $k == $j ) { print OUTPUT " | $k2\n"; } else { print OUTPUT " | " . "$k2\n"; } } print OUTPUT "]
\n"; print OUTPUT "

Exercise $j2: $A[$j][2]

\n"; while ( ) { if ( /__SOURCE_UNCOMMENTED (.*)/ ) { print OUTPUT "
\n";
         open( INPUT2, $1 ) or die "Can't open $1\n";
         # We're supposed to strip all comments and blank lines,
         # *except* when either of these ends with a trailing blank.
         while (  ) {
            # is there a trailing blank ?
            if ( /^(.*) $/ ) {
               print OUTPUT "$1\n";  # echo it, without the trailing blank
            }
            # is the line empty, or does it only contain whitespace ?
            elsif ( /^(\s*)$/ ) {
               # don't echo anything
            }
            # does the line contain "//" preceded only by whitespace ?
            elsif ( /^(\s*)\/\/(.*)$/ ) {
               # don't echo anything
            }
            # does the line contain "//" ?
            elsif ( /^(.*)\/\/(.*)$/ ) {
               # output contents preceding comment
               # (unfortunately, trailing blanks might get output too)
               print OUTPUT "$1\n";
            }
            else {
               print OUTPUT "$_";  # output entire line
            }
         }
         close( INPUT2 );
         print OUTPUT "
\n"; } elsif ( /__SOURCE (.*)/ ) { print OUTPUT "
\n";
         open( INPUT2, $1 ) or die "Can't open $1\n";
         while (  ) {
            print OUTPUT "$_";
         }
         close( INPUT2 );
         print OUTPUT "
\n"; } elsif ( /__APPLET (.*)/ ) { print OUTPUT "
\n"; print OUTPUT "\n"; print OUTPUT " ( You need to enable Java to see this applet. )\n"; print OUTPUT "\n"; print OUTPUT "
\n"; } else { print OUTPUT "$_"; } } print OUTPUT "

\n"; close( OUTPUT ); close( INPUT ); chdir(".."); } # generate the thumbnail links # printf "\n"; for ( $j = 0; $j < $lenA; $j++ ) { for ( $k = 0; $k < $A[$j][3]; $k ++ ) { $k2 = $k+1; print "" . "" . "\n"; } }