From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (schwarze@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id s7M4qufp000409 for ; Fri, 22 Aug 2014 00:52:56 -0400 (EDT) Received: (from schwarze@localhost) by krisdoz.my.domain (8.14.5/8.14.3/Submit) id s7M4qt4o020504; Fri, 22 Aug 2014 00:52:55 -0400 (EDT) Date: Fri, 22 Aug 2014 00:52:55 -0400 (EDT) Message-Id: <201408220452.s7M4qt4o020504@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: implement MANPAGER and PAGER X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- implement MANPAGER and PAGER Modified Files: -------------- mdocml: apropos.1 main.c mandoc.1 Revision Data ------------- Index: mandoc.1 =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.1,v retrieving revision 1.107 retrieving revision 1.108 diff -Lmandoc.1 -Lmandoc.1 -u -p -r1.107 -r1.108 --- mandoc.1 +++ mandoc.1 @@ -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 Index: apropos.1 =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos.1,v retrieving revision 1.32 retrieving revision 1.33 diff -Lapropos.1 -Lapropos.1 -u -p -r1.32 -r1.33 --- apropos.1 +++ apropos.1 @@ -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 Index: main.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v retrieving revision 1.183 retrieving revision 1.184 diff -Lmain.c -Lmain.c -u -p -r1.183 -r1.184 --- main.c +++ main.c @@ -637,7 +637,12 @@ mmsg(enum mandocerr t, enum mandoclevel 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); } -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv