Whamcloud - gitweb
util.c (open_pager): Search for the pager to use, starting with
authorTheodore Ts'o <tytso@mit.edu>
Sun, 7 Dec 2003 18:16:25 +0000 (13:16 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 7 Dec 2003 18:16:25 +0000 (13:16 -0500)
'pager', and then falling back to 'less' and then 'more'.
(Addresses Debian Bug: #221977)

debugfs/ChangeLog
debugfs/util.c

index ae475fd..319da69 100644 (file)
@@ -1,5 +1,9 @@
 2003-12-07  Theodore Ts'o  <tytso@mit.edu>
 
+       * util.c (open_pager): Search for the pager to use, starting with
+               'pager', and then falling back to 'less' and then 'more'.
+               (Addresses Debian Bug: #221977)
+
        * debugfs.c, debugfs.h, dump.c, htree.c, icheck.c, logdump.c,
                ls.c, lsdel.c, ncheck.c, setsuper.c, unused.c: Fix gcc
                -Wall nitpicks.
index fd2e99a..319d4fb 100644 (file)
@@ -54,12 +54,30 @@ void reset_getopt(void)
 #ifdef HAVE_OPTRESET
        optreset = 1;           /* Makes BSD getopt happy */
 #endif
-}      
+}
+
+static const char *pager_search_list[] = { "pager", "less", "more", 0 };
+static const char *pager_dir_list[] = { "/usr/bin", "/bin", 0 };
+
+static const char *find_pager(char *buf)
+{
+       const char **i, **j;
+
+       for (i = pager_search_list; *i; i++) {
+               for (j = pager_dir_list; *j; j++) {
+                       sprintf(buf, "%s/%s", *j, *i);
+                       if (access(buf, X_OK) == 0)
+                               return(buf);
+               }
+       }
+       return 0;
+}
 
 FILE *open_pager(void)
 {
-       FILE *outfile;
+       FILE *outfile = 0;
        const char *pager = getenv("PAGER");
+       char buf[80];
 
        signal(SIGPIPE, SIG_IGN);
        if (pager) {
@@ -67,11 +85,15 @@ FILE *open_pager(void)
                        return stdout;
                }
        } else
-               pager = "more";
+               pager = find_pager(buf);
+
+       if (pager)
+               outfile = popen(pager, "w");
 
-       outfile = popen(pager, "w");
+       if (!outfile)
+               outfile = stdout;
 
-       return (outfile ? outfile : stdout);
+       return (outfile);
 }
 
 void close_pager(FILE *stream)