#!/bin/csh -f
#
# usage: find [dir] filename [outputfile]
#
# quick and easy find
# assumes root directory unless directory spezified
#
set noglob                              # prevent file expansion
set com = $0                            # save command name

if (-d $argv[1]:q) then
  set p = $argv[1]                      # arg1 = directory
  shift                                 # remove first argument
else
  set p = /                             # use root-directory as default
endif

if ($#argv == 1) then
  set tf = /tmp/$com:t.$$               # set up temp file
else if ($#argv == 2) then
  set tf = $argv[2]
else
  echo "usage: $com:t [path] filename [outfile]"
  exit 1                                # error exit
endif

# throw away diagnostic output; standard output in $tf
((find $p -name $argv[1] -print | tee $tf) > /dev/tty) >& /dev/null

if (-z $tf) then                        # no output from find
  echo "$com:t: Can't find $argv[1]."   # failure message
  rm -f $tf                             # remove temp file
  exit 1                                # error exit
endif
if ($#argv == 1) rm -f $tf              # remove temp file
exit 0                                  # normal exit
