#!/bin/csh -f
# dir.tmp - source script for the ../htmlbin/dir script
# dir     - created from dir.tmp by Makefile
# purpose - to display the dictionary-type directory structure
#           for the jgofs data management system
#   narration added 9/30/94 clh
#   output log file entry if .log present 10/12/94 clh
#
# set stuff = the subdir that is requested - may be empty if at top level
# if we are at the top level, do nothing
# if we are at first level down, add a link to get to top
# if we are in subdirs 2 levels or below, link allows going up one level
# list the subdirectories, create a hypertext reference to the subdir, 
# name the link the same as the subdir
# to list the objects of this directory, send name of this subdir (if any)
#      and .remoteobjects to readdct2 which creates the 'obj, pi, descript' 
#      type of directory listing
# 
echo "Content-type: text/html"
echo ""

if ( "$QUERY_STRING" == "" ) setenv QUERY_STRING /globec/

echo "<h2>$QUERY_STRING -- data objects</h2><p>"
echo "<pre>"
echo "SUBDIRECTORIES"
cd /data/globec/objects$QUERY_STRING
set stuff=$QUERY_STRING
set stuff=$stuff:h
# echo stuff $stuff
if ( "$stuff" == "/globec" ) then
else
  echo "<a href="\""http:/jg/dir?/globec/"\"">Top level directory</a>"
  echo "<a href="\""http:/jg/dir?$stuff:h/"\"">Back up one directory</a>"
endif

find . -type d -print | sort | nawk '\
$1 != "." {\
  n=split($1,arr,"/");\
  for(i=1;i<n;i++)printf "   "\
  printf "<a href=\"http:/jg/dir?%s%s/\">%s</a>\n","'$QUERY_STRING'",substr($1,3,length($1)-2),arr[n]}\
'

echo ""
if ( -f .log) then
   echo `cat .log`
   echo ""
endif

if ( -e .remoteobjects) then
  echo "OBJECTS                        Click on this column for Documentation"
  echo "<hr>"
 /data/globec/htmlbin/bin/readdct2 $QUERY_STRING < .remoteobjects
endif

echo "</pre>"
