#!/bin/ash
# muFind 0.0.3 by Andrea Manzini <linux@netbusiness.it>
# patch by Ed Hynan <ehy@delphi.com> 

LS=/bin/ls

for F in $@; do
case $F in
    -name|-user|-h) C=$F; continue;;
    -print) L=$F; continue;;
esac
if [ -d "$F" ] ; then P=$F;
else R=$F; fi
done

[ "$C" ] || C="-name"
[ "$R" ] || R="a*"
[ "$P" ] || P="."

case $C in
-name) { echo "$P"; $LS $P -1UAR | sed -n '/:$/P'
} | tr -d ':' | while read D; do
 $LS $D -1UA | sed -n "/$R/P" | while read F; do
   [ "$D" = '/' ] && echo "/$F" || echo "$D/$F"
 done
done ;;
-user) $LS $P -FURAo | sed -n "/ $R /P" ;;
-h) cat <<EOF
Usage: find [path] [-name|-user regexp] [-print]
	-- filename regexp is greedy. I.E. foo will match *foo*
	-- example: find / -name runlevels
EOF

;;
*) cat <<EOF
Error: no valid command specified 
valid commands are: -h -name -user [-print]
EOF
 
;;
esac
