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.
#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) {
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)