#!/bin/csh
setenv OPTHOME /data/wsass/port8200/wjsOOserver-Oct09
setenv OPTRUNDIR optbin
#
setenv MYADDR optserv1.whoi.edu:8200
setenv DEFAULT_PORT 8200
setenv JGTEMP /data/wsass/port8200/wjsOOserver-Oct09/htdocs/jgofsopt/8200
#
# check that the temporary directory exists and that it has all setup
#    info/data in it that any of the menu items needs
#  mod November 2, 1998 - clh - move here so all items need not dup code
#       note that REMOTE_HOST is environment of HTTPD
#  mod December 15, 1998 - clh - add conditional use of REMOTE_HOST
#       hosts w/o DNS name cannot serve - REMOTE_ADDR always served
if (${?REMOTE_HOST}) then
  set remotehost_dir=$REMOTE_HOST
else
  set remotehost_dir=$REMOTE_ADDR
endif

set realtempdir=${JGTEMP}/$remotehost_dir
setenv USETEMPDIR $realtempdir
setenv USETEMPADDR http://optserv1.whoi.edu:8200/jgofsopt/8200/$remotehost_dir

# check that the temporary directory exists and that it has all setup
#    info/data in it that any of the menu items needs
if (${?PATH_INFO}) then
  set tmp=$PATH_INFO
  set ext=$tmp:e
  if ("$ext" == "") then
     set ext=`cat $realtempdir/proto-lev`
     setenv PROTOLEV $ext
     setenv OBJEXT "$tmp.$ext"
  else
     setenv OBJEXT $tmp
#       OMITTING FOR TESTING: echo $ext > $realtempdir/proto-lev
  endif
  setenv PROTOLEV $ext
  setenv OBJECT $tmp:r
#       OMITTING FOR TESTING: echo $ext > $realtempdir/proto-lev
  endif
  setenv PROTOLEV $ext
  setenv OBJECT $tmp:r
#       OMITTING FOR TESTING: echo "$OBJECT" > $realtempdir/obj
  setenv URLOBJ `${OPTHOME}/bin/fixurl "${OBJECT}"`
  setenv URLOBJX "${URLOBJ}.$ext"
  setenv SUBSELS ""
  setenv SUBSELS_QS ""
  setenv DISPSS ""
  setenv DISPOBJ "${OBJECT}"
endif
if ( ${?QUERY_STRING} && "$QUERY_STRING" != "" ) then
  set subsels_qs="$QUERY_STRING"
  setenv SUBSELS_QS "$subsels_qs"
#
# Check QS for htmlescaped operator - if found, unescape for subsels
#      ex: press&lt;200 --->  press<200
#
  set found=`${OPTHOME}/bin/strpbrk "$subsels_qs" "&;"`

  if ($found == "yes") then
    set subsels=`${OPTHOME}/bin/htmlunesc "$subsels_qs"`
  else
    set subsels=$subsels_qs
  endif
  set subsels=`${OPTHOME}/bin/trigram_util "$subsels"`
  setenv SUBSELS "$subsels"
#       OMITTING FOR TESTING: echo "$SUBSELS" > $realtempdir/sel
#
# Check QS for operator that should be htmlescaped for displaying
#      ex: press<200 --->  press&lt;200
#
  set found=`${OPTHOME}/bin/strpbrk $subsels "<>"`

  if ($found == "yes") then
    set dispss=`${OPTHOME}/bin/htmlesc "$subsels"`
  else
    set dispss="$subsels_qs"
  endif
  set dispss=`${OPTHOME}/bin/trigram_util -un "$dispss"`
  setenv DISPSS "$dispss"
  setenv DISPOBJ "${OBJECT}($dispss)"
endif
printenv
