From ec7fdb8f76ea88ba838690ae151735ae5ef800ba Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sun, 7 Dec 2003 13:16:25 -0500 Subject: [PATCH] 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/ChangeLog | 4 ++++ debugfs/util.c | 32 +++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/debugfs/ChangeLog b/debugfs/ChangeLog index ae475fd..319da69 100644 --- a/debugfs/ChangeLog +++ b/debugfs/ChangeLog @@ -1,5 +1,9 @@ 2003-12-07 Theodore Ts'o + * 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. diff --git a/debugfs/util.c b/debugfs/util.c index fd2e99a..319d4fb 100644 --- a/debugfs/util.c +++ b/debugfs/util.c @@ -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) -- 1.8.3.1