#!/usr/local/bin/perl -w # foliate v. 21 Dec 1995, Dave Schweisguth # Indexes digest2html output files and links them to each other and the index # Inspired by work by Tom Fine # Version history # --------------- # 21 Dec 1995 First release. ### Preliminaries # Emulate #!/usr/local/bin/perl on systems without #! eval '(exit $?0)' && eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}' & eval 'exec /usr/local/bin/perl -S $0 $argv:q' if 0; require 5; # Perl 5 required, 5.001m recommended ### Constants # Environment ($whatami = $0) =~ s|.*/||; # `basename $0` chop($date = `date '+%d %b %Y'`); # dd Mon yy # Configuration $force = 0; # Overwrite existing files $horiz = 1; # Make horizontal links between digests $vert = 1; # Make vertical links to top index $top = 1; # Make top index $index = 'index.html'; # Name of entry point in each directory $tlb = "\n"; # Link insertion points $tle = "\n"; $blb = "\n"; $ble = "\n"; $author = 'The SGI FAQ group'; $email = 'sgi-faq@viz.tamu.edu'; $whereami = 'http://www-viz.tamu.edu/~sgi-faq/tools/'; $toptitle = 'SGI Frequently Asked Questions (FAQs)'; ### Arguments and error-checking # Parse args $arg = ''; # Perl 5 lossage alert while ($#ARGV > -1 && (($first, $rest) = ($ARGV[0] =~ /^-(.)(.*)/))) { # Perl 5 lossage alert if ($first =~ /[\0]/) { # Switches with arguments (none at the moment) shift; $arg = $rest ne '' ? $rest : $ARGV[0] ne '' ? shift : &usage("$whatami: -$first requires an argument.\n"); } elsif ($rest ne '') { $ARGV[0] = "-$rest"; } else { shift; } if ($first eq 'f') { $force = 1; } elsif ($first eq 'h') { $horiz = 0; } elsif ($first eq 'v') { $vert = 0; } elsif ($first eq 's') { $short = 1; } elsif ($first eq 't') { $top = 0; } elsif ($first eq 'u') { &usage(0); } else { &usage("$whatami: -$first is not an option.\n"); } } sub usage { local ($message) = $_[0]; warn $message if $message; warn <([^<]*)<\/title>/ && ($titles[$n] = $1), ); close IN; } # Make top-level index # Do this first, so if $index exists we'll die before doing anything else if ($top) { if (-e $index && ! $force) { die "$whatami: Output file $index already exists!\n"; } open(OUT, ">$index") || die "$whatami: Can't write to $index!\n"; select OUT; print < $toptitle

$toptitle

    EOP foreach $n (0 .. $#infiles) { print "
  • $titles[$n]\n"; } print <
    $author <$email>
    Generated by $whatami, $date
    EOP close OUT; } # Process input files foreach $n (0 .. $#infiles) { open(IN, $infiles[$n]) || die "$whatami: Can't read $infiles[$n]!\n"; @buf = ; close IN; open(OUT, ">$infiles[$n]") || die "$whatami: Can't write to $infiles[$n]!\n"; select OUT; # Print file over itself, substituting links as we go $i = 0; until ($buf[$i] eq $tlb) { # Print lines up to TOP LINK BEGIN print $buf[$i]; $i++; } print $buf[$i]; # Top Up/Next/Previous links print "Up: $toptitle\n" if $vert; if ($horiz && $n < $#infiles) { print "
    \n" if $vert; print "Next: $titles[$n+1]\n"; } if ($horiz && $n > 0) { print "
    \n" if $vert || $n < $#infiles; print "Previous: $titles[$n-1]\n" } print "
    \n" if $vert || ($horiz && $n > 0 && $n < $#infiles); until ($buf[$i] eq $tle) { # Skip lines between BEGIN and END $i++; } until ($buf[$i] eq $blb) { # Print lines up to BOTTOM LINK BEGIN print $buf[$i]; $i++; } print $buf[$i]; # Bottom Up/Next/Previous links print "
    \n" if $vert || ($horiz && $n > 0 && $n < $#infiles); print "Up: $toptitle\n" if $vert; if ($horiz && $n < $#infiles) { print "
    \n" if $vert; print "Next: $titles[$n+1]\n"; } if ($horiz && $n > 0) { print "
    \n" if $vert || $n < $#infiles; print "Previous: $titles[$n-1]\n" } until ($buf[$i] eq $ble) { # Skip lines between BEGIN and END $i++; } while ($i <= $#buf) { # Print the remainder print $buf[$i]; $i++; } close OUT; } exit;