summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-05-15 01:20:39 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-05-15 01:21:36 +0200
commit9450b556e1bd3da2d9073a970d6f44ccf0b33d36 (patch)
tree34a9a2cd74e7fdd2fdf4f203c5937c302f147b0e
parent44d6c152f776a991fdbe43d39e1bcbf164337b98 (diff)
grepc, grepc.1: -tu: Search also within enum and type definitions
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
-rwxr-xr-xbin/grepc46
-rw-r--r--share/man/man1/grepc.17
2 files changed, 51 insertions, 2 deletions
diff --git a/bin/grepc b/bin/grepc
index 173cf2b..32b1dd3 100755
--- a/bin/grepc
+++ b/bin/grepc
@@ -268,6 +268,15 @@ grepc_type()
}
+grepc_use_enum()
+{
+ grepc_helper \
+ '\benum\b' \
+ "\b$1\b" \
+ "(?s)^([\w[]+[\w\s]*)?\benum\b\s*([\w\s[\]]|::)*\s*{[^}]*^\s*\w+[\w\s[\]=]*\b$1\b.*?^}.*?;";
+}
+
+
grepc_use_func_def()
{
grepc_helper \
@@ -308,10 +317,47 @@ grepc_use_macro()
}
+grepc_use_type_struct_union()
+{
+ grepc_helper \
+ "\b(struct|union)\b" \
+ "\b$1\b" \
+ "(?s)^(?!^[ \t]*typedef\b)([\w[]([\w\s\(,\)[\]*]|::)*[\w\s\)*\]]\s+)?\b(struct|union)\s+\w+\s*[\w\s[\]]*{(?:(?!^}).)*?\b$1\b.*?^}.*?;";
+}
+
+
+grepc_use_type_typedef_simple()
+{
+ grepc_helper \
+ '^[ \t]*typedef\s' \
+ "\b$1\b" \
+ "(?s)^[ \t]*typedef\s+[^{};]*\b$1\b[^{};]+;";
+}
+
+
+grepc_use_type_typedef_struct_union()
+{
+ grepc_helper \
+ '^[ \t]*typedef\s+(struct|union)\b[^;]*$' \
+ "\b$1\b" \
+ "(?s)^[ \t]*typedef\s+(struct|union)\s+[\w\s[\]]*{(?:(?!^( )?}|^\s*typedef).)*\b$1\b(?:(?!^( )?}|^\s*typedef).)*^( )?}\s*\w+;";
+}
+
+
+grepc_use_type()
+{
+ grepc_use_type_struct_union "$1";
+ grepc_use_type_typedef_simple "$1";
+ grepc_use_type_typedef_struct_union "$1";
+}
+
+
grepc_use()
{
+ grepc_use_enum "$1";
grepc_use_func "$1";
grepc_use_macro "$1";
+ grepc_use_type "$1";
}
diff --git a/share/man/man1/grepc.1 b/share/man/man1/grepc.1
index d860ce4..e504f5d 100644
--- a/share/man/man1/grepc.1
+++ b/share/man/man1/grepc.1
@@ -55,8 +55,11 @@ Type definitions.
Uses.
Searches occurences of
.BI \eb identifier \eb
-within function bodies and macro replacements,
-and prints the whole functions and/or macros.
+within enums (except as an enum constant),
+function bodies,
+macro replacements,
+and type definitions,
+and prints the whole enum, function, macro, and/or type definitions.
.SH OPTIONS
.TP
.B \-g