source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: implement MANPAGER and PAGER
@ 2014-08-22  4:52 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-08-22  4:52 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-08-22  4:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-22  4:52 mdocml: implement MANPAGER and PAGER schwarze

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).