#!/usr/bin/perl # # $Id: dir2htm,v 1.3 1997/10/11 00:41:59 vogelke Exp $ # # NAME: # dir2htm # # SYNOPSIS: # dir2htm # # DESCRIPTION: # Reads an index of contents (index.cnt), and writes a corresponding # index.htm file. # # SAMPLE INPUT: # A Karl Vogel (vogelke@c17.com) # U Revision/Date information. # T Document collections # N admin # C Holds documents useful for administrators, such as: # C - protecting your system through disclaimers and warnings # C - liability # # AUTHOR: # Karl E. Vogel # Sumaria Systems, Inc. eval 'exec perl -S $0 ${1+"$@"}' # If the shell can't handle "#!", if 0; # fire up perl directly. $ENV{"PATH"} = "/bin:/usr/sbin:/usr/local/bin"; ($myname) = split (/\//, reverse ($0)); $myname = reverse ($myname); # script basename. # # Set up common strings and indenting. # $max = 25; # number of spaces at start of a line. $fmt = "%" . $max . "." . $max . "s"; $nlspaces = sprintf ("$fmt", " "); # spaces at start of new comment line. # # Main loop. # open (IN, "index.cnt") || die "no index.cnt file: $!\n"; open (STDOUT, "> index.htm") || die "can't redirect stdout: $!\n"; $remaining = 0; while () { chop; next if /^#/; next if /^\s*$/; if (/^A /) { s/^A //g; $author = $_; } elsif (/^U /) { s/^U //g; s/\$Revision://g; s/\$Date://g; s/ \$//g; $version = $_; } elsif (/^T /) { s/^T //g; $title = $_; &printheader; } elsif (/^N /) { s/^N //g; $collection = 1; $name = $_; if (-d $name) { print ""; print " $name"; } if (-f $name) { print ""; print " $name"; } } elsif (/^C /) { s/^C //g; if ($collection == 1) { $collection = 0; $count = $max - length ($name) - 3; $spaces = substr ($nlspaces, 0, $count); print "$spaces"; } else { print "$nlspaces"; } print "$_\n"; } elsif (/^R /) # remaining lines to be printed unchanged. { print "
\n"; $remaining = 1; last; } else { print "unknown: $_\n"; } } while () { print; } close (IN); print "" if $remaining == 0; &printtrailer; exit (0); # ------------------------------------------------------------------- # print HTML header. sub printheader { $top = "/space/html/htdocs"; # top-level directory for use with # creating parent-directory link. chop ($_ = `pwd`); # get working directory... s,^$top,,g; # ...zap top-level part... $_ = "/" if $_ eq ""; $pos = rindex ($_, "/") + 1; $parent = substr ($_, 0, $pos); # Get name and description spaced properly. $count = $max - length ("Name") - 3; $spaces = substr ($nlspaces, 0, $count); $topline = "Name" . $spaces . "Description"; print <<"EndofHeader"; $title

$title

 $topline

Parent Directory EndofHeader } # ------------------------------------------------------------------- # print HTML trailer. sub printtrailer { print <<"EndofTrailer";
Author: $author
Version: $version, created by $myname
EndofTrailer }