]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
grepc: Optimize
authorAlejandro Colomar <alx.manpages@gmail.com>
Mon, 9 May 2022 12:35:57 +0000 (14:35 +0200)
committerAlejandro Colomar <alx@kernel.org>
Wed, 29 Oct 2025 20:28:51 +0000 (21:28 +0100)
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>
bin/grepc

index 7e76e98021d94d64682a2864c195e8db7a842852..15c2b367cad0a106ee305d66720b5728267e877b 100755 (executable)
--- 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;";
 }