#! /bin/csh -f
#++++++++++++++++
#.IDENTIFICATION Echo
#.LANGUAGE       C-shell
#.AUTHOR         Francois Ochsenbein [CDS]
#.ENVIRONMENT    
#.KEYWORDS       
#.VERSION  1.0   28-Sep-1994
#.PURPOSE        
#.COMMENTS       Example of a cgi-script
#----------------
#
######## Issue the standard Header #############
echo "Content-Type: text/plain"
echo ""

if ($?Vroot) then
    source $Vroot/Venv
endif
if ($?SCRIPT_NAME) then
    set debug = 0
    if ("$SCRIPT_NAME" =~ */local/*) set debug = 1
    if ("$SCRIPT_NAME" =~ */test/*) set debug = 1
    echo "#...SCRIPT_NAME=$SCRIPT_NAME (debug=$debug)"
    if ($debug>0) then
        test -d /home/francois/src/html && setenv PATH \
	/home/francois/src/html:$PATH
	echo "PATH=$PATH"
	ls -l `which cgiparm` `which cgiprint`
    endif
endif

echo "I'm in $cwd"
echo "Current Environment (umask=`umask`):"
printenv | sort | sed 's/^/    /'	# Show all environment variables
echo "===================================================="
echo "             $0"
echo " with        `cgiparm -version`"
echo "===================================================="
if ($#argv > 0) then
    echo ""
    echo "Input arguments (generated by httpd server): "
    while ($#argv > 0) 
	echo "    $1"
	shift
    end
endif

####### Get Arguments
set tt = /tmp/cgi$$
#touch /tmp/Echo.log
echo "===================================================="
echo "  Result of cgiparm -v -praw -print -csh"
echo "  (raw result in $tt, removed after 6h)"
echo "  A log is in /tmp/Echo.log"
ls -lL `which cgiparm` 
echo "===================================================="
cgiparm -v -praw -print -csh -ilog $tt -log /tmp/Echo.log \
| tee /tmp/Echo | sed 's/^/    /'
#      >& $tt.2
#cat $tt.2 ; rm $tt.2
#~francois/src/html/a.out -v -perl
####### To have the arguments in standard input, use
# cgiparm -print | ....
####### To have the arguments in $1 $2 etc..., use
# eval `cgiparm -csh`
#######################

####### Print the current Environment
echo ""
echo "======================================================================"
echo "Contents of $tt (file removed after 1hr)"
echo "======================================================================"
cat $tt
#rm -f $tt
echo ""
echo "======================================================================"
echo "A copy of 'cgiparm  -print' alone is in the file /tmp/Echo"
echo "======================================================================"
echo ""
############################
#  Cleanup done in cgiparm
############################
#echo2 "#...cleanup files /tmp/cgi*"
#cleanup.sh -v -p cgi -t 6h
exit 0
