summaryrefslogtreecommitdiffstats
path: root/devtools/find-type-definition
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-12-07 22:51:52 +0100
committerMattias Andrée <maandree@kth.se>2023-12-07 22:51:52 +0100
commit9f449569df9c94670f51fd8cd5558b66884cd877 (patch)
tree21d3c31e22b2cd0544351584c8614e70b66826e4 /devtools/find-type-definition
parentFourth commit (diff)
downloadlibsyscalls-9f449569df9c94670f51fd8cd5558b66884cd877.tar.gz
libsyscalls-9f449569df9c94670f51fd8cd5558b66884cd877.tar.bz2
libsyscalls-9f449569df9c94670f51fd8cd5558b66884cd877.tar.xz
Improve portability
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rwxr-xr-xdevtools/find-type-definition19
1 files changed, 16 insertions, 3 deletions
diff --git a/devtools/find-type-definition b/devtools/find-type-definition
index 9523e7c..2a99b78 100755
--- a/devtools/find-type-definition
+++ b/devtools/find-type-definition
@@ -4,6 +4,19 @@
type="$1"
shift 1
-grep -r '\(define\s\+\(__kernel_\)\?'"$type"'\s\|typedef\s.*\s\(__kernel_\)\?'"$type"'\b\)' "$@" \
-| sed 's/^\([^:]*\):/\x1b[35m\1\x1b[m /' \
-| sed 's/\(__kernel_\)\?'"$type"'/\x1b[1;31m&\x1b[m/g'
+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