I have created a new patch which handles both the section page
and page.section formats. (The page(section) format has been ignored as it is less common and more tedious to implement.) This patch also fixes a few typos in the previous patch. This should be my final version of this patch. Thanks to everyone for the feedback! Hopefully this can get merged :) ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Tuesday, December 22, 2020 5:15 PM, Harald van Dijk <[email protected]> wrote: > On 22/12/2020 15:42, Xabier Oneca -- xOneca wrote: > > > Hi Depsterr, > > > > > Usage: man [-aw] MANPAGE[.SECTION]... > > > > That does not seem to be compatible with the standard man: > > man [OPTION...] [SECTION] PAGE... > > It is not so much incompatible as it is incomplete. The widely used > man-db implementation of man does support this form as well. It supports > three forms of specifying the section, which all do the same thing: > > man 7 man > man man.7 > man 'man(7)' > > Cheers, > Harald van Dijk
From d98344765643a99107dd79285a56be67004d886a Mon Sep 17 00:00:00 2001 From: depsterr <[email protected]> Date: Tue, 22 Dec 2020 18:29:15 +0100 Subject: [PATCH] man: added possibility to specify page section --- miscutils/man.c | 95 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 18 deletions(-) diff --git a/miscutils/man.c b/miscutils/man.c index 61086612a..84af86aa8 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 from which section they would +//config: 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]" IF_FEATURE_MAN_SPECIFY_SECTION(" [SECTION]") " PAGE..." //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) { @@ -312,39 +338,67 @@ int man_main(int argc UNUSED_PARAM, char **argv) } not_found = 0; +#if ENABLE_FEATURE_MAN_SPECIFY_SECTION + /* string size needs to be increased if longer sections are added. */ + char sect_str[3] ALIGN1; + char *sect_ptr = NULL; +#endif do { /* for each argv[] */ const char *cur_path; int cur_mp; int found = 0; + int sect_len; if (strchr(*argv, '/')) { found = show_manpage(*argv, /*man:*/ 1, 0); goto check_found; } + +#if ENABLE_FEATURE_MAN_SPECIFY_SECTION + /* section page format */ + if ((sect_ptr = strstr(sec_list, *argv))) { + /* !*(argv + 1) do not treat as section name if last arg */ + if (*sect_ptr == ':' || !*(argv + 1)) { + sect_ptr = NULL; + } else { + /* copy section name into sect_str */ + int n = 0; + while (*sect_ptr != ':' && *sect_ptr != '\0') { + sect_str[n] = *sect_ptr; + sect_ptr++; + n++; + } + sect_len = n; + sect_str[n] = '\0'; + argv++; + } + /* page.section format */ + } else if ((sect_ptr = strrchr(*argv, '.'))) { + if (strstr(sec_list, sect_ptr + 1)) { + strncpy(sect_str, sect_ptr + 1, sizeof(sect_str)); + sect_len = strlen(sect_str); + *sect_ptr = '\0'; + } else { + sect_ptr = NULL; + } + } +#endif cur_mp = 0; while ((cur_path = man_path_list[cur_mp++]) != NULL) { +#if ENABLE_FEATURE_MAN_SPECIFY_SECTION + if (sect_ptr) { + found |= check_path(cur_path, sect_str, 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 +409,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 (sect_ptr) + bb_error_msg("no manual entry for '%s' in section '%s'", *argv, sect_str); + 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
