#! /bin/csh -f
# Lists all directories in $2-* which contain $1.
# If only $1 is given, searches in current path.

if ( $#argv == 0 ) then
  echo "usage: search-path name directories..."
  exit 1
endif

set f = $1
if ( $#argv == 1 ) then
  set ds = ( $path )
else
  set ds = ( ${argv[2-]} )
endif

set found = 0
foreach d ( $ds )
  if ( ! -e $d ) then
    echo "$d doesn't exist"
  else if ( ! -d $d ) then
    echo "$d is not a directory"
  else if ( ! -r $d ) then
    echo "$d is not readable"
  else if ( -e $d/$f ) then
    if ( ( ! $found ) && ( ! -d $d/$f ) && ( -x $d/$f ) ) then
      echo -n '* '
      set found = 1
    else
      echo -n '  '
    endif
    /bin/ls -ld $d/$f
  endif
end
