#!/usr/local/bin/perl # # script name: dir # used from : /data/globec/htmlbin # converted from dir (/bin/csh script) originally written by Glenn Flierl # Christine Hammond # April 12, 1996 # # added documentation for buttons # CLH # May 14,1996 # # modified to accept a .remoteobjects entry such as # stuff=//globec.whoi.edu/test(station=7,press<100) # and turn it into # http://globec.whoi.edu/jg/serv/test.html0?station=7,press<100 # CLH, per GRF's suggestion # December 13, 1996 # # # Note: this script uses images/youhere.gif, # images/helpb.gif, # images/homeb.gif # which can be downloaded from anonymous ftp # on dataone.whoi.edu (128.128.80.28) in pub/images # # NOTE: Please change the values for the entries below # to those that will work on your machine # Additionally, links to buttons at the top of the directory display # can easily be added. See note "To add buttons" below. # ############ Customized values for this site ################### $jghome="/data/globec"; $topdir="/globec/gb/"; $infoserver="//globec.whoi.edu"; $homeurl=""; # # in DocumentRoot (srm.conf), name of file with help info # $helpfile="http://www1.whoi.edu/dir-help.html"; # # DMO name # $office=""; # ############ End of Custom values for this site ################ # $dictionary=".remoteobjects"; $logentry=".log"; $dirspacer = " "; $jgroot=$jghome."/objects"; print "Content-type: text/html\n\n"; # # Locate directory to display # if ($ENV{'QUERY_STRING'}) { $currentdir = $ENV{'QUERY_STRING'}; } else { $currentdir = $topdir; } $curdir = $currentdir; chop($curdir); print "$currentdir data directory page\n"; chdir("$jgroot$currentdir"); # # At the toplevel directory, check for files describing # the system (dirhead) and explaining the organization (direxplain) # if ($currentdir eq $topdir) { if (-r "dirhead") { open(INFILE,"dirhead") || die "Can't open input file: $!\n"; while () { print; } close(INFILE); } if (-r "direxplain") { open(INFILE,"direxplain") || die "Can't open input file: $!\n"; while () { print; } close(INFILE); } } # # Display the Links at top of Directory page # To add buttons: create a button GIF file by creating a simple html doc with # the commands
#
# grab the image that is displayed (use snapshot (on a Sun), # or xwd) then, xv does a nice job with cropping and saving # as a GIF. Refer to the 2nd print statement below, and # duplicate the 3rd and 4th lines of the continued print # (starts with $office Data System\n"; # # Following is the print statement that prints the buttons # print "

\ \ \ \

"; print "
\n";
#
# Check that there is some data to display (.remoteobjects or .log)
#

if (-r $dictionary || -r $logentry) {

   print "\n

Directory of Data in $currentdir

\n"; if (-r $logentry) { &readdct($logentry); print "\n"; } if (-r $dictionary) { print "Data Investigator Description and Documentation\n"; print "
\n"; &readdct($dictionary); } print "
\n"; } # # Always print the directory categories of data in the jgroot # print "

$office Data Categories

"; print "Go to the indicated category of data by clicking on its name\n"; print "

\n"; # # First, find all subdirectories in the given tree # open(FIND,"find $jgroot$topdir -type d -print| sort |"); $|=1; while ($dir = ) { chop $dir; # # find all subdirectories containing 'objects' and the top of the tree # if ($dir =~ /\/objects\// && $dir =~ /$topdir/) { # # the url pathitem for the link starts at $topdir # $urldir = substr($dir,(rindex($dir,$topdir))); # # strip final '/' from $topdir (only one that has it), printf will insert it. # if ($urldir eq $topdir) { $urldir = substr($topdir,0,(rindex($topdir,"/"))); } @subdirs = split(/\//,$dir); foreach $diritem (@subdirs) { print $dirspacer; } @revlist = reverse(@subdirs); # # get tail of directory list - last item in array of directories # $diritem = shift(@revlist); # # mark the current directory being displayed by an arrow # if ($curdir eq $urldir) { printf " %s \n",$urldir,$diritem; } else { printf " %s\n",$urldir,$diritem; } # } } close(FIND); print "<\pre>\n"; # -------------------------Subroutines---------------------------- sub readdct{ local($whichone) = pop(@_); local($dictentry); local($i) = 0; local($ndx) = 0; open(INFILE,"$whichone") || die "Can't open input file: $!\n"; while ($dictentry = ) { $i++; chop($dictentry); # # 1st line has object=serving-host entry # if ($i == 1) { $dispobj=substr($dictentry,0,index($dictentry,"=")); $rightside=substr($dictentry,(index($dictentry,"=")+1)); # # syntax of serving host entry can include full url: http:/jg/serv/test.html0 # if ((index($rightside,":/")) > 1) { printf("%-18s", $rightside, $dispobj); # # find string /jg/serv and move to string just beyond it # $ndx = index($rightside,"/jg/serv/",0)+8; # # now have to remove the .html0 extension from objectname # $fullobj=substr($rightside,$ndx,(rindex($rightside,".htm")-$ndx)); # # enhancement to catch entries with subselections - htmlify them # } elsif ($rightside =~ /\/\/.+\(.+\)/ ) { $ndx = index($rightside,"("); $servhost=substr($rightside,0,index($rightside,"/",2)); $fullobj=substr($rightside,index($rightside,"/",2), $ndx-index($rightside,"/",2)); $subselections=substr($rightside,$ndx+1,length($rightside)-$ndx-2); printf("%-18s", $servhost, $fullobj, $subselections, $dispobj); # # and then, there are "regular" entries # } else { $servhost=substr($rightside,0,index($rightside,"/",2)); $fullobj=substr($rightside,index($rightside,"/",2)); printf("%-18s", $servhost, $fullobj, $dispobj); } } elsif ($i == 3) { # # 3rd line, infoserving-host and the description of the data # $infohost=$infoserver; # # first, check that anything is there # if (length($dictentry) > 2) { if ($dictentry =~ /\/jg\/info/) { # # a space separates the info serving host from the description # $ndx = index($dictentry," ",2); $infohost = substr($dictentry,2,$ndx-2); $descript = substr($dictentry,$ndx+1); # # when info serving host entry ends in '/', use same object name as displayed # if (substr($infohost,-1,1) eq '/') { printf(" %s\n", $infohost, $dispobj, $descript ); # # otherwise, assume objname (x of x.info file) is provided # } else { printf(" %s\n", $infohost, $descript ); } } else { $descript = substr($dictentry,2); printf(" %s\n", $infohost, $fullobj, $descript ); } # # finish the line displayed for this directory entry # } else { printf("\n"); } $i = 0; } else { # # the PI name is on the 2nd line of a dictionary entry # if (length($dictentry) < 3) { printf("%-20s", " "); } else { printf("%-20s", substr($dictentry,2)); } } } close(INFILE); }