]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
grepc: grepc_type_*: Fix some typedef corner cases
authorAlejandro Colomar <alx.manpages@gmail.com>
Mon, 9 May 2022 13:21:06 +0000 (15:21 +0200)
committerAlejandro Colomar <alx@kernel.org>
Wed, 29 Oct 2025 20:28:51 +0000 (21:28 +0100)
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
bin/grepc

index fb10366fffa950f07f58c198e080ba9bea6698c1..0c736964366be04bc31d1aa0e589142b6a0673ed 100755 (executable)
--- a/bin/grepc
+++ b/bin/grepc
@@ -120,25 +120,25 @@ 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[\]]*{.*?^}.*?;";
+         "(?s)^(?!^\s*typedef\b)([\w[][\w\s(,)[:\]*]+\s+)?\b(struct|union|enum)\s+$1\b\s*[\w\s[\]]*{.*?^}.*?;";
 }
 
 
 function grepc_type_typedef_simple()
 {
        grepc_helper '\.[ch]$' \
-         "^typedef\s" \
+         "^\s*typedef\s" \
          "\b$1;" \
-         "(?s)^typedef\s+[^{};]+$1;";
+         "(?s)^\s*typedef\s+[^{};]+$1;";
 }
 
 
 function grepc_type_typedef_struct_union_enum()
 {
        grepc_helper '\.[ch]$' \
-         "^typedef\s[^;]+$" \
-         "^}\s*$1;" \
-         "(?s)^typedef\s(?:(?!^}).)*^}\s*$1;";
+         "^\s*typedef\s+(struct|union|enum)\b[^;]*$" \
+         "^(\s\s)?}\s*$1;" \
+         "(?s)^\s*typedef\s+(struct|union|enum)\s+(?:(?!^(\s\s)?}|^\s*typedef).)*^(\s\s)?}\s*$1;";
 }
 
 
@@ -146,8 +146,8 @@ function grepc_type_typedef_underlying_struct_union_enum()
 {
        find . -type f \
        | grep '\.[ch]$' \
-       | xargs grep -hP "^typedef\s+.*\b$1;" \
-       | sed -E -e 's/^typedef\s+//' -e "s/\s*\**\b$1;.*//" \
+       | xargs grep -hP "^\s*typedef\s+(struct|union|enum)\s+.*\b$1;" \
+       | sed -E -e 's/^\s*typedef\s+//' -e "s/\s*\**\b$1;.*//" \
        | sed -E -e 's/^struct\s+//' -e 's/^union\s+//' -e 's/^enum\s+//' \
        | while read t; do
                test "$1" != "$t" \