summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-05-13 17:17:45 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-05-13 17:22:27 +0200
commit3342a8422ba72e4df937262a688ecc174eb9099f (patch)
tree83f23b1f5719260c68a19c515d286f6aa7e984c8
parent44156f8553271c7b29a3fc02f718a278dd4dc194 (diff)
grepc, grepc.1: Add -tu to search for uses
Reported-by: наб <nabijaczleweli@nabijaczleweli.xyz> Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
-rwxr-xr-xbin/grepc55
-rw-r--r--share/man/man1/grepc.19
2 files changed, 63 insertions, 1 deletions
diff --git a/bin/grepc b/bin/grepc
index 0687095..97346c9 100755
--- a/bin/grepc
+++ b/bin/grepc
@@ -11,6 +11,7 @@ t_enum='no';
t_func='no';
t_macro='no';
t_type='no';
+t_use='no';
grepc_usage()
@@ -47,6 +48,9 @@ grepc_parse_cmd()
t)
t_type='yes';
;;
+ u)
+ t_use='yes';
+ ;;
*)
grepc_usage;
exit 1;
@@ -259,12 +263,60 @@ grepc_type()
}
+grepc_use_func_def()
+{
+ grepc_helper \
+ "\b$1\b" \
+ '.' \
+ "(?s)^[\w[]([\w\s\(,\)[\]*]|::)*[\w\s\)*\]]\s+\**\w+\s*\([\w\s\(,\)[\]*]+?(...)?\)\s*{(?:(?!^}).)*\b$1\b.*?^}";
+}
+
+
+grepc_linux_use_func_syscall_def()
+{
+ grepc_helper \
+ "SYSCALL_DEFINE.\(" \
+ "\b$1\b" \
+ "(?s)^(COMPAT_)?SYSCALL_DEFINE.\(\w+\b(?:(?!^}).)*\b$1\b.?^}";
+}
+
+
+grepc_linux_use_func()
+{
+ grepc_linux_use_func_syscall_def "$1";
+}
+
+
+grepc_use_func()
+{
+ grepc_use_func_def "$1";
+ grepc_linux_use_func "$1";
+}
+
+
+grepc_use_macro()
+{
+ grepc_helper \
+ "\b$1\b" \
+ 'define' \
+ '(?s)^[ \t]*#\s*define\s+\w+\b(\([^\)]*\))?(?:(?![^\\]$).)*'"$1"'.*?[^\\]$';
+}
+
+
+grepc_use()
+{
+ grepc_use_func "$1";
+ grepc_use_macro "$1";
+}
+
+
grepc_search_default()
{
grepc_enum_constant "$1";
grepc_func "$1";
grepc_macro "$1";
grepc_type "$1";
+ grepc_use "$1";
}
@@ -286,6 +338,9 @@ grepc_search()
if [ "$t_type" = 'yes' ]; then
grepc_type "$1";
fi;
+ if [ "$t_use" = 'yes' ]; then
+ grepc_use "$1";
+ fi;
fi;
}
diff --git a/share/man/man1/grepc.1 b/share/man/man1/grepc.1
index 8bae0ee..b54b020 100644
--- a/share/man/man1/grepc.1
+++ b/share/man/man1/grepc.1
@@ -50,6 +50,13 @@ Macro definitions.
.TP
.B t
Type definitions.
+.TP
+.B u
+Uses.
+Searches occurences of
+.BI \eb identifier \eb
+within function bodies and macro replacements,
+and prints the whole functions and/or macros.
.SH OPTIONS
.TP
.B \-g
@@ -70,7 +77,7 @@ of code (see Types of code under DESCRIPTION).
This option can be passed multiple times
to search for various types of code.
Default:
-.BR "e f m t" .
+.BR "e f m t u" .
.TP
.BI \-x " extension"
Restrict the search to files ending with