man: default to ascii
[oweals/busybox.git] / miscutils / man.c
index e380fdabaf2b984a58edde8ea57637173dae62bf..5c1fa2c9dedea0b433668d64727614b21707a028 100644 (file)
@@ -102,11 +102,12 @@ static int run_pipe(const char *pager, char *man_filename, int man, int level)
 
  ordinary_manpage:
        close(STDIN_FILENO);
-       open_zipped(man_filename); /* guaranteed to use fd 0 (STDIN_FILENO) */
+       open_zipped(man_filename, /*fail_if_not_compressed:*/ 0); /* guaranteed to use fd 0 (STDIN_FILENO) */
        /* "2>&1" is added so that nroff errors are shown in pager too.
         * Otherwise it may show just empty screen */
        cmd = xasprintf(
-               man ? "gtbl | nroff -Tlatin1 -mandoc 2>&1 | %s"
+               /* replaced -Tlatin1 with -Tascii for non-UTF8 displays */
+               man ? "gtbl | nroff -Tascii -mandoc 2>&1 | %s"
                    : "%s",
                pager);
        system(cmd);
@@ -150,7 +151,7 @@ int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int man_main(int argc UNUSED_PARAM, char **argv)
 {
        parser_t *parser;
-       const char *pager;
+       const char *pager = ENABLE_LESS ? "less" : "more";
        char **man_path_list;
        char *sec_list;
        char *cur_path, *cur_sect;
@@ -162,7 +163,7 @@ int man_main(int argc UNUSED_PARAM, char **argv)
        opt = getopt32(argv, "+aw");
        argv += optind;
 
-       sec_list = xstrdup("1:2:3:4:5:6:7:8:9");
+       sec_list = xstrdup("0p:1:1p:2:3:3p:4:5:6:7:8:9");
        /* Last valid man_path_list[] is [0x10] */
        count_mp = 0;
        man_path_list = xzalloc(0x11 * sizeof(man_path_list[0]));
@@ -171,12 +172,6 @@ int man_main(int argc UNUSED_PARAM, char **argv)
                man_path_list[0] = (char*)"/usr/man";
        else
                count_mp++;
-       pager = getenv("MANPAGER");
-       if (!pager) {
-               pager = getenv("PAGER");
-               if (!pager)
-                       pager = "more";
-       }
 
        /* Parse man.conf[ig] or man_db.conf */
        /* man version 1.6f uses man.config */
@@ -190,6 +185,11 @@ int man_main(int argc UNUSED_PARAM, char **argv)
        while (config_read(parser, token, 2, 0, "# \t", PARSE_NORMAL)) {
                if (!token[1])
                        continue;
+               if (strcmp("DEFINE", token[0]) == 0) {
+                       if (strncmp("pager", token[1], 5) == 0) {
+                               pager = xstrdup(skip_whitespace(token[1]) + 5);
+                       }
+               } else
                if (strcmp("MANDATORY_MANPATH"+10, token[0]) == 0 /* "MANPATH"? */
                 || strcmp("MANDATORY_MANPATH", token[0]) == 0
                ) {
@@ -230,6 +230,15 @@ int man_main(int argc UNUSED_PARAM, char **argv)
        }
        config_close(parser);
 
+       {
+               /* environment overrides setting from man.config */
+               char *env_pager = getenv("MANPAGER");
+               if (!env_pager)
+                       env_pager = getenv("PAGER");
+               if (env_pager)
+                       pager = env_pager;
+       }
+
        not_found = 0;
        do { /* for each argv[] */
                int found = 0;