From: Alejandro Colomar <alx.manpages@gmail.com>
To: mtk.manpages@gmail.com
Cc: Alejandro Colomar <alx.manpages@gmail.com>,
linux-man@vger.kernel.org, Stefan Puiu <stefan.puiu@gmail.com>,
Walter Harms <wharms@bfs.de>
Subject: [PATCH v2] scripts/bash_aliases: Make man_lsfunc() more robust; Add sed_rm_ccomments().
Date: Sun, 7 Mar 2021 21:26:35 +0100 [thread overview]
Message-ID: <20210307202634.1215744-1-alx.manpages@gmail.com> (raw)
In-Reply-To: <20210307195622.1140064-1-alx.manpages@gmail.com>
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>
---
Hi Michael,
Never mind the previous email. I fixed it and merged two lines that
could be merged.
Regards,
Alex
scripts/bash_aliases | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/scripts/bash_aliases b/scripts/bash_aliases
index d9b6047d1..ba6544a97 100644
--- a/scripts/bash_aliases
+++ b/scripts/bash_aliases
@@ -20,6 +20,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 -r '\%/\*%,\%\*/%{\%(\*/|/\*)%!d; s%/\*.*%%; s%.*\*/%%;}' \
+ |sed 's%//.*%%';
+}
+
########################################################################
# Linux kernel
@@ -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 -r 's/^[^(]+ +\**(\w+)\(.*/\1/' \
|uniq;
}
--
2.30.1
next prev parent reply other threads:[~2021-03-07 20:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-07 19:56 [PATCH] scripts/bash_aliases: Make man_lsfunc() more robust; Add sed_rm_ccomments() Alejandro Colomar
2021-03-07 20:21 ` Alejandro Colomar (man-pages)
2021-03-07 20:26 ` Alejandro Colomar [this message]
2021-03-07 20:55 ` [PATCH v3] " Alejandro Colomar
2021-03-07 23:32 ` [PATCH v4] " Alejandro Colomar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210307202634.1215744-1-alx.manpages@gmail.com \
--to=alx.manpages@gmail.com \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=stefan.puiu@gmail.com \
--cc=wharms@bfs.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox