aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-12-27 16:02:37 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-12-27 16:02:37 +0100
commit1462673dde780091664dbbc79e1c01811bd48e40 (patch)
treea49b0ff1c65929e6b73479029d2bb954b7b375f8
parentcad20ced8603f2d4c1ff13fbf01cdccc9cb1b7aa (diff)
downloadbusybox-w32-1462673dde780091664dbbc79e1c01811bd48e40.tar.gz
busybox-w32-1462673dde780091664dbbc79e1c01811bd48e40.tar.bz2
busybox-w32-1462673dde780091664dbbc79e1c01811bd48e40.zip
man: implement SECTION parameters
function old new delta man_main 807 942 +135 is_section_name - 52 +52 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 187/0) Total: 187 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/man.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/miscutils/man.c b/miscutils/man.c
index 61086612a..722f6641e 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -13,7 +13,7 @@
13//kbuild:lib-$(CONFIG_MAN) += man.o 13//kbuild:lib-$(CONFIG_MAN) += man.o
14 14
15//usage:#define man_trivial_usage 15//usage:#define man_trivial_usage
16//usage: "[-aw] MANPAGE..." 16//usage: "[-aw] [SECTION] MANPAGE[.SECTION]..."
17//usage:#define man_full_usage "\n\n" 17//usage:#define man_full_usage "\n\n"
18//usage: "Display manual page\n" 18//usage: "Display manual page\n"
19//usage: "\n -a Display all pages" 19//usage: "\n -a Display all pages"
@@ -240,10 +240,21 @@ static const char *if_redefined(const char *var, const char *key, const char *li
240 return xstrdup(skip_whitespace(line)); 240 return xstrdup(skip_whitespace(line));
241} 241}
242 242
243static int is_section_name(const char *sections, const char *str)
244{
245 const char *s = strstr(sections, str);
246 if (s) {
247 int l = strlen(str);
248 return (s[l] == ':' || s[l] == '\0');
249 }
250 return 0;
251}
252
243int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 253int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
244int man_main(int argc UNUSED_PARAM, char **argv) 254int man_main(int argc UNUSED_PARAM, char **argv)
245{ 255{
246 parser_t *parser; 256 parser_t *parser;
257 char *conf_sec_list;
247 char *sec_list; 258 char *sec_list;
248 char **man_path_list; 259 char **man_path_list;
249 int count_mp; 260 int count_mp;
@@ -255,7 +266,7 @@ int man_main(int argc UNUSED_PARAM, char **argv)
255 opt = getopt32(argv, "^+" "aw" "\0" "-1"/*at least one arg*/); 266 opt = getopt32(argv, "^+" "aw" "\0" "-1"/*at least one arg*/);
256 argv += optind; 267 argv += optind;
257 268
258 sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9"); 269 conf_sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9");
259 270
260 count_mp = 0; 271 count_mp = 0;
261 man_path_list = add_MANPATH(NULL, &count_mp, 272 man_path_list = add_MANPATH(NULL, &count_mp,
@@ -285,8 +296,8 @@ int man_main(int argc UNUSED_PARAM, char **argv)
285 man_path_list = add_MANPATH(man_path_list, &count_mp, token[1]); 296 man_path_list = add_MANPATH(man_path_list, &count_mp, token[1]);
286 } 297 }
287 if (strcmp("MANSECT", token[0]) == 0) { 298 if (strcmp("MANSECT", token[0]) == 0) {
288 free(sec_list); 299 free(conf_sec_list);
289 sec_list = xstrdup(token[1]); 300 conf_sec_list = xstrdup(token[1]);
290 } 301 }
291 } 302 }
292 config_close(parser); 303 config_close(parser);
@@ -311,6 +322,13 @@ int man_main(int argc UNUSED_PARAM, char **argv)
311 G.pager = xasprintf("%s -b -p -x", G.col); 322 G.pager = xasprintf("%s -b -p -x", G.col);
312 } 323 }
313 324
325 /* is 1st ARG a SECTION? */
326 sec_list = conf_sec_list;
327 if (is_section_name(conf_sec_list, *argv)) {
328 /* yes */
329 sec_list = *argv++;
330 }
331
314 not_found = 0; 332 not_found = 0;
315 do { /* for each argv[] */ 333 do { /* for each argv[] */
316 const char *cur_path; 334 const char *cur_path;
@@ -321,11 +339,20 @@ int man_main(int argc UNUSED_PARAM, char **argv)
321 found = show_manpage(*argv, /*man:*/ 1, 0); 339 found = show_manpage(*argv, /*man:*/ 1, 0);
322 goto check_found; 340 goto check_found;
323 } 341 }
342
343 /* for each MANPATH */
324 cur_mp = 0; 344 cur_mp = 0;
325 while ((cur_path = man_path_list[cur_mp++]) != NULL) { 345 while ((cur_path = man_path_list[cur_mp++]) != NULL) {
326 /* for each MANPATH */
327 const char *cur_sect = sec_list; 346 const char *cur_sect = sec_list;
328 do { /* for each section */ 347
348 /* is MANPAGE of the form NAME.SECTION? */
349 char *sect_ext = strrchr(*argv, '.');
350 if (sect_ext && is_section_name(conf_sec_list, sect_ext + 1)) {
351 *sect_ext = '\0';
352 cur_sect = sect_ext + 1;
353 }
354
355 do { /* for each SECTION in cur_sect */
329 char *next_sect = strchrnul(cur_sect, ':'); 356 char *next_sect = strchrnul(cur_sect, ':');
330 int sect_len = next_sect - cur_sect; 357 int sect_len = next_sect - cur_sect;
331 char *man_filename; 358 char *man_filename;
@@ -352,6 +379,8 @@ int man_main(int argc UNUSED_PARAM, char **argv)
352 while (*cur_sect == ':') 379 while (*cur_sect == ':')
353 cur_sect++; 380 cur_sect++;
354 } while (*cur_sect); 381 } while (*cur_sect);
382
383 if (sect_ext) *sect_ext = '.';
355 } 384 }
356 check_found: 385 check_found:
357 if (!found) { 386 if (!found) {