~vcs-imports/busybox/trunk

« back to all changes in this revision

Viewing changes to miscutils/man.c

  • Committer: Denys Vlasenko
  • Author(s): Christian Franke
  • Date: 2023-11-13 10:32:35 UTC
  • Revision ID: git-v1:a63b60bdd6fa26b867c80d44074118babbae7ffd
Cygwin: regenerate defconfig

Signed-off-by: Christian Franke <christian.franke@t-online.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
//kbuild:lib-$(CONFIG_MAN) += man.o
14
14
 
15
15
//usage:#define man_trivial_usage
16
 
//usage:       "[-aw] MANPAGE..."
 
16
//usage:       "[-aw] [SECTION] MANPAGE[.SECTION]..."
17
17
//usage:#define man_full_usage "\n\n"
18
18
//usage:       "Display manual page\n"
19
19
//usage:     "\n        -a      Display all pages"
240
240
        return xstrdup(skip_whitespace(line));
241
241
}
242
242
 
 
243
static 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
 
243
253
int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
244
254
int man_main(int argc UNUSED_PARAM, char **argv)
245
255
{
246
256
        parser_t *parser;
 
257
        char *conf_sec_list;
247
258
        char *sec_list;
248
259
        char **man_path_list;
249
260
        int count_mp;
255
266
        opt = getopt32(argv, "^+" "aw" "\0" "-1"/*at least one arg*/);
256
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
271
        count_mp = 0;
261
272
        man_path_list = add_MANPATH(NULL, &count_mp,
285
296
                        man_path_list = add_MANPATH(man_path_list, &count_mp, token[1]);
286
297
                }
287
298
                if (strcmp("MANSECT", token[0]) == 0) {
288
 
                        free(sec_list);
289
 
                        sec_list = xstrdup(token[1]);
 
299
                        free(conf_sec_list);
 
300
                        conf_sec_list = xstrdup(token[1]);
290
301
                }
291
302
        }
292
303
        config_close(parser);
293
304
 
294
305
        if (!man_path_list) {
295
 
                static const char *const mpl[] = { "/usr/man", "/usr/share/man", NULL };
 
306
                static const char *const mpl[] ALIGN_PTR = { "/usr/man", "/usr/share/man", NULL };
296
307
                man_path_list = (char**)mpl;
297
308
                /*count_mp = 2; - not used below anyway */
298
309
        }
311
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) && argv[1]) {
 
328
                /* yes */
 
329
                sec_list = *argv++;
 
330
        }
 
331
 
314
332
        not_found = 0;
315
333
        do { /* for each argv[] */
316
334
                const char *cur_path;
321
339
                        found = show_manpage(*argv, /*man:*/ 1, 0);
322
340
                        goto check_found;
323
341
                }
 
342
 
 
343
                /* for each MANPATH */
324
344
                cur_mp = 0;
325
345
                while ((cur_path = man_path_list[cur_mp++]) != NULL) {
326
 
                        /* for each MANPATH */
327
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
356
                                char *next_sect = strchrnul(cur_sect, ':');
330
357
                                int sect_len = next_sect - cur_sect;
331
358
                                char *man_filename;
352
379
                                while (*cur_sect == ':')
353
380
                                        cur_sect++;
354
381
                        } while (*cur_sect);
 
382
 
 
383
                        if (sect_ext) *sect_ext = '.';
355
384
                }
356
385
 check_found:
357
386
                if (!found) {