summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-05-09 14:35:57 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-05-09 14:46:24 +0200
commitfe96c53a1402005d4dd23113abaac3616f79f59a (patch)
treee27f8f47f9cc259b52dd7ab413fe36e58c3ffa01 /bin
parent2a6d0fdf2ea68ff515d6a4b709913a150820d58d (diff)
grepc: Optimize
Use 2 grep(1) filters instead of 1, to be able to filter better before the multiline pcregrep(1) filter, which is considerably slower. Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/grepc25
1 files changed, 18 insertions, 7 deletions
diff --git a/bin/grepc b/bin/grepc
index 7e76e98..15c2b36 100755
--- a/bin/grepc
+++ b/bin/grepc
@@ -11,9 +11,10 @@ function grepc_helper()
{
find . -type f \
| grep "$1" \
- | xargs grep -lP "$2" \
+ | xargs grep -lPI "$2" \
+ | xargs grep -lP "$3" \
| sort \
- | xargs pcregrep -Mn "$3" /dev/null \
+ | xargs pcregrep -Mn "$4" /dev/null \
| sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/';
}
@@ -21,16 +22,18 @@ function grepc_helper()
function grepc_macro_simple()
{
grepc_helper '\.[ch]$' \
- "define\s+$1\b[^(]" \
- "(?s)define\s+$1\b[^(].*?[^\\\\]$";
+ "#\s*define\s+$1\b[^(]" \
+ "." \
+ "(?s)#\s*define\s+$1\b[^(].*?[^\\\\]$";
}
function grepc_macro_func()
{
grepc_helper '\.[ch]$' \
- "define\s+$1\(" \
- "(?s)define\s+$1\(.*?[^\\\\]$";
+ "#\s*define\s+$1\(" \
+ "." \
+ "(?s)#\s*define\s+$1\(.*?[^\\\\]$";
}
@@ -44,6 +47,7 @@ function grepc_macro()
function grepc_enum_constant()
{
grepc_helper '\.[ch]$' \
+ "^enum\s" \
"^\s*$1\s*[,=]" \
"(?s)\benum\b\s*[\w\s[\]]*{[^}]*^\s*$1\s*[=,].*?^}.*?;";
}
@@ -53,6 +57,7 @@ function grepc_func_decl()
{
grepc_helper '\.[ch]$' \
"\b$1\s*\(" \
+ "." \
"(?s)^[\w[][\w\s(,)[:\]*]+\s+\**$1\s*\([\w\s(,)[\]*]+?(...)?\)[\w\s(,)[:\]]*;";
}
@@ -61,6 +66,7 @@ function grepc_func_def()
{
grepc_helper '\.[ch]$' \
"\b$1\s*\(" \
+ "." \
"(?s)^[\w[][\w\s(,)[:\]*]+\s+\**$1\s*\([\w\s(,)[\]*]+?(...)?\)\s*{.*?^}";
}
@@ -75,7 +81,8 @@ function grepc_func()
function grepc_linux_syscall_decl()
{
grepc_helper '\.[ch]$' \
- "\bsys_$1\s*\(" \
+ "^asmlinkage\s+[\w\s]+\**sys_$1\s*\(" \
+ "." \
"(?s)^asmlinkage\s+[\w\s]+\**sys_$1\s*\(.*?\)";
}
@@ -84,6 +91,7 @@ function grepc_linux_syscall_def()
{
grepc_helper '\.c$' \
"SYSCALL_DEFINE.\($1\b" \
+ "." \
"(?s)^\w*SYSCALL_DEFINE.\($1\b.*?^}";
}
@@ -111,6 +119,7 @@ function grepc_type_struct_union_enum()
{
grepc_helper '\.[ch]$' \
"\b(struct|union|enum)\s+$1\b" \
+ "." \
"(?s)^(?!^typedef\b)([\w[][\w\s(,)[:\]*]+\s+)?\b(struct|union|enum)\s+$1\b\s*[\w\s[\]]*{.*?^}.*?;";
}
@@ -118,6 +127,7 @@ function grepc_type_struct_union_enum()
function grepc_type_typedef_simple()
{
grepc_helper '\.[ch]$' \
+ "^typedef\s" \
"\b$1;" \
"(?s)^typedef\s+[^{};]+$1;";
}
@@ -126,6 +136,7 @@ function grepc_type_typedef_simple()
function grepc_type_typedef_struct_union_enum()
{
grepc_helper '\.[ch]$' \
+ "^typedef\s[^;]+$" \
"^}\s*$1;" \
"(?s)^typedef\s(?:(?!^}).)*^}\s*$1;";
}