diff options
Diffstat (limited to 'miscutils/man.c')
-rw-r--r-- | miscutils/man.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/miscutils/man.c b/miscutils/man.c index 6724b4b5d..052b50054 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" |
@@ -239,10 +239,21 @@ static const char *if_redefined(const char *var, const char *key, const char *li | |||
239 | return xstrdup(skip_whitespace(line)); | 239 | return xstrdup(skip_whitespace(line)); |
240 | } | 240 | } |
241 | 241 | ||
242 | static int is_section_name(const char *sections, const char *str) | ||
243 | { | ||
244 | const char *s = strstr(sections, str); | ||
245 | if (s) { | ||
246 | int l = strlen(str); | ||
247 | return (s[l] == ':' || s[l] == '\0'); | ||
248 | } | ||
249 | return 0; | ||
250 | } | ||
251 | |||
242 | int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 252 | int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
243 | int man_main(int argc UNUSED_PARAM, char **argv) | 253 | int man_main(int argc UNUSED_PARAM, char **argv) |
244 | { | 254 | { |
245 | parser_t *parser; | 255 | parser_t *parser; |
256 | char *conf_sec_list; | ||
246 | char *sec_list; | 257 | char *sec_list; |
247 | char **man_path_list; | 258 | char **man_path_list; |
248 | int count_mp; | 259 | int count_mp; |
@@ -267,7 +278,7 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
267 | chdir_system_drive(); | 278 | chdir_system_drive(); |
268 | #endif | 279 | #endif |
269 | 280 | ||
270 | sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9"); | 281 | conf_sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9"); |
271 | 282 | ||
272 | count_mp = 0; | 283 | count_mp = 0; |
273 | man_path_list = add_MANPATH(NULL, &count_mp, | 284 | man_path_list = add_MANPATH(NULL, &count_mp, |
@@ -297,8 +308,8 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
297 | man_path_list = add_MANPATH(man_path_list, &count_mp, token[1]); | 308 | man_path_list = add_MANPATH(man_path_list, &count_mp, token[1]); |
298 | } | 309 | } |
299 | if (strcmp("MANSECT", token[0]) == 0) { | 310 | if (strcmp("MANSECT", token[0]) == 0) { |
300 | free(sec_list); | 311 | free(conf_sec_list); |
301 | sec_list = xstrdup(token[1]); | 312 | conf_sec_list = xstrdup(token[1]); |
302 | } | 313 | } |
303 | } | 314 | } |
304 | config_close(parser); | 315 | config_close(parser); |
@@ -337,6 +348,13 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
337 | G.pager = xasprintf("%s -b -p -x", G.col); | 348 | G.pager = xasprintf("%s -b -p -x", G.col); |
338 | } | 349 | } |
339 | 350 | ||
351 | /* is 1st ARG a SECTION? */ | ||
352 | sec_list = conf_sec_list; | ||
353 | if (is_section_name(conf_sec_list, *argv)) { | ||
354 | /* yes */ | ||
355 | sec_list = *argv++; | ||
356 | } | ||
357 | |||
340 | not_found = 0; | 358 | not_found = 0; |
341 | do { /* for each argv[] */ | 359 | do { /* for each argv[] */ |
342 | const char *cur_path; | 360 | const char *cur_path; |
@@ -347,11 +365,20 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
347 | found = show_manpage(*argv, /*man:*/ 1, 0); | 365 | found = show_manpage(*argv, /*man:*/ 1, 0); |
348 | goto check_found; | 366 | goto check_found; |
349 | } | 367 | } |
368 | |||
369 | /* for each MANPATH */ | ||
350 | cur_mp = 0; | 370 | cur_mp = 0; |
351 | while ((cur_path = man_path_list[cur_mp++]) != NULL) { | 371 | while ((cur_path = man_path_list[cur_mp++]) != NULL) { |
352 | /* for each MANPATH */ | ||
353 | const char *cur_sect = sec_list; | 372 | const char *cur_sect = sec_list; |
354 | do { /* for each section */ | 373 | |
374 | /* is MANPAGE of the form NAME.SECTION? */ | ||
375 | char *sect_ext = strrchr(*argv, '.'); | ||
376 | if (sect_ext && is_section_name(conf_sec_list, sect_ext + 1)) { | ||
377 | *sect_ext = '\0'; | ||
378 | cur_sect = sect_ext + 1; | ||
379 | } | ||
380 | |||
381 | do { /* for each SECTION in cur_sect */ | ||
355 | char *next_sect = strchrnul(cur_sect, ':'); | 382 | char *next_sect = strchrnul(cur_sect, ':'); |
356 | int sect_len = next_sect - cur_sect; | 383 | int sect_len = next_sect - cur_sect; |
357 | char *man_filename; | 384 | char *man_filename; |
@@ -378,6 +405,8 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
378 | while (*cur_sect == ':') | 405 | while (*cur_sect == ':') |
379 | cur_sect++; | 406 | cur_sect++; |
380 | } while (*cur_sect); | 407 | } while (*cur_sect); |
408 | |||
409 | if (sect_ext) *sect_ext = '.'; | ||
381 | } | 410 | } |
382 | check_found: | 411 | check_found: |
383 | if (!found) { | 412 | if (!found) { |