Initial addition of hgrep and lgrep scripts from http://dev.haiku-os.org/ticket/3376

TODO make use of finddir where useful, perhaps nicer usage displays.
This commit is contained in:
Scott McCreary
2011-06-16 01:55:36 +00:00
parent 660785a457
commit aa968963d8
2 changed files with 60 additions and 0 deletions

10
sys-apps/hgrep/hgrep Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
#
# Copyright 2011, Haiku, Inc. All Rights Reserved.
# Distributed under the terms of the MIT License.
#
find $(finddir B_COMMON_DEVEOP_DIRECTORY/headers -type f -print0 | xargs -0 egrep "$@"
# TODO add other header directories to search?

50
sys-apps/lgrep/lgrep Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/sh
#
# Copyright 2011, Haiku, Inc. All Rights Reserved.
# Distributed under the terms of the MIT License.
#
usage() {
echo `basename $0` \[-V\] \<symbol\>
echo \- list files containing \<symbol\>
echo " -V lists also directories searched"
echo ""
echo `basename $0` -h
echo \- Show this help
exit 0
}
if [ "$1" == "-V" ]; then
VERBOSE=1
shift
else
VERBOSE=0
fi
if [ "$1" == "-h" ]; then
usage
fi
if [ "x$1" == "x" ]; then
usage
fi
LPATH=`echo $LIBRARY_PATH|sed "s|%A/lib:||"`
[ -d ./lib ] && LPATH="./lib:$LPATH" || true
LPATH=`echo $LPATH|sed "s/:/ /g"`
TEMPFILE=/boot/var/tmp/`basename $0`.$PPID
for libdir in `echo $LPATH`; do
if [ "$VERBOSE" == "1" ]; then
echo Searching in \"$libdir\"...
fi
for lib in $libdir/*.so ; do
echo "[ $lib ]" > $TEMPFILE
(nm -D $lib 2>/dev/null)|grep $1 >> $TEMPFILE
LINES=`wc -l $TEMPFILE | awk '{ print $1; }'`
if [ "$LINES" != "1" ]; then
cat $TEMPFILE
fi
done
done
rm -f $TEMPFILE