From aa968963d81e0b3df42df02fcb6ddb03ac6d27c3 Mon Sep 17 00:00:00 2001 From: Scott McCreary Date: Thu, 16 Jun 2011 01:55:36 +0000 Subject: [PATCH] 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. --- sys-apps/hgrep/hgrep | 10 +++++++++ sys-apps/lgrep/lgrep | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100755 sys-apps/hgrep/hgrep create mode 100755 sys-apps/lgrep/lgrep diff --git a/sys-apps/hgrep/hgrep b/sys-apps/hgrep/hgrep new file mode 100755 index 000000000..737e5a2dd --- /dev/null +++ b/sys-apps/hgrep/hgrep @@ -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? diff --git a/sys-apps/lgrep/lgrep b/sys-apps/lgrep/lgrep new file mode 100755 index 000000000..aa9a00c41 --- /dev/null +++ b/sys-apps/lgrep/lgrep @@ -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\] \ + echo \- list files containing \ + 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