diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2014-08-22 04:52:55 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2014-08-22 04:52:55 +0000 |
commit | 5aa048ebe37935a5d5f1b75804c0adfcde21a146 (patch) | |
tree | c66a9273d444c083b1ec659b1cf9c60b6cf0c42b | |
parent | c3e7065441bd0ab25518a236f7d95b8bd84d2694 (diff) | |
download | mandoc-5aa048ebe37935a5d5f1b75804c0adfcde21a146.tar.gz |
implement MANPAGER and PAGER
-rw-r--r-- | apropos.1 | 14 | ||||
-rw-r--r-- | main.c | 58 | ||||
-rw-r--r-- | mandoc.1 | 15 |
3 files changed, 76 insertions, 11 deletions
@@ -318,7 +318,12 @@ Text production: .It Li \&Dx Ta Dx No version reference .El .Sh ENVIRONMENT -.Bl -tag -width MANPATH +.Bl -tag -width MANPAGER +.It Ev MANPAGER +Any non-empty value of the environment variable +.Ev MANPAGER +will be used instead of the standard pagination program, +.Xr more 1 . .It Ev MANPATH The standard search path used by .Xr man 1 @@ -336,6 +341,13 @@ or if it contains two adjacent colons, the standard search path is inserted between the colons. If none of these conditions are met, it overrides the standard search path. +.It Ev PAGER +Specifies the pagination program to use when +.Ev MANPAGER +is not defined. +If neither PAGER nor MANPAGER is defined, +.Pa /usr/bin/more Fl s +will be used. .El .Sh FILES .Bl -tag -width "/etc/man.conf" -compact @@ -637,7 +637,12 @@ mmsg(enum mandocerr t, enum mandoclevel lvl, static void spawn_pager(void) { - int fildes[2]; +#define MAX_PAGER_ARGS 16 + char *argv[MAX_PAGER_ARGS]; + const char *pager; + char *cp; + int fildes[2]; + int argc; if (pipe(fildes) == -1) { fprintf(stderr, "%s: pipe: %s\n", @@ -659,15 +664,48 @@ spawn_pager(void) } return; default: - close(fildes[1]); - if (dup2(fildes[0], STDIN_FILENO) == -1) { - fprintf(stderr, "%s: dup input: %s\n", - progname, strerror(errno)); - } else { - execlp("more", "more", "-s", NULL); - fprintf(stderr, "%s: exec: %s\n", - progname, strerror(errno)); - } + break; + } + + /* The original process becomes the pager. */ + + close(fildes[1]); + if (dup2(fildes[0], STDIN_FILENO) == -1) { + fprintf(stderr, "%s: dup input: %s\n", + progname, strerror(errno)); exit((int)MANDOCLEVEL_SYSERR); } + + pager = getenv("MANPAGER"); + if (pager == NULL || *pager == '\0') + pager = getenv("PAGER"); + if (pager == NULL || *pager == '\0') + pager = "/usr/bin/more -s"; + cp = mandoc_strdup(pager); + + /* + * Parse the pager command into words. + * Intentionally do not do anything fancy here. + */ + + argc = 0; + while (argc + 1 < MAX_PAGER_ARGS) { + argv[argc++] = cp; + cp = strchr(cp, ' '); + if (cp == NULL) + break; + *cp++ = '\0'; + while (*cp == ' ') + cp++; + if (*cp == '\0') + break; + } + argv[argc] = NULL; + + /* Hand over to the pager. */ + + execvp(argv[0], argv); + fprintf(stderr, "%s: exec: %s\n", + progname, strerror(errno)); + exit((int)MANDOCLEVEL_SYSERR); } @@ -440,6 +440,21 @@ See .Sx HTML Output for details; beyond generating XHTML tags instead of HTML tags, these output modes are identical. +.Sh ENVIRONMENT +.Bl -tag -width MANPAGER +.It Ev MANPAGER +Any non-empty value of the environment variable +.Ev MANPAGER +will be used instead of the standard pagination program, +.Xr more 1 . +.It Ev PAGER +Specifies the pagination program to use when +.Ev MANPAGER +is not defined. +If neither PAGER nor MANPAGER is defined, +.Pa /usr/bin/more Fl s +will be used. +.El .Sh EXIT STATUS The .Nm |