aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
authorAlejandro Colomar <alx.manpages@gmail.com>2021-05-09 23:39:09 +0200
committerMichael Kerrisk <mtk.manpages@gmail.com>2021-05-10 11:32:17 +1200
commit5ae99ccb427914e49bb1c03efb57673cafb57409 (patch)
treef807cd1001890dc067834fa2055c48e7c6f6c348 /scripts
parentb08daf3c0cb75fbbe7998f043b6d2bddd18cb3cf (diff)
downloadman-pages-5ae99ccb427914e49bb1c03efb57673cafb57409.tar.gz
scripts/bash_aliases: Make man_lsfunc() more robust; Add sed_rm_ccomments().
This patch makes man_lsfunc() search for the function prototypes, instead of relying on the current manual page formatting, which might change in the future, and break this function. It also simplifies the code, by reusing man_section(). Create a new function sed_rm_ccomments(), which is needed by man_lsfunc(), and may also be useful in other cases. Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bash_aliases39
1 files changed, 21 insertions, 18 deletions
diff --git a/scripts/bash_aliases b/scripts/bash_aliases
index d9b6047d16..c50108a165 100644
--- a/scripts/bash_aliases
+++ b/scripts/bash_aliases
@@ -21,6 +21,21 @@ EX_OK=0;
EX_USAGE=64;
########################################################################
+# C
+
+# sed_rm_ccomments() removes C comments.
+# It can't handle multiple comments in a sinlge line correctly,
+# nor mixed or embedded //... and /*...*/ comments.
+# Use as a filter (see man_lsfunc() in this file).
+
+function sed_rm_ccomments()
+{
+ sed 's%/\*.*\*/%%' \
+ |sed -E '\%/\*%,\%\*/%{\%(\*/|/\*)%!d; s%/\*.*%%; s%.*\*/%%;}' \
+ |sed 's%//.*%%';
+}
+
+########################################################################
# Linux kernel
# grep_syscall() finds the prototype of a syscall in the kernel sources,
@@ -106,25 +121,13 @@ function man_lsfunc()
return ${EX_USAGE};
fi
- find "${@}" -type f \
- |xargs grep -l "\.SH SYNOPSIS" \
- |sort -V \
- |while read -r manpage; do
- <${manpage} \
- sed -n \
- -e '/^\.TH/,/^\.SH/{/^\.SH/!p}' \
- -e "/^\.SH SYNOPSIS/p" \
- -e "/^\.SH SYNOPSIS/,/^\.SH/{/^\.SH/!p}" \
- |sed \
- -e '/Feature/,$d' \
- -e '/{/,/}/d' \
- |man -P cat -l - 2>/dev/null;
+ for arg in "$@"; do
+ man_section "${arg}" 'SYNOPSIS';
done \
- |sed -n "/^SYNOPSIS/,/^\w/p" \
- |grep '^ \w' \
- |grep -v ':' \
- |sed 's/^[^(]* \**\(\w*\)(.*/\1/' \
- |grep '^\w' \
+ |sed_rm_ccomments \
+ |pcregrep -Mn '(?s)^ [\w ]+ \**\w+\([\w\s(,)[\]*]+?(...)?\s*\); *$' \
+ |grep '^[0-9]' \
+ |sed -E 's/^[^(]+ \**(\w+)\(.*/\1/' \
|uniq;
}