r4083 - in developers/tick: . scripts

tick at sita.openmoko.org tick at sita.openmoko.org
Mon Feb 18 10:42:21 CET 2008


Author: tick
Date: 2008-02-18 10:42:18 +0100 (Mon, 18 Feb 2008)
New Revision: 4083

Added:
   developers/tick/scripts/
   developers/tick/scripts/chout
Log:
put a grep script


Added: developers/tick/scripts/chout
===================================================================
--- developers/tick/scripts/chout	2008-02-17 10:50:35 UTC (rev 4082)
+++ developers/tick/scripts/chout	2008-02-18 09:42:18 UTC (rev 4083)
@@ -0,0 +1,97 @@
+#!/bin/bash
+#composer Tick
+
+function usage {
+if (( $#==0 ));then
+    echo "USAGE: chout [-i] [-<name|type|dir> <FILE|TYPE|DIR>] <Keywords>"
+    echo "Example: chout DEBUG                    <-- finding files contain DEBUG"
+    echo "Example: chout -name '*.pro' DEBUG      <-- finding DEBUG from pro files"
+    echo "Example: chout -dir /tmp/ -type f DEBUG <-- all files in specific directory"
+    echo "Example: chout -i DeBuG                 <-- ignore case"
+    echo "Other flags: -cmin -ctime"
+    echo "Please reference to \"man find\""
+    exit
+fi
+}
+
+usage $@
+ICASE=" "
+DIR=" "
+NAMEFLAG=" "
+NAME=" "
+TYPEFLAG=" "
+TYPE=" "
+CMINFLAG=" "
+CMIN=" "
+CTIMEFLAG=" "
+CTIME=" "
+ares=" "
+
+
+while (( $# > 1 )) && ( [ "$1" == "-dir" ]  || [ "$1" == "-i" ]  || [ "$1" == "-name" ] || [ "$1" == "-type" ]  || [ "$1" == "-ctime" ] || [ "$1" == "-cmin" ]   );do
+     if  [ "$1" == "-dir" ];then
+        shift
+        DIR="$1"
+     elif [ "$1" == "-type" ];then 
+     	shift
+        TYPEFLAG="-type"
+	TYPE="$1"
+     elif [ "$1" == "-name" ];then
+        shift 
+	NAMEFLAG="-name"
+	NAME="$1"
+     elif [ "$1" == "-i" ];then
+     	ICASE=" -i"
+     elif [ "$1" == "-ctime" ];then
+     	shift
+     	CTIMEFLAG="-ctime"
+	CTIME="$1"
+     elif [ "$1" == "-cmin" ];then
+     	shift
+     	CMINFLAG="-cmin"
+	CMIN="$1"
+     else
+     	echo break time $@
+        break
+     fi
+     shift
+done
+usage $@
+
+if [ "$ares" != " " ];then
+ echo -n ""
+elif 		   [ "$TYPEFLAG" == " " ] \
+		&& [ "$NAMEFLAG" == " " ] \
+		&& [ "$CTIMEFLAG" == " " ] \
+		&& [ "$CMINFLAG" == " " ] \
+		;then 
+	#echo DIR=$DIR
+	ares="`find ${DIR} -name '*.h'` `find ${DIR} -name '*.c'` `find ${DIR} -name '*.cpp'`"
+else
+	if [ "${NAME}" == " " ];then
+		ares=`find ${DIR} ${CTIMEFLAG} ${CTIME} ${CMINFLAG} ${CMIN} ${TYPEFLAG} ${TYPE}`
+	else 
+		#echo "find ${DIR} ${CTIMEFLAG} ${CTIME} ${CMINFLAG} ${CMIN} ${TYPEFLAG} ${TYPE} ${NAMEFLAG} \"${NAME}\""
+		ares=`find ${DIR} ${CTIMEFLAG} ${CTIME} ${CMINFLAG} ${CMIN} ${TYPEFLAG} ${TYPE} ${NAMEFLAG} "${NAME}"`
+	fi
+
+fi
+
+target=" "
+while (( $# > 0 ));do
+   target="$target -e $1"
+   shift
+done
+
+for arrs in $ares ;do
+ if (( `file $arrs | grep "text" | wc -l ` == 0 ));then
+  #echo $arrs is binary
+  continue
+ fi
+ if [ -f $arrs ] && (( `cat $arrs | grep ${ICASE} ${target}  | wc -l` > 0 )); then
+  echo "In file $arrs"
+  grep --color -n ${ICASE} ${target} $arrs
+  #awk '{print NR":\t"$0}' $arrs | grep ${ICASE} $1 | sed -n "s/${target}/&/p"
+  echo " "
+ fi
+done


Property changes on: developers/tick/scripts/chout
___________________________________________________________________
Name: svn:executable
   + *





More information about the commitlog mailing list