Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/miscutils/man.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/miscutils/man.c

    r3232 r3621  
    6767
    6868        line = xmalloc_open_zipped_read_close(man_filename, NULL);
    69         if (!line || strncmp(line, ".so ", 4) != 0) {
     69        if (!line || !is_prefixed_with(line, ".so ")) {
    7070            free(line);
    7171            goto ordinary_manpage;
     
    103103 ordinary_manpage:
    104104    close(STDIN_FILENO);
    105     open_zipped(man_filename); /* guaranteed to use fd 0 (STDIN_FILENO) */
     105    open_zipped(man_filename, /*fail_if_not_compressed:*/ 0); /* guaranteed to use fd 0 (STDIN_FILENO) */
    106106    /* "2>&1" is added so that nroff errors are shown in pager too.
    107107     * Otherwise it may show just empty screen */
    108108    cmd = xasprintf(
    109         man ? "gtbl | nroff -Tlatin1 -mandoc 2>&1 | %s"
     109        /* replaced -Tlatin1 with -Tascii for non-UTF8 displays */
     110        man ? "gtbl | nroff -Tascii -mandoc 2>&1 | %s"
    110111            : "%s",
    111112        pager);
     
    147148}
    148149
     150static char **add_MANPATH(char **man_path_list, int *count_mp, char *path)
     151{
     152    if (path) while (*path) {
     153        char *next_path;
     154        char **path_element;
     155
     156        next_path = strchr(path, ':');
     157        if (next_path) {
     158            if (next_path == path) /* "::"? */
     159                goto next;
     160            *next_path = '\0';
     161        }
     162        /* Do we already have path? */
     163        path_element = man_path_list;
     164        if (path_element) while (*path_element) {
     165            if (strcmp(*path_element, path) == 0)
     166                goto skip;
     167            path_element++;
     168        }
     169        man_path_list = xrealloc_vector(man_path_list, 4, *count_mp);
     170        man_path_list[*count_mp] = xstrdup(path);
     171        (*count_mp)++;
     172        /* man_path_list is NULL terminated */
     173        /* man_path_list[*count_mp] = NULL; - xrealloc_vector did it */
     174 skip:
     175        if (!next_path)
     176            break;
     177        /* "path" may be a result of getenv(), be nice and don't mangle it */
     178        *next_path = ':';
     179 next:
     180        path = next_path + 1;
     181    }
     182    return man_path_list;
     183}
     184
    149185int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    150186int man_main(int argc UNUSED_PARAM, char **argv)
    151187{
    152188    parser_t *parser;
    153     const char *pager;
    154     char **man_path_list;
     189    const char *pager = ENABLE_LESS ? "less" : "more";
    155190    char *sec_list;
    156191    char *cur_path, *cur_sect;
    157     int count_mp, cur_mp;
     192    char **man_path_list;
     193    int count_mp;
     194    int cur_mp;
    158195    int opt, not_found;
    159196    char *token[2];
     
    163200    argv += optind;
    164201
    165     sec_list = xstrdup("1:2:3:4:5:6:7:8:9");
    166     /* Last valid man_path_list[] is [0x10] */
     202    sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9");
     203
    167204    count_mp = 0;
    168     man_path_list = xzalloc(0x11 * sizeof(man_path_list[0]));
    169     man_path_list[0] = getenv("MANPATH");
    170     if (!man_path_list[0]) /* default, may be overridden by /etc/man.conf */
     205    man_path_list = add_MANPATH(NULL, &count_mp,
     206            getenv("MANDATORY_MANPATH"+10) /* "MANPATH" */
     207    );
     208    if (!man_path_list) {
     209        /* default, may be overridden by /etc/man.conf */
     210        man_path_list = xzalloc(2 * sizeof(man_path_list[0]));
    171211        man_path_list[0] = (char*)"/usr/man";
    172     else
    173         count_mp++;
    174     pager = getenv("MANPAGER");
    175     if (!pager) {
    176         pager = getenv("PAGER");
    177         if (!pager)
    178             pager = "more";
     212        /* count_mp stays 0.
     213         * Thus, man.conf will overwrite man_path_list[0]
     214         * if a path is defined there.
     215         */
    179216    }
    180217
     
    191228        if (!token[1])
    192229            continue;
     230        if (strcmp("DEFINE", token[0]) == 0) {
     231            if (is_prefixed_with("pager", token[1])) {
     232                pager = xstrdup(skip_whitespace(token[1]) + 5);
     233            }
     234        } else
    193235        if (strcmp("MANDATORY_MANPATH"+10, token[0]) == 0 /* "MANPATH"? */
    194236         || strcmp("MANDATORY_MANPATH", token[0]) == 0
    195237        ) {
    196             char *path = token[1];
    197             while (*path) {
    198                 char *next_path;
    199                 char **path_element;
    200 
    201                 next_path = strchr(path, ':');
    202                 if (next_path) {
    203                     *next_path = '\0';
    204                     if (next_path++ == path) /* "::"? */
    205                         goto next;
    206                 }
    207                 /* Do we already have path? */
    208                 path_element = man_path_list;
    209                 while (*path_element) {
    210                     if (strcmp(*path_element, path) == 0)
    211                         goto skip;
    212                     path_element++;
    213                 }
    214                 man_path_list = xrealloc_vector(man_path_list, 4, count_mp);
    215                 man_path_list[count_mp] = xstrdup(path);
    216                 count_mp++;
    217                 /* man_path_list is NULL terminated */
    218                 /*man_path_list[count_mp] = NULL; - xrealloc_vector did it */
    219  skip:
    220                 if (!next_path)
    221                     break;
    222  next:
    223                 path = next_path;
    224             }
     238            man_path_list = add_MANPATH(man_path_list, &count_mp, token[1]);
    225239        }
    226240        if (strcmp("MANSECT", token[0]) == 0) {
     
    230244    }
    231245    config_close(parser);
     246
     247    {
     248        /* environment overrides setting from man.config */
     249        char *env_pager = getenv("MANPAGER");
     250        if (!env_pager)
     251            env_pager = getenv("PAGER");
     252        if (env_pager)
     253            pager = env_pager;
     254    }
    232255
    233256    not_found = 0;
Note: See TracChangeset for help on using the changeset viewer.