summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-08-22 03:42:18 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-08-22 03:42:18 +0000
commitc3e7065441bd0ab25518a236f7d95b8bd84d2694 (patch)
tree07708e9dcfc7c69276562a6f433f743f92e107b5
parent8d9cd5cdd95aa9923e4a071a9e4c7f63545120d4 (diff)
downloadmandoc-c3e7065441bd0ab25518a236f7d95b8bd84d2694.tar.gz
mandoc -a, man, apropos -a, whatis -a now paginate by default
but provide an option -c to not paginate; taking inspiration from manpage.c, hence adding (c) 2012 kristaps@
-rw-r--r--apropos.117
-rw-r--r--main.c54
-rw-r--r--mandoc.117
3 files changed, 83 insertions, 5 deletions
diff --git a/apropos.1 b/apropos.1
index 43e2c62b..91bed314 100644
--- a/apropos.1
+++ b/apropos.1
@@ -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 30a64a83..34da84e4 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,6 @@
/* $Id$ */
/*
- * 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 7e31af4f..2ed605ca 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -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