#!/usr/local/bin/perl # Be sure to set proper path to perl above # # classgen.pl - usage: classgen.pl DIRNAME # Version 14Jan97 S.T.Myers (UPenn) # # Script to automatically generate an HTML index to a CLASS directory # containing .gif files. Works on subdirectory of current working # directory. For example, # classgen.pl CLASS1a # will index subdirectory CLASS1a putting # in file CLASS1a/CLASS1a.html # # Need library module use Cwd; # Get current working directory $dir = cwd() || die "cannot get cwd\n"; print "Found current directory to be $dir \n"; # These are some directory specific variables from command line if ( $#ARGV == 0 ) { $target = $ARGV[0]; $topfile = "$ARGV[0].html"; } else { die "usage: classgen.pl DIRNAME \n"; } # Construct target directory name $classdir = $dir . "/" . $target; print "Target directory is $classdir\n"; chdir $classdir || die "cannot chdir to $classdir\n"; system("pwd"); # Open target directory and make sorted file list opendir(DOT,".") || die "cannot opendir . "; @a = sort(readdir(DOT)); print "Found ","".@a," total files\n"; # Now make stack of gif filenames foreach $name (@a) { if ($name =~ /\.gif$/) { push(@b,$name); } } print "Found ","".@b," gif files\n"; closedir(DOT); # # Make the associative array for the sources, splitting the name # at the . and putting the number of fields in the array # foreach $name (@b) { @fields = split(/\./,$name); $src = $fields[0]; # this is the source name (eg. 16156554) $cnt = $fields[1]; # this is the field number # print "Processing $src field $cnt\n"; if ($cnt eq "0") { $srclist{$src} = 0; # A blank field } else { $srclist{$src}++ ; # increment field count } $counter{$cnt}++; # increment counter array } print "Found ","".keys(%srclist)," individual sources\n"; # Sort sourcenames @sortedkeys = sort keys(%srclist); # # Now we want to make the top-level html file if ( -e $topfile ) { die " Error: $topfile already exists "; } else { open(TOPF,">$topfile") || die "Error: cannot create $topfile "; } print "Creating HTML file $topfile\n"; # Write HTML header print TOPF "\n"; print TOPF "
\n"; print TOPF "There are ","".@b," images of ","".keys(%srclist)," sources in the database
\n"; # Construct table header print "Creating HTML table\n"; print TOPF "Source | Blank Field | Fields | ||
---|---|---|---|---|
$_ | "; if ( $srclist{$_} == 0 ) { $gif = $_ . ".0.gif" ; print TOPF "$gif | "; } else { print TOPF " | "; for ($i = 1; $i <= $srclist{$_}; $i++ ) { $gif = $_ . "." . $i . ".gif" ; print TOPF "$gif "; } } print TOPF " |
This file automatically generated on ".`date`; print TOPF "
\n"; # Write HTML footer print TOPF "\n"; print TOPF "\n"; # close files - clean up close(TOPF); # report print "Created HTML file $topfile\n";