#!/bin/csh -f

# user needs to supply:
# --htdocs : top-level of www files

set htdocs  = ""
set args    = ""
set VERBOSE = 0

while ("$1" != "") 
 switch ("$1")
  case --htdocs*
   if ("$1" == "--htdocs") then
     shift
     set htdocs = $1
   else
     set htdocs = `echo $1 | tr = ' ' | awk '{print $2}'`
   endif
   breaksw;
  case -v:
  case --verbose:
   set VERBOSE = 1;
   breaksw;
  case -h:
  case --help:
   goto usage
  default:
   set args=($args $1);
   breaksw;
 endsw
 shift
end

if ($#args != 2) goto usage

if ($VERBOSE) then
  echo
  echo "htdocs: $htdocs"
  echo "input : $args[1]"
  echo "output: $args[2]"
endif

if ("$htdocs" == "") goto usage

cat $args[1] | sed "s|@HTDOCS@|$htdocs|" > $args[2]
exit 0

usage:
if ($#args > 2) then
  shift args
  shift args
  echo unrecognized options: $args
endif

cat <<EOF

  USAGE: generate [OPTION] (input) (output)
  
  replace install-time options in scripts
  
  set the WWW installation directory root with --htdocs
  
  switches:
    -h, --help              display this help and exit
    --htdocs (required)     set the top-level directory

EOF
 exit 2;
