#!/usr/local/bin/perl # # updates the index.html file in the current directory # by including a listing of all the other html files in the directory. # # Uses the last-modified date stamp on each file to see if there is # any work to do (ie if any other files are newer than index.html). # # If there's some text in the document titles that you *don't* want # in the index, include it in $remove below, or with -remove on # the commandline (eg -remove=xxx). # # Earl Fogel, July 1996 $startpat = ""; $endpat = ""; # use -remove=xxx to remove 'xxx' from all titles # or define $remove (eg. $remove="xxx";) while ($_ = $ARGV[0], /^-/) { shift; last if /^--$/; /^-remove=(.*)/ && ($remove=$1); } ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat("index.html"); $indexchangetime = $mtime if -r _; $somethingtodo = 0; while (<*.html>) { ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($_); $somethingtodo=1 if $mtime > $indexchangetime; # print "$_ is newer\n" if $mtime > $indexchangetime; } exit if ! $somethingtodo; # read in the existing file open (INDEX, "index.html") || die("can't read index.html\n"); @index = ; close(INDEX); # now create a new one open (INDEX, ">index.html") || die("can't write index.html\n"); # check file for ending pattern # if it's not there, we'll insert it foreach $line (@index) { $OKendpat = 1 if $line =~ /$endpat/i; } foreach $line (@index) { $skipping = 0 if $line =~ /$endpat/i; print INDEX $line if ! $skipping; if ($line =~ /$startpat/i && ! $done) { &InsertList; print INDEX "$endpat\n\n" if ! $OKendpat; $done = 1; $skipping = 1 if $OKendpat; } } # if we can't find where it belongs, add it to the end of the file if (! $done) { print INDEX "\n$startpat\n"; &InsertList; print INDEX "$endpat\n\n"; } close(INDEX); sub InsertList { while (<*.html>) { next if /^index.html/; $fname = $_; $title = $fname; if (open (IN, $_)) { while () { if (s/.*//i) { chop; s/$remove//i if defined($remove); s/<.title>.*//i; $title = $_; } } close(IN); print INDEX "<a href=\"$fname\">$title</a><br>\n"; } } }