From: Alejandro Colomar <alx@kernel.org>
To: "G. Branden Robinson" <g.branden.robinson@gmail.com>,
cjwatson@debian.org
Cc: Ian Rogers <irogers@google.com>, David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Jonathan Corbet <corbet@lwn.net>,
dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-man@vger.kernel.org,
cjwatson@debian.org, groff@gnu.org
Subject: Re: [PATCH v2 1/3] proc_pid_fdinfo.5: Reduce indent for most of the page
Date: Sat, 2 Nov 2024 22:36:20 +0100 [thread overview]
Message-ID: <20241102213620.kfccilxvhihwmnld@devuan> (raw)
In-Reply-To: <20241102103937.ose4y72a7yl3dcmz@devuan>
[-- Attachment #1: Type: text/plain, Size: 4844 bytes --]
Hi Branden, Colin,
On Sat, Nov 02, 2024 at 11:40:13AM +0100, Alejandro Colomar wrote:
> > I also of course have ideas for generalizing the feature, so that you
> > can request any (sub)section by name, and, with a bit more ambition,[4]
> > paragraph tags (`TP`) too.
> >
> > So you could do things like:
> >
> > nroff -man -d EXTRACT="RETURN VALUE" man3/bsearch.3
>
> I certainly use this.
>
> # man_section() prints specific manual page sections (DESCRIPTION, SYNOPSIS,
> # ...) of all manual pages in a directory (or in a single manual page file).
> # Usage example: .../man-pages$ man_section man2 SYNOPSIS 'SEE ALSO';
>
> man_section()
> {
> if [ $# -lt 2 ]; then
> >&2 echo "Usage: ${FUNCNAME[0]} <dir> <section>...";
> return $EX_USAGE;
> fi
>
> local page="$1";
> shift;
> local sect="$*";
>
> find "$page" -type f \
> |xargs wc -l \
> |grep -v -e '\b1 ' -e '\btotal\b' \
> |awk '{ print $2 }' \
> |sort \
> |while read -r manpage; do
> (sed -n '/^\.TH/,/^\.SH/{/^\.SH/!p}' <"$manpage";
> for s in $sect; do
> <"$manpage" \
> sed -n \
> -e "/^\.SH $s/p" \
> -e "/^\.SH $s/,/^\.SH/{/^\.SH/!p}";
> done;) \
> |mandoc -Tutf8 2>/dev/null \
> |col -pbx;
> done;
> }
On the other hand, you may want to just package this small shell script
(or rather a part of it) as a program.
How about this?
$ cat /usr/local/bin/mansect
#!/bin/sh
if [ $# -lt 1 ]; then
>&2 echo "Usage: $0 SECTION [FILE ...]";
return 1;
fi
s="$1";
shift;
if test -z "$*"; then
sed -n \
-e '/^\.TH/,/^\.SH/{/^\.SH/!p}' \
-e '/^\.SH '"$s"'$/p' \
-e '/^\.SH '"$s"'$/,/^\.SH/{/^\.SH/!p}' \
;
else
find "$@" -not -type d \
| xargs wc -l \
| sed '${/ total$/d}' \
| grep -v '\b1 ' \
| awk '{ print $2 }' \
| xargs -L1 sed -n \
-e '/^\.TH/,/^\.SH/{/^\.SH/!p}' \
-e '/^\.SH '"$s"'$/p' \
-e '/^\.SH '"$s"'$/,/^\.SH/{/^\.SH/!p}' \
;
fi;
This only filters the source of the page, producing output that's
suitable for the groff pipeline.
alx@devuan:~$ man -w proc | xargs cat | mansect NAME
.TH proc 5 2024-06-15 "Linux man-pages 6.9.1-158-g2ac94c631"
.SH NAME
proc \- process information, system information, and sysctl pseudo-filesystem
alx@devuan:~$ man -w strtol strtoul | xargs mansect 'NAME'
.TH strtol 3 2024-07-23 "Linux man-pages 6.9.1-158-g2ac94c631"
.SH NAME
strtol, strtoll, strtoq \- convert a string to a long integer
.TH strtoul 3 2024-07-23 "Linux man-pages 6.9.1-158-g2ac94c631"
.SH NAME
strtoul, strtoull, strtouq \- convert a string to an unsigned long integer
You can request several sections with a regex:
$ man -w strtol strtoul | xargs mansect '\(NAME\|SEE ALSO\)'
.TH strtol 3 2024-07-23 "Linux man-pages 6.9.1-158-g2ac94c631"
.SH NAME
strtol, strtoll, strtoq \- convert a string to a long integer
.SH SEE ALSO
.BR atof (3),
.BR atoi (3),
.BR atol (3),
.BR strtod (3),
.BR strtoimax (3),
.BR strtoul (3)
.TH strtoul 3 2024-07-23 "Linux man-pages 6.9.1-158-g2ac94c631"
.SH NAME
strtoul, strtoull, strtouq \- convert a string to an unsigned long integer
.SH SEE ALSO
.BR a64l (3),
.BR atof (3),
.BR atoi (3),
.BR atol (3),
.BR strtod (3),
.BR strtol (3),
.BR strtoumax (3)
And it can then be piped to groff(1) to format the entire set of pages:
$ man -w strtol strtoul | xargs mansect '\(NAME\|SEE ALSO\)' | groff -man -Tutf8
strtol(3) Library Functions Manual strtol(3)
NAME
strtol, strtoll, strtoq - convert a string to a long integer
SEE ALSO
atof(3), atoi(3), atol(3), strtod(3), strtoimax(3), strtoul(3)
Linux man‐pages 6.9.1‐158‐g2ac... 2024‐07‐23 strtol(3)
───────────────────────────────────────────────────────────────────────────────
strtoul(3) Library Functions Manual strtoul(3)
NAME
strtoul, strtoull, strtouq - convert a string to an unsigned long integer
SEE ALSO
a64l(3), atof(3), atoi(3), atol(3), strtod(3), strtol(3), strtoumax(3)
Linux man‐pages 6.9.1‐158‐g2ac... 2024‐07‐23 strtoul(3)
This is quite naive, and will not work with pages that define their own
stuff, since this script is not groff(1). But it should be as fast as
is possible, which is what Colin wants, is as simple as it can be (and
thus relatively safe), and should work with most pages (as far as
indexing is concerned, probably all?).
Have a lovely night!
Alex
--
<https://www.alejandro-colomar.es/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-11-02 21:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 21:17 [PATCH v2 1/3] proc_pid_fdinfo.5: Reduce indent for most of the page Ian Rogers
2024-10-15 21:17 ` [PATCH v2 2/3] proc_pid_fdinfo.5: Add subsection headers for different fd types Ian Rogers
2024-10-15 21:17 ` [PATCH v2 3/3] proc_pid_fdinfo.5: Add DRM subsection Ian Rogers
2024-11-01 13:24 ` [PATCH v2 1/3] proc_pid_fdinfo.5: Reduce indent for most of the page Alejandro Colomar
2024-11-01 18:19 ` Ian Rogers
2024-11-01 20:07 ` Alejandro Colomar
2024-11-02 10:08 ` G. Branden Robinson
2024-11-02 10:39 ` Alejandro Colomar
2024-11-02 21:36 ` Alejandro Colomar [this message]
2024-11-02 23:47 ` Colin Watson
2024-11-03 0:05 ` Alejandro Colomar
2024-11-03 0:07 ` Alejandro Colomar
2024-11-03 0:24 ` Colin Watson
2024-11-03 0:47 ` Colin Watson
2024-11-03 1:09 ` G. Branden Robinson
2024-11-03 1:18 ` Colin Watson
2024-11-03 4:05 ` G. Branden Robinson
2024-11-02 19:06 ` Colin Watson
2024-11-03 0:50 ` G. Branden Robinson
2024-11-03 1:55 ` Colin Watson
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=20241102213620.kfccilxvhihwmnld@devuan \
--to=alx@kernel.org \
--cc=airlied@gmail.com \
--cc=cjwatson@debian.org \
--cc=corbet@lwn.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=g.branden.robinson@gmail.com \
--cc=groff@gnu.org \
--cc=irogers@google.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.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;
as well as URLs for NNTP newsgroup(s).