summaryrefslogtreecommitdiffstats
path: root/devtools/find-type-definition
blob: 2a99b78f9309689ebc1071c4e07d22f2505d8e6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
# See LICENSE file for copyright and license details.

type="$1"
shift 1

e="$(printf '\033\n')"

pattern1='define[[:space:]]\{1,\}\(__kernel_\)\{0,1\}'"$type"'[[:space:]]'
pattern2='typedef[[:space:]].*[[:space:]]\(__kernel_\)\{0,1\}'"$type"'\([^A-Za-z0-9_]\|$\)'

pattern='\('"${pattern1}"'\|'"${pattern2}"'\)'

find "$@" | while read f; do
	if test -L "$f" || test -d "$f"; then
		continue
	fi
	fe="$(printf '%s\n' "$f" | sed 's/\([\[*.]\|\/\|\]\)/\\&/g')"
	sed -n '/^.*'"$pattern.*"'$/p' < "$f" \
	| sed 's/\(__kernel_\)\{0,1\}'"$type/$e"'[1;31m&'"$e"'[m/g' \
	| sed "s/^/$e[35m$fe$e[m /"
done