]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
src/bin/grepc_c: -te, -tue: Reuse code from function body
authorAlejandro Colomar <alx@kernel.org>
Wed, 5 Nov 2025 17:24:40 +0000 (18:24 +0100)
committerAlejandro Colomar <alx@kernel.org>
Thu, 6 Nov 2025 00:43:09 +0000 (01:43 +0100)
A function body and an enum body are quite similar.
The same regex works for both.

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

index b4125ededb1555f34061b49709a8700057a4b810..a3c5d7f804fde7f477980d4953b7873b1e9a45d2 100755 (executable)
@@ -114,7 +114,7 @@ grepc_c_f_params_()     { printf '%s' '\s*(?<params>\((?:[\w\s,;[\]*\?:+-]|(?&pa
 grepc_c_f_decl_()       { grepc_c_f_return_;
                           printf '%s' '\(?'"$1"'\)?';
                           grepc_c_f_params_; }
-grepc_c_f_body_()       { printf '%s' '[ \t]*\n*(?<space>[ \t]*){(?:(?!^\k<space>?}).)*'"$1"'.*?^\k<space>}'; }
+grepc_c_body_()         { printf '%s' '[ \t]*\n*(?<space>[ \t]*){(?:(?!^\k<space>?}).)*'"$1"'.*?^\k<space>}'; }
 grepc_c_fld_decl_()     { printf '%s' '(?s)^(COMPAT_)?SYSCALL_DEFINE.\('"$1"'\b[\w\s,;[\]*\?:+-]*\)'; }
 grepc_c_m_decl_()       { printf '%s' '(?s)^[ \t]*#\s*define\s[\s\\]*'"$1"'\b'; }
 grepc_c_mf_decl_()      { grepc_c_m_decl_ "$1";
@@ -125,11 +125,12 @@ grepc_c_m_repl_()       { printf '%s' '(?:(?![^\\]$).)*'"$1"'.*?(?<!\\)$'; }
 
 
 grepc_c_e()             { grepc_c_e_decl_;
-                          echo '\n*([ \t]*){[^}]*^[ \t]*'"$1"'\b\s*[=,].*?^\3}.*?;'; }
+                          grepc_c_body_ '^[ \t]*'"$1"'\b\s*[=,]';
+                          echo '[^;]*;'; }
 grepc_c_fp()            { grepc_c_f_decl_ "$1";
                           echo '(?:[\w\s\(,\)[\]]|::)*;'; }
 grepc_c_fd()            { grepc_c_f_decl_ "$1";
-                          grepc_c_f_body_ '';
+                          grepc_c_body_ '';
                           echo; }
 grepc_c_fgd_libm()      { grepc_c_fd "M_DECL_FUNC \(__$1\)"; }
 grepc_c_fgd_libio()     { grepc_c_fd "_IO_$1"; }
@@ -137,7 +138,7 @@ grepc_c_fgp_libio()     { grepc_c_fp "_IO_$1"; }
 grepc_c_fgp()           { grepc_c_fgp_libio "$1"; }
 grepc_c_flp()           { grepc_c_fp "(?:compat_)?sys_$1"; }
 grepc_c_fld()           { grepc_c_fld_decl_ "$1";
-                          grepc_c_f_body_ '';
+                          grepc_c_body_ '';
                           echo; }
 grepc_c_mf()            { grepc_c_mf_decl_ "$1";
                           grepc_c_m_repl_ '';
@@ -150,12 +151,13 @@ grepc_c_t_td_simple()   { echo '(?s)^[ \t]*typedef\s+[^{};]+\b'"$1"';'; }
 grepc_c_t_td_braced()   { echo '(?s)^[ \t]*typedef\s+(struct|union|enum)\b(?:(?!\W'"$1"'\W)([\w \t[\]]|::))*\n*([ \t]*){(?:(?!^\3?}).)*?^\3}\s*'"$1"'(\[[\w\(,\)]\])*;'; }
 grepc_c_t_td_func()     { echo '(?s)^[ \t]*typedef\s+[^{};]+\(\**'"$1"'\)\s*\([^{};]+;'; }
 grepc_c_ue()            { grepc_c_e_decl_;
-                          echo '\n*([ \t]*){[^}]*^\s*\w+[\w\s[\]=]*'"$1"'.*?^\3}.*?;'; }
+                          grepc_c_body_ "$1";
+                          echo '[^;]*;'; }
 grepc_c_uf_def()        { grepc_c_f_decl_ '\w+';
-                          grepc_c_f_body_ "$1";
+                          grepc_c_body_ "$1";
                           echo; }
 grepc_c_uf_linux_def()  { grepc_c_fld_decl_ '\w+';
-                          grepc_c_f_body_ "$1";
+                          grepc_c_body_ "$1";
                           echo; }
 grepc_c_umf()           { grepc_c_mf_decl_ '\w+'
                           grepc_c_m_repl_ "$1";