Hello!
I've used and loved busybox for a while now, however something which has always
bothered me has been the inability to specify from which section to grab a man
page, so I've devised a patch to fix this!
This patch adds an option called "Support specifying section of page" (which
depends on man). If enabled it "Lets the user specify which from which section
they would like to retrieve their manpage from." - the help message for the
option.
In practice this is done as such:
Usage: man [-aw] MANPAGE[.SECTION]...
This works perfectly with both existing flags and does not effect the behavior
of man when disabled.
patch file is in attachments!
From 1cff1d7943021398a6bca8e9862cd976660267b2 Mon Sep 17 00:00:00 2001
From: depsterr <[email protected]>
Date: Tue, 22 Dec 2020 02:52:55 +0100
Subject: [PATCH] Added option to support specifying section of manpage
---
miscutils/man.c | 75 ++++++++++++++++++++++++++++++++++++-------------
1 file changed, 56 insertions(+), 19 deletions(-)
diff --git a/miscutils/man.c b/miscutils/man.c
index 61086612a..664caf0da 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -7,13 +7,20 @@
//config: default y
//config: help
//config: Format and display manual pages.
+//config:config FEATURE_MAN_SPECIFY_SECTION
+//config: bool "Support specifying section of page"
+//config: default y
+//config: depends on MAN
+//config: help
+//config: Lets the user specify which from which section
+//config: they would like to retrieve their manpage from.
//applet:IF_MAN(APPLET(man, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_MAN) += man.o
//usage:#define man_trivial_usage
-//usage: "[-aw] MANPAGE..."
+//usage: "[-aw] MANPAGE" IF_FEATURE_MAN_SPECIFY_SECTION("[.SECTION]") "..."
//usage:#define man_full_usage "\n\n"
//usage: "Display manual page\n"
//usage: "\n -a Display all pages"
@@ -240,6 +247,25 @@ static const char *if_redefined(const char *var, const char *key, const char *li
return xstrdup(skip_whitespace(line));
}
+static const char check_path(const char* cur_path, const char* cur_sect, int sect_len, const char* man_name)
+{
+ char *man_filename;
+ int cat0man1 = 0;
+ int ret = 0;
+ while (cat0man1 < 2) {
+ man_filename = xasprintf("%s/%s%.*s/%s.%.*s",
+ cur_path,
+ "cat\0man" + (cat0man1 * 4),
+ sect_len, cur_sect,
+ man_name,
+ sect_len, cur_sect);
+ ret = show_manpage(man_filename, cat0man1, 0);
+ cat0man1 += ret + 1;
+ free(man_filename);
+ }
+ return ret;
+}
+
int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int man_main(int argc UNUSED_PARAM, char **argv)
{
@@ -316,35 +342,41 @@ int man_main(int argc UNUSED_PARAM, char **argv)
const char *cur_path;
int cur_mp;
int found = 0;
+ int sect_len;
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+ char* section;
+#endif
if (strchr(*argv, '/')) {
found = show_manpage(*argv, /*man:*/ 1, 0);
goto check_found;
}
+
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+ section = strrchr(*argv, '.');
+ if (section) {
+ *section = '\0';
+ section++;
+ sect_len = strlen(section);
+ }
+#endif
cur_mp = 0;
while ((cur_path = man_path_list[cur_mp++]) != NULL) {
- /* for each MANPATH */
+
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+ if (section) {
+ found |= check_path(cur_path, section, sect_len, *argv);
+ continue;
+ }
+#endif
+ /* for each MANPATH */
const char *cur_sect = sec_list;
do { /* for each section */
char *next_sect = strchrnul(cur_sect, ':');
- int sect_len = next_sect - cur_sect;
- char *man_filename;
- int cat0man1 = 0;
+ sect_len = next_sect - cur_sect;
/* Search for cat, then man page */
- while (cat0man1 < 2) {
- int found_here;
- man_filename = xasprintf("%s/%s%.*s/%s.%.*s",
- cur_path,
- "cat\0man" + (cat0man1 * 4),
- sect_len, cur_sect,
- *argv,
- sect_len, cur_sect);
- found_here = show_manpage(man_filename, cat0man1, 0);
- found |= found_here;
- cat0man1 += found_here + 1;
- free(man_filename);
- }
+ found = check_path(cur_path, cur_sect, sect_len, *argv);
if (found && !(opt & OPT_a))
goto next_arg;
@@ -355,7 +387,12 @@ int man_main(int argc UNUSED_PARAM, char **argv)
}
check_found:
if (!found) {
- bb_error_msg("no manual entry for '%s'", *argv);
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+ if (section)
+ bb_error_msg("no manual entry for '%s' in section '%s'", *argv, section);
+ else
+#endif
+ bb_error_msg("no manual entry for '%s'", *argv);
not_found = 1;
}
next_arg:
--
2.29.2
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox