aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--apropos.121
-rw-r--r--main.c56
-rw-r--r--mandoc.121
3 files changed, 88 insertions, 10 deletions
diff --git a/apropos.1 b/apropos.1
index 4a7bba67..e1756039 100644
--- a/apropos.1
+++ b/apropos.1
@@ -1,4 +1,4 @@
-.\" $Id: apropos.1,v 1.31 2014/08/21 02:28:40 schwarze Exp $
+.\" $Id: apropos.1,v 1.32 2014/08/22 03:42:18 schwarze Exp $
.\"
.\" Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 21 2014 $
+.Dd $Mdocdate: August 22 2014 $
.Dt APROPOS 1
.Os
.Sh NAME
@@ -24,7 +24,7 @@
.Nd search manual page databases
.Sh SYNOPSIS
.Nm
-.Op Fl afkw
+.Op Fl acfkw
.Op Fl C Ar file
.Op Fl M Ar path
.Op Fl m Ar path
@@ -71,7 +71,14 @@ just like
.Xr man 1
.Fl a
would.
-In this mode, the options
+If the standard output is a terminal device and
+.Fl c
+is not specified, use
+.Xr more 1
+to paginate them.
+In
+.Fl a
+mode, the options
.Fl IOTW
described in the
.Xr mandoc 1
@@ -82,6 +89,12 @@ Specify an alternative configuration
in
.Xr man.conf 5
format.
+.It Fl c
+In
+.Fl a
+mode, copy the formatted manual pages to the standard output without using
+.Xr more 1
+to paginate them.
.It Fl f
Search for all words in
.Ar expression
diff --git a/main.c b/main.c
index b36bc899..924eddd3 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,6 @@
-/* $Id: main.c,v 1.182 2014/08/21 00:32:15 schwarze Exp $ */
+/* $Id: main.c,v 1.183 2014/08/22 03:42:18 schwarze Exp $ */
/*
- * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
*
@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <assert.h>
+#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@@ -84,6 +85,7 @@ static void mmsg(enum mandocerr, enum mandoclevel,
const char *, int, int, const char *);
static void parse(struct curparse *, int,
const char *, enum mandoclevel *);
+static void spawn_pager(void);
static int toptions(struct curparse *, char *);
static void usage(enum argmode) __attribute__((noreturn));
static void version(void) __attribute__((noreturn));
@@ -111,6 +113,7 @@ main(int argc, char *argv[])
enum mandoclevel rc;
enum outmode outmode;
int show_usage;
+ int use_pager;
int options;
int c;
@@ -145,9 +148,11 @@ main(int argc, char *argv[])
options = MPARSE_SO;
defos = NULL;
+ use_pager = 1;
show_usage = 0;
outmode = OUTMODE_DEF;
- while (-1 != (c = getopt(argc, argv, "aC:fI:ikM:m:O:S:s:T:VW:w"))) {
+
+ while (-1 != (c = getopt(argc, argv, "aC:cfI:ikM:m:O:S:s:T:VW:w"))) {
switch (c) {
case 'a':
outmode = OUTMODE_ALL;
@@ -155,6 +160,9 @@ main(int argc, char *argv[])
case 'C':
conf_file = optarg;
break;
+ case 'c':
+ use_pager = 0;
+ break;
case 'f':
search.argmode = ARG_WORD;
break;
@@ -223,6 +231,7 @@ main(int argc, char *argv[])
switch (search.argmode) {
case ARG_FILE:
outmode = OUTMODE_ALL;
+ use_pager = 0;
break;
case ARG_NAME:
outmode = OUTMODE_ONE;
@@ -319,6 +328,9 @@ main(int argc, char *argv[])
if ( ! moptions(&options, auxpaths))
return((int)MANDOCLEVEL_BADARG);
+ if (use_pager && isatty(STDOUT_FILENO))
+ spawn_pager();
+
curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos);
/*
@@ -621,3 +633,41 @@ mmsg(enum mandocerr t, enum mandoclevel lvl,
fputc('\n', stderr);
}
+
+static void
+spawn_pager(void)
+{
+ int fildes[2];
+
+ if (pipe(fildes) == -1) {
+ fprintf(stderr, "%s: pipe: %s\n",
+ progname, strerror(errno));
+ return;
+ }
+
+ switch (fork()) {
+ case -1:
+ fprintf(stderr, "%s: fork: %s\n",
+ progname, strerror(errno));
+ exit((int)MANDOCLEVEL_SYSERR);
+ case 0:
+ close(fildes[0]);
+ if (dup2(fildes[1], STDOUT_FILENO) == -1) {
+ fprintf(stderr, "%s: dup output: %s\n",
+ progname, strerror(errno));
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
+ 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));
+ }
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
+}
diff --git a/mandoc.1 b/mandoc.1
index e9f73757..a9e4a67d 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -1,4 +1,4 @@
-.\" $Id: mandoc.1,v 1.106 2014/08/08 01:50:59 schwarze Exp $
+.\" $Id: mandoc.1,v 1.107 2014/08/22 03:42:18 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 8 2014 $
+.Dd $Mdocdate: August 22 2014 $
.Dt MANDOC 1
.Os
.Sh NAME
@@ -23,7 +23,7 @@
.Nd format and display UNIX manuals
.Sh SYNOPSIS
.Nm mandoc
-.Op Fl V
+.Op Fl acV
.Sm off
.Op Fl I Cm os Li = Ar name
.Sm on
@@ -53,6 +53,21 @@ output.
.Pp
The arguments are as follows:
.Bl -tag -width Ds
+.It Fl a
+If the standard output is a terminal device and
+.Fl c
+is not specified, use
+.Xr more 1
+to paginate the output, just like
+.Xr man 1
+would.
+.It Fl c
+Copy the formatted manual pages to the standard output without using
+.Xr more 1
+to paginate them.
+This is the default.
+It can be specified to override
+.Fl a .
.Sm off
.It Fl I Cm os Li = Ar name
.Sm on