]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
scripts/bash_aliases: Add man_lsvar(), similar to man_lsfunc() but lists variables
authorAlejandro Colomar <alx.manpages@gmail.com>
Sun, 9 May 2021 21:39:10 +0000 (23:39 +0200)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Sun, 9 May 2021 23:32:42 +0000 (11:32 +1200)
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
scripts/bash_aliases

index c50108a165d102ab2d0faf488247b55f624c2bd7..813c00960cc2534df07535d7644ea4cf7b9babfd 100644 (file)
@@ -131,6 +131,33 @@ function man_lsfunc()
        |uniq;
 }
 
+#  man_lsvar()  prints the name of all C variables declared in the SYNOPSIS
+# of all manual pages in a directory (or in a single manual page file).
+# Each name is printed in a separate line
+# Usage example:  .../man-pages$ man_lsvar man3;
+
+function man_lsvar()
+{
+       if ! [ -v 1 ]; then
+               >&2 echo "Usage: ${FUNCNAME[0]} <dir>";
+               return ${EX_USAGE};
+       fi
+
+       for arg in "$@"; do
+               man_section "${arg}" 'SYNOPSIS';
+       done \
+       |sed_rm_ccomments \
+       |pcregrep -Mv '(?s)^ [\w ]+ \**\w+\([\w\s(,)[\]*]+?(...)?\s*\); *$' \
+       |pcregrep -Mn \
+         -e '(?s)^ +extern [\w ]+ \**\(\*+[\w ]+\)\([\w\s(,)[\]*]+?\s*\); *$' \
+         -e '^ +extern [\w ]+ \**[\w ]+; *$' \
+       |grep '^[0-9]' \
+       |grep -v 'typedef' \
+       |sed -E 's/^[0-9]+: +extern [^(]+ \**\(\*+(\w* )?(\w+)\)\(.*/\2/' \
+       |sed    's/^[0-9]\+: \+extern .* \**\(\w\+\); */\1/' \
+       |uniq;
+}
+
 #  pdfman()  renders a manual page in PDF
 # Usage example:  .../man-pages$ pdfman man2/membarrier.2;