]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
src/bin/grepc_c: -tum: Split regex part for the replacement list
authorAlejandro Colomar <alx@kernel.org>
Wed, 5 Nov 2025 16:29:05 +0000 (17:29 +0100)
committerAlejandro Colomar <alx@kernel.org>
Thu, 6 Nov 2025 00:43:08 +0000 (01:43 +0100)
While splitting, improve the regex part in two ways:

-  Use a non-capturing group.  This improves performance.
-  Use negative lookahead instead of '[^\\]$'.  This allows matching
   a macro where the searched identifier is the last thing in the
   replacement list.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/bin/grepc_c

index 9ca87a1bae6a48a3a0a9dc065293257ad9e94f6b..c752dec190219f3752cf83cdbd05e52ce5af6545 100755 (executable)
@@ -119,6 +119,7 @@ grepc_c_mf_decl_()      { grepc_c_m_decl_ "$1";
 grepc_c_mo_decl_()      { grepc_c_m_decl_ "$1";
                           printf '%s' '(?!\()'; }
 grepc_c_m_repl_()       { printf '%s' '.*?(?<!\\)$'; }
+grepc_c_um_repl_()      { printf '%s' '(?:(?![^\\]$).)*'"$1"'.*?(?<!\\)$'; }
 
 
 grepc_c_e()             { echo '(?s)^([\w[]+[\w\s]*)?\benum\b[ \t]*([\w \t[\]]|::)*\n*([ \t]*){[^}]*^[ \t]*'"$1"'\b\s*[=,].*?^\3}.*?;'; }
@@ -153,7 +154,9 @@ grepc_c_uf_linux_def()  { grepc_c_fld_decl_ '\w+';
                           grepc_c_f_body_ "$1";
                           echo; }
 grepc_c_um()            { grepc_c_m_decl_ '\w+'
-                          echo '(\([^\)]*\))?(?:(?![^\\]$).)*'"$1"'.*?[^\\]$'; }
+                          printf '%s' '(?:\([^\)]*\))?';
+                          grepc_c_um_repl_ "$1";
+                          echo; }
 grepc_c_ut_su()         { echo '(?s)^(?!^[ \t]*typedef\b)([\w[]([\w\s\(,\)[\]*]|::)*[\w\s\)*\]]\s+)?\b(struct|union)\b([\w \t[\]]|::)*\w+[ \t]*\n*([ \t]*){(?:(?!^\5?}).)*?'"$1"'.*?^\5}.*?;'; }
 grepc_c_ut_td_simple()  { echo '(?s)^[ \t]*typedef\s+[^{};]*'"$1"'[^{};]+;'; }
 grepc_c_ut_td_su()      { echo '(?s)^[ \t]*typedef\s+(struct|union)\b([\w \t[\]]|::)*\n*([ \t]*){(?:(?!^\3?}|^\s*typedef).)*'"$1"'(?:(?!^\3?}|^\s*typedef).)*^\3}\s*\w+;'; }