#! /usr/bin/perl # Inspired by src2html.pl by Mark Gaither - WebTechs. # Copyright (c) 1997-1999 by Alex Schroeder $usage = "Usage: html-navigation-bar [-hd] [file.html ...] OPTIONS -h this message -d debuggin -v verbose EXAMPLES modify navigation bars in current directory html-navigation-bar convert specific files html-navigation-bar bar.html foo/bar.html This will replace the top and the bottom navigation bar with an updated equivalent constructed from link tags. A link tag looks like this: ... The top navigation bar looks like this \(ended by an empty line\):

Navigation: ... The bottom navigation bar looks like this \(ended by an empty line\):

Navigation: Top, ... "; require "getopts.pl"; &Getopts('hdv'); if($opt_h) { print $usage; exit; } if($opt_d) { $verbose = 1; $debug = 1; print "Debugging...\n"; } if($opt_v) { $verbose = 1; print "Verbose...\n"; } # Convert all files in the current directory if no file spec given on # the command line. if ($#ARGV < 0) { opendir(DIR,'.') || die "Can't open current directory: $!\n"; @srcfiles = grep(/\.html$/,readdir(DIR)); print "Files:\n", join("\n", @srcfiles), "\n" if $debug; close(DIR); } else { print "Files:\n" if $debug; foreach (@ARGV) { push(@srcfiles, $_); print "$_\n" if $debug; } } # Convert each SRC file into an HTML doc foreach $srcfile (@srcfiles) { if($srcfile =~ /~$/) { print "$srcfile is a backup. Skipping...\n"; next; } # Start with a clean variable. This will hold the entire document. my $html = ''; # Read file into $html. undef $/; open(DATA, $srcfile); $original = $html = ; close(DATA); # navigation bar based on link tags. my $navigation_bar = ''; # hash of links that is already part of $navigation_bar. my %links = {}; # Link tags while ( $html =~ //sigo ) { next if (lc $1 eq 'stylesheet') or (exists $links{$2}) or ($2 eq $srcfile); $navigation_bar .= ',' if $navigation_bar; if (lc $1 eq 'contents' or lc $1 eq 'index') { $navigation_bar .= "\n$4"; } else { $navigation_bar .= "\n$1: $4"; } $links{$2} = 1; } if ( ! $navigation_bar ) { print STDERR "No LINK tags found in $srcfile.\n" if $verbose; next; } my $replacements = 0; $replacements++ if $html =~ s|

Navigation:.*? |

Navigation: $navigation_bar |si; $replacements++ if $html =~ s|

Navigation: Top,.*? |

Navigation: Top,$navigation_bar |si; if (! $replacements) { print "Nothing replaced in $srcfile.\n" if $verbose; next; } # Don't touch the file if nothing has changed. if ( $original eq $html ) { print "No changes in $srcfile.\n" if $verbose; next; } # Backup old HTML file. rename $srcfile, $srcfile . '~'; # Write new HTML file. open(OUT,"> $srcfile") || die "Can't write to $srcfile: $!\n"; print OUT $html; close(OUT); print "Navigation bars replaced in $srcfile.\n" if $verbose; }