diff options
author | Theodore Ts'o <tytso@mit.edu> | 2003-12-07 13:16:25 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2003-12-07 13:16:25 -0500 |
commit | ec7fdb8f76ea88ba838690ae151735ae5ef800ba (patch) | |
tree | 4040c3905f3639f57ca3ec31ae553c72ff4573ff /debugfs/util.c | |
parent | 817cc0358c8d128015c80ed30171a69ff1e1d2fc (diff) | |
download | e2fsprogs-ec7fdb8f76ea88ba838690ae151735ae5ef800ba.tar.gz |
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)
Diffstat (limited to 'debugfs/util.c')
-rw-r--r-- | debugfs/util.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/debugfs/util.c b/debugfs/util.c index fd2e99a9..319d4fba 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) |