groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/3] src/bin/mansect, mansect.1: Add program and its manual page


From: Alejandro Colomar
Subject: [PATCH 2/3] src/bin/mansect, mansect.1: Add program and its manual page
Date: Sun, 3 Nov 2024 00:10:33 +0100

Cc: "G. Branden Robinson" <branden@debian.org>
Cc: Colin Watson <cjwatson@debian.org>
Cc: <groff@gnu.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
 man/man1/mansect.1 | 61 ++++++++++++++++++++++++++++++++++++++++++++++
 src/bin/mansect    | 33 +++++++++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100644 man/man1/mansect.1
 create mode 100755 src/bin/mansect

diff --git a/man/man1/mansect.1 b/man/man1/mansect.1
new file mode 100644
index 000000000..f46dc0609
--- /dev/null
+++ b/man/man1/mansect.1
@@ -0,0 +1,61 @@
+.\" Copyright 2024, Alejandro Colomar <alx@kernel.org>
+.\"
+.\" SPDX-License-Identifier: Linux-man-pages-copyleft
+.\"
+.TH mansect 1 (date) "Linux man-pages (unreleased)"
+.SH NAME
+mansect
+\-
+print the source code of sections of manual pages
+.SH SYNOPSIS
+.B mansect
+.I section
+.RI [ file\~ .\|.\|.]
+.SH DESCRIPTION
+The
+.B mansect
+command prints the source code of the
+.I section
+of the given manual-page files.
+If no files are specified,
+the standard input is used.
+.P
+.I section
+is a basic regular expression.
+.P
+The
+.B TH
+line is unconditionally printed.
+.P
+The output of this program is suitable for piping to the
+.BR groff (1)
+pipeline.
+.SH EXAMPLES
+.EX
+.RB $\~ "man -w strtol strtoul | xargs mansect '\[rs](NAME\[rs]|SEE 
ALSO\[rs])'"
+\&.TH strtol 3 2024-07-23 "Linux man-pages 6.9.1"
+\&.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"
+\&.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)
+.EE
+.SH SEE ALSO
+.BR lexgrog (1),
+.BR groff (1),
+.BR man (1)
diff --git a/src/bin/mansect b/src/bin/mansect
new file mode 100755
index 000000000..a35d387b1
--- /dev/null
+++ b/src/bin/mansect
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# Copyright 2020-2024, Alejandro Colomar <alx@kernel.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+
+if test $# -lt 1; then
+       >&2 echo "Usage: $0 SECTION [FILE ...]";
+       return 1;
+fi;
+
+s="$1";
+shift;
+
+
+if test $# -lt 1; 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;
-- 
2.39.5

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]