aboutsummaryrefslogtreecommitdiff
path: root/g
blob: 0a228922a7684312a7c881e9600a7d6f484a5370 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh

IFS='
'

pat=
opt=
i=0

while [ $((i++)) -lt $# ]; do
	case "$1" in
	-*)	opt=`printf '%s%s\n' "$opt" $1`
		shift ;;
	*)	break ;;
	esac
done

[ $# -eq 0 ] && { echo usage: $0 [-...] pattern [file ...] 1>&2; exit 1; }

pat=$1
shift

files=`find . -name '*.c' -or -name '*.h' -or -name '*.cc' | sed s,./,,`
[ -z "$files" ] && [ -z "$*" ] && { echo no matching files found 1>&2; exit 1; }

# todo (?): treat argument \*.x like -or -name \*.x

p grep $opt -n "$pat" $files "$@"