#!/bin/csh -f
#
#   Name: add_path
#
#   Purpose: add input paths to users UNIX path (avoid)
#
#   Switches: 
#      /prepend - prepend paths (only paths which follow switch)
#      /loud    - echo some status information
#
#   Calling Sequence
#      source add_path path1 [path2 path3...]  # append paths
#        OR
#      source /prepend path1 [path2 path3...]  # prepend paths
#
#   History
#      29-jun-1995 S.L.Freeland
#
#

set newpaths=""
set curp=$PATH			# bracket with delimiters
set prepend="0"			# default is append
set loud="0"
set new=""

foreach arg ($argv)
   switch ($arg)
      case /prepend:
      case  prepend:
         set prepend="1"
      breaksw
      case /loud:
      case  loud:
         set loud="1"
      breaksw
      default:
         if (-d $arg) then 
            set chk=`echo ":"$curp":" | grep ":"$arg":"`        
            if ("$chk" == "") then
               set new=($new $arg)
               if ($prepend) then
                  set curp=$arg":"$curp
               else
                  set curp=$curp":"$arg
               endif
            endif
         else
            echo $arg" is not a valid directory"
         endif
   endsw         
end

if ($loud) then
   if ($new[1] == "") then
      echo "No new paths - PATH not changed..."
   else
      echo "Paths added: "$new
   endif
endif

eval setenv PATH $curp

exit
