aboutsummaryrefslogtreecommitdiff
path: root/miscutils/man.c
diff options
context:
space:
mode:
Diffstat (limited to 'miscutils/man.c')
-rw-r--r--miscutils/man.c54
1 files changed, 24 insertions, 30 deletions
diff --git a/miscutils/man.c b/miscutils/man.c
index 0bc11e623..6724b4b5d 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -13,9 +13,9 @@
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] MANPAGE..."
17//usage:#define man_full_usage "\n\n" 17//usage:#define man_full_usage "\n\n"
18//usage: "Format and display manual page\n" 18//usage: "Display manual page\n"
19//usage: "\n -a Display all pages" 19//usage: "\n -a Display all pages"
20//usage: "\n -w Show page locations" 20//usage: "\n -w Show page locations"
21//usage: "\n" 21//usage: "\n"
@@ -209,9 +209,6 @@ static char **add_MANPATH(char **man_path_list, int *count_mp, char *path)
209 path_element = man_path_list; 209 path_element = man_path_list;
210 if (path_element) while (*path_element) { 210 if (path_element) while (*path_element) {
211 if (strcmp(*path_element, path) == 0) { 211 if (strcmp(*path_element, path) == 0) {
212 /* Have path but haven't counted it, must be default */
213 if (*count_mp == 0)
214 break;
215 goto skip; 212 goto skip;
216 } 213 }
217 path_element++; 214 path_element++;
@@ -247,14 +244,14 @@ int man_main(int argc UNUSED_PARAM, char **argv)
247{ 244{
248 parser_t *parser; 245 parser_t *parser;
249 char *sec_list; 246 char *sec_list;
250 char *cur_path, *cur_sect;
251 char **man_path_list; 247 char **man_path_list;
252 int count_mp; 248 int count_mp;
253 int cur_mp;
254 int opt, not_found; 249 int opt, not_found;
255 char *token[2]; 250 char *token[2];
256#if ENABLE_PLATFORM_MINGW32 251#if ENABLE_PLATFORM_MINGW32
257 char **ptr; 252 char **ptr;
253 char *exepath, *relpath;
254 const char *mpl[] = { "/usr/man", "/usr/share/man", NULL, NULL };
258#endif 255#endif
259 256
260 INIT_G(); 257 INIT_G();
@@ -276,16 +273,6 @@ int man_main(int argc UNUSED_PARAM, char **argv)
276 man_path_list = add_MANPATH(NULL, &count_mp, 273 man_path_list = add_MANPATH(NULL, &count_mp,
277 getenv("MANDATORY_MANPATH"+10) /* "MANPATH" */ 274 getenv("MANDATORY_MANPATH"+10) /* "MANPATH" */
278 ); 275 );
279 if (!man_path_list) {
280 /* default, may be overridden by /etc/man.conf */
281 man_path_list = xzalloc(2 * sizeof(man_path_list[0]));
282 man_path_list[0] = (char*)"/usr/man";
283 /* count_mp stays 0.
284 * Thus, man.conf will overwrite man_path_list[0]
285 * if a path is defined there.
286 */
287 }
288
289 /* Parse man.conf[ig] or man_db.conf */ 276 /* Parse man.conf[ig] or man_db.conf */
290 /* man version 1.6f uses man.config */ 277 /* man version 1.6f uses man.config */
291 /* man-db implementation of man uses man_db.conf */ 278 /* man-db implementation of man uses man_db.conf */
@@ -299,7 +286,7 @@ int man_main(int argc UNUSED_PARAM, char **argv)
299 if (!token[1]) 286 if (!token[1])
300 continue; 287 continue;
301 if (strcmp("DEFINE", token[0]) == 0) { 288 if (strcmp("DEFINE", token[0]) == 0) {
302 G.col = if_redefined(G.tbl , "col", token[1]); 289 G.col = if_redefined(G.col , "col", token[1]);
303 G.tbl = if_redefined(G.tbl , "tbl", token[1]); 290 G.tbl = if_redefined(G.tbl , "tbl", token[1]);
304 G.nroff = if_redefined(G.nroff, "nroff", token[1]); 291 G.nroff = if_redefined(G.nroff, "nroff", token[1]);
305 G.pager = if_redefined(G.pager, "pager", token[1]); 292 G.pager = if_redefined(G.pager, "pager", token[1]);
@@ -317,17 +304,22 @@ int man_main(int argc UNUSED_PARAM, char **argv)
317 config_close(parser); 304 config_close(parser);
318 305
319#if ENABLE_PLATFORM_MINGW32 306#if ENABLE_PLATFORM_MINGW32
320 { 307 /* allow man pages to be stored relative to the executable */
321 char *exepath = xstrdup(bb_busybox_exec_path); 308 exepath = xstrdup(bb_busybox_exec_path);
322 char *relpath = concat_path_file(dirname(exepath), "man"); 309 relpath = concat_path_file(dirname(exepath), "man");
323 if (count_mp == 0) { 310
324 /* default must match path set above */ 311 if (!man_path_list) {
325 man_path_list = add_MANPATH(man_path_list, &count_mp, 312 mpl[2] = relpath;
326 (char *)"/usr/man"); 313 man_path_list = (char**)mpl;
327 } 314 }
315 else {
328 man_path_list = add_MANPATH(man_path_list, &count_mp, relpath); 316 man_path_list = add_MANPATH(man_path_list, &count_mp, relpath);
329 free(relpath); 317 }
330 free(exepath); 318#else
319 if (!man_path_list) {
320 static const char *const mpl[] = { "/usr/man", "/usr/share/man", NULL };
321 man_path_list = (char**)mpl;
322 /*count_mp = 2; - not used below anyway */
331 } 323 }
332#endif 324#endif
333 325
@@ -347,16 +339,18 @@ int man_main(int argc UNUSED_PARAM, char **argv)
347 339
348 not_found = 0; 340 not_found = 0;
349 do { /* for each argv[] */ 341 do { /* for each argv[] */
342 const char *cur_path;
343 int cur_mp;
350 int found = 0; 344 int found = 0;
351 cur_mp = 0;
352 345
353 if (strchr(*argv, '/')) { 346 if (strchr(*argv, '/')) {
354 found = show_manpage(*argv, /*man:*/ 1, 0); 347 found = show_manpage(*argv, /*man:*/ 1, 0);
355 goto check_found; 348 goto check_found;
356 } 349 }
350 cur_mp = 0;
357 while ((cur_path = man_path_list[cur_mp++]) != NULL) { 351 while ((cur_path = man_path_list[cur_mp++]) != NULL) {
358 /* for each MANPATH */ 352 /* for each MANPATH */
359 cur_sect = sec_list; 353 const char *cur_sect = sec_list;
360 do { /* for each section */ 354 do { /* for each section */
361 char *next_sect = strchrnul(cur_sect, ':'); 355 char *next_sect = strchrnul(cur_sect, ':');
362 int sect_len = next_sect - cur_sect; 356 int sect_len = next_sect - cur_sect;