#! /bin/csh -f
#
#/*****************************************************************************
#                Copyright Carnegie Mellon University 1992
#
#                      All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of CMU not be
# used in advertising or publicity pertaining to distribution of the
# software without specific, written prior permission.
#
# CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
# CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
#*****************************************************************************/
#
#
# Written by Allan Heydon for the Miro project at Carnegie Mellon
#
# SYNTAX
#   searchfs [path]
#
# SYNOPSIS
#   Recursively searches the filesystem tree rooted at 'path', printing the
#   protection, owner, and group-owner information of each node in the tree.
#   The argument 'path' defaults to the current directory.
#
# FILES
#   /usr/miro/libi/awk/ls-lgR.awk	awk file for printing relevent info
#
# SEE ALSO
#   fs2iff(1), searchpath(1)

# handle case where 'path' not specified
if ( $#argv < 1 ) then
  set pathname = $cwd
else
  set pathname = $1
endif

# respond differently to files and directories
if ( -f "$pathname" ) then
  ls -lg $pathname | awk -e '{ printf("%s %-8s %-8s %s\n",$1,$3,$4,$9); }'
else if ( -d "$pathname" ) then
  set tempfile = /tmp/searchfs-$$.txt
  ls -ldgF $pathname > $tempfile
  echo "${pathname}:" >> $tempfile
  ls -algRF $pathname >> $tempfile
  awk -f /usr/miro/libi/awk/ls-lgR.awk < $tempfile | sort +3 -
  rm -f $tempfile
else
  echo "$0: Neither directory nor file: $pathname"
endif
