From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: implement MANPAGER and PAGER
Date: Fri, 22 Aug 2014 00:52:55 -0400 (EDT) [thread overview]
Message-ID: <201408220452.s7M4qt4o020504@krisdoz.my.domain> (raw)
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
reply other threads:[~2014-08-22 4:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201408220452.s7M4qt4o020504@krisdoz.my.domain \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).