#!/usr/bin/perl # -*- perl -*- # # htdblist.cgi - generate a list of elements in a database directory # RMM, 15 Mar 97 # # This CGI script generates a listing of the contents of a directory # using the description files contained in the directory to format the # data as desired. # # This script should be called as # # http://machine/path/htdblist.cgi? # or # http://machine/path/htdblist.cgi?db=&args # # where is the name of the configuration file that defines # all of the information needed to generate the listing. The optional # arguments are: # # count=NN only list the first NN entries # tight=1 use tight listing # ssi=1 don't print header, trailer info (for includs) # # Include the necessary libraries require "cgi-lib.pl"; require "htdblib.pl"; if (&htdbinit) { # Get the names of the files in the database directory $getfnames = defined &GetFnames ? \&GetFnames : htdb::GetFnames; if (@filenames = &{$getfnames}($DBPath)) { # Generate the context header for the browser print &PrintHeader; # Now print out the title information if (defined &ListHeader) {$listheader = \&ListHeader}; if (not $listheader) {$listheader = \&htdb::ListHeader;} &{$listheader}($DBName) if (!$in{ssi}); # Print the contents of the database &PrintContents(@filenames); # Generate the trailer if (defined &dbtrailer) {$dbtrailer = \&DBTrailer}; if (not $dbtrailer) {$dbtrailer = \&htdb::DBTrailer;} &{$dbtrailer}($DBName) if (!$in{ssi}); } elsif (!$in{ssi}) { &CgiError("HTDB error: cannot access database or database empty"); } } # # Subroutine for printing the contents of the database # sub PrintContents { local (@filenames) = @_; local ($count); # keep track of number of items printed # Check to see if there is a user function for parsing filenames if (defined &ParseFname) {$parsefname = \&ParseFname}; if (not $parsefname) {$parsefname = \&htdb::ParseFname;} # Check to see if there is a user function for printing the entry if (defined &PrintEntry) {$printentry = \&PrintEntry}; if (not $printentry) {$printentry = \&htdb::PrintEntry;} # Check to see if there is a user function for printing the entry if (defined &TightEntry) {$tightentry = \&TightEntry}; if (not $tightentry) {$tightentry = \&htdb::TightEntry;} # Print the command to generate a list of elements print ($in{tight} ? "
    \n" : "
    \n"); # Loop through the files in the database directory $count = 1; for (@filenames) { # Parse the filname and extract the ID and tag information ($id, $tag) = &{$parsefname}($filename = $_); next if not $id; # Open the file and extract the contents $contents = &htdb::readfile($filename); next if not $contents; # Print out the information associated with this entry $count += &{($in{tight} ? $tightentry : $printentry)} ($filename, $contents, $id, $tag, $DBURL."/".$filename); # See if we are counting and stop if needed last if ($in{count} && $count > $in{count}); } print ($in{tight} ? "
\n" : "\n"); }