home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Pavilions / BrainOpera / text-site-bak / perl / brainop.pl next >
Perl Script  |  2017-09-21  |  4KB  |  105 lines

  1. #!/usr/athena/bin/perl
  2.  
  3. # Mike Jacknis, mjacknis@mit.edu
  4.  
  5. print "
  6. This perl script will compile the big brainop text site:
  7.    big.html
  8. This file consists of a hyperlinked table of contents
  9. followed by all the files.
  10.  
  11. I am expecting an INDEX file that lists the files to be included.
  12. I am also expecting:
  13.   warning.cat    --- File contents copied at the very beginning.
  14.   header.cat     --- File contents copied at the beginning.
  15.   contfooter.cat --- File copied after the table of contents,
  16.                      but before the body.
  17.   footer.cat     --- File copied after the body.
  18.  
  19. Also, if the individual files include a comment of the form:
  20.   <! ENTRY table of contents entry>
  21. then I will make an entry in the table of contents at that point.
  22.  
  23. ";
  24.  
  25. # First we read in a whole bunch of informational text files:
  26.  
  27. open(INDEX,"INDEX") || die "I couldn't open INDEX";
  28. open(HEAD,"header.cat") || die "I couldn't open header.cat";
  29. open(CONTFOOT,"contfooter.cat") || die "I couldn't open contfooter.cat";
  30. open(FOOT,"footer.cat") || die "I couldn't open footer.cat";
  31. open(WARNING,"warning.cat") || die "I couldn't open warning.cat";
  32.  
  33. # We copy the contents of these files to array variables:
  34. @head=<HEAD>;
  35. @contfoot=<CONTFOOT>;
  36. @foot=<FOOT>;
  37. @warning=<WARNING>;
  38.  
  39. # We close most of the files:
  40. close(HEAD);
  41. close(CONTFOOT);
  42. close(FOOT);
  43. close(WARNING);
  44.  
  45. # We open the output file:
  46. open (OUT,">big.html") || die "Couldn't open big.html for output";
  47.  
  48. while(<INDEX>) {        # MAIN LOOP... through all the filenames.
  49.     chop;            # Get rid of ending carriage return.
  50.     s/#.*//;            # get rid of comments
  51.     if (/.+/) {            # Check that there is a name there.
  52.     open (IN, $_)        # Open the input file.
  53.         || die "I couldn't open $_"; 
  54.     print "opened $_ \n";    # This goes out to the USER.
  55.     $file=$_;        # Save the filename.
  56.     $file =~ s/^.*\///;    # Get rid of directory.
  57.     $copy="";        # Clear the flag saying to copy the text.
  58.     push(@body,"<a name=\"$file\">\n"); # Make an anchor.
  59.     $number=1;        # reset the counter of anchors.
  60.     while(<IN>) {        # Loop through the file.
  61.         if (/^<! *ENTRY +(.*) *>/i) { # Is this a 
  62.                 # table of contents entry?
  63.         push(@contents,"<LI><a href=\"\#$file$number\">$1</a>\n"); 
  64.                 # Make a link in the table of contents...
  65.             push(@body,"<a name=\"$file$number\">\n");
  66.                 # ...make the anchor where the link will go.
  67.         $number++;}    # Increment the anchor counter.
  68.         elsif (/<BODY>(.*)/i) { # We found the start of the <BODY>
  69.         $copy="t";    # Set the flag to begin copying text.
  70.         push(@body,$1);} # Copy any text that may be after <BODY>
  71.         elsif (/(.*)<\/BODY>/i) { # We found the end... </BODY>
  72.         $copy="";    # Clear the flag to copy text.
  73.         push(@body,$1); } # Send off any last remaining text.
  74.         elsif ($copy eq "t") { # If we are copying text...
  75.         if (m@<a +href *= *\"http://@i) {
  76.             # If this is an OUTSIDE link
  77.             push(@body,$_); } # just copy it normally
  78.         else {
  79.             s@<a +href *= *\".*/(.*\.html)@<a href=\"$1@i; # get rid
  80.                 #        ^ HERE is the bug
  81.                 # This period needs to be changed
  82.                 # to mean "not a /"
  83.         # get rid of directories
  84.             s@<a +href *= *\"(.*\.html)@<a href=\"\#$1@i; 
  85.                 # add in the # sign. 
  86.             push(@body,$_); }}}    # Send off the result.
  87.     close(IN);}}        # Close off the .html file, try another.
  88.  
  89. close(INDEX);            # We are finished.
  90.  
  91. # NOW TO PUT THE WHOLE OUTPUT FILE TOGETHER:
  92.  
  93. print OUT @warning;        # Warns the user.
  94. print OUT @head;        # The header
  95. print OUT @contents;        # The table of contents.
  96. print OUT @contfoot;        # The end of the table of contents.
  97. print OUT @body;        # The full text of all the files...
  98. print OUT @foot;        # The ending.
  99.  
  100. close (OUT);            # Close up the file, we're done.
  101.  
  102.  
  103.  
  104.  
  105.