Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/pr - Fix PR 19468 by adding -f and -p options to pr(1).
details: https://anonhg.NetBSD.org/src/rev/e763e4f93bb5
branches: trunk
changeset: 780440:e763e4f93bb5
user: ginsbach <ginsbach%NetBSD.org@localhost>
date: Tue Jul 24 02:13:04 2012 +0000
description:
- Fix PR 19468 by adding -f and -p options to pr(1).
Changes adapted from patch by Ryan Younce and FreeBSD. The provided
patch was not used directly as the changes didn't mimic the System V
origins of these options. System V pr(1) does not pause for empty files.
These changes follow that precedent.
- Improve man page description of the -i option.
diffstat:
usr.bin/pr/pr.1 | 33 +++++++++++++++--
usr.bin/pr/pr.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++-------
usr.bin/pr/pr.h | 12 +++++-
3 files changed, 127 insertions(+), 21 deletions(-)
diffs (truncated from 347 to 300 lines):
diff -r 91609ee331c4 -r e763e4f93bb5 usr.bin/pr/pr.1
--- a/usr.bin/pr/pr.1 Mon Jul 23 19:06:10 2012 +0000
+++ b/usr.bin/pr/pr.1 Tue Jul 24 02:13:04 2012 +0000
@@ -1,8 +1,10 @@
-.\" $NetBSD: pr.1,v 1.18 2012/04/08 22:00:39 wiz Exp $
+.\" $NetBSD: pr.1,v 1.19 2012/07/24 02:13:04 ginsbach Exp $
.\"
.\" Copyright (c) 1991 Keith Muller.
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
+.\" Copyright (c) 1994-1995, 1997, 1999-2003, 2009, 2012
+.\" The NetBSD Foundation, Inc.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Keith Muller of the University of California, San Diego.
@@ -32,9 +34,9 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)pr.1 8.1 (Berkeley) 6/6/93
-.\" $NetBSD: pr.1,v 1.18 2012/04/08 22:00:39 wiz Exp $
+.\" $NetBSD: pr.1,v 1.19 2012/07/24 02:13:04 ginsbach Exp $
.\"
-.Dd June 6, 1993
+.Dd May 4, 2012
.Dt PR 1
.Os
.Sh NAME
@@ -44,7 +46,7 @@
.Nm
.Op Ar \&+page
.Op Fl Ar column
-.Op Fl adFmrt
+.Op Fl adFfmprt
.Oo
.Op Fl e
.Op Ar char
@@ -161,6 +163,11 @@
sequence of
.Em \*[Lt]newline\*[Gt]
characters.
+.It Fl f
+Same as
+.Fl F .
+Additionally pause before beginning the first page
+if the standard output is associated with a terminal.
.It Fl h Ar header
Use the string
.Ar header
@@ -184,6 +191,12 @@
is specified, it is used as the output
.Em \*[Lt]tab\*[Gt]
character.
+If the first character of
+.Ar char
+is a digit then
+.Ar char
+is treated as
+.Ar gap .
.It Fl l Ar lines
Override the 66 line default and reset the page length to
.Ar lines .
@@ -239,6 +252,16 @@
.Fl o
option is not specified, the default is zero.
The space taken is in addition to the output line width.
+.It Fl p
+Pause before beginning each page if the
+standard output is associated with a terminal.
+.Nm
+will write an
+.Em \*[Lt]alert\*[Gt]
+to standard error and wait for a
+.Em \*[Lt]carriage-return\*[Gt]
+to be read on
+.Pa /dev/tty .
.It Fl r
Write no diagnostic reports on failure to open a file.
.It Fl s Ar char
@@ -324,5 +347,5 @@
The
.Nm
utility is
-.St -p1003.2
+.St -p1003.1-2008
compatible.
diff -r 91609ee331c4 -r e763e4f93bb5 usr.bin/pr/pr.c
--- a/usr.bin/pr/pr.c Mon Jul 23 19:06:10 2012 +0000
+++ b/usr.bin/pr/pr.c Tue Jul 24 02:13:04 2012 +0000
@@ -1,9 +1,11 @@
-/* $NetBSD: pr.c,v 1.22 2012/03/12 18:06:24 christos Exp $ */
+/* $NetBSD: pr.c,v 1.23 2012/07/24 02:13:04 ginsbach Exp $ */
/*-
* Copyright (c) 1991 Keith Muller.
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
+ * Copyright (c) 2012
+ * The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to Berkeley by
* Keith Muller of the University of California, San Diego.
@@ -43,7 +45,7 @@
#if 0
from: static char sccsid[] = "@(#)pr.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: pr.c,v 1.22 2012/03/12 18:06:24 christos Exp $");
+__RCSID("$NetBSD: pr.c,v 1.23 2012/07/24 02:13:04 ginsbach Exp $");
#endif
#endif /* not lint */
@@ -96,9 +98,12 @@
static int nodiag; /* do not report file open errors */
static char schar; /* text column separation character */
static int sflag; /* -s option for multiple columns */
+static int ttyout; /* output is a tty */
static int nohead; /* do not write head and trailer */
+static int pgpause; /* pause before each page */
static int pgwd; /* page width with multiple col output */
static const char *timefrmt = TIMEFMT; /* time conversion string */
+static FILE *ttyinf; /* input terminal for page pauses */
/*
* misc globals
@@ -120,6 +125,7 @@
static int otln(char *, int, int *, int *, int);
static void pfail(void);
static int prhead(char *, const char *, int);
+static void prpause(int);
static int prtail(int, int);
static int setup(int, char **);
__dead static void terminate(int);
@@ -242,9 +248,14 @@
*/
if ((cnt = inln(inf,lbuf,LBUF,&cps,0,&mor)) < 0)
break;
- if (!linecnt && !nohead &&
- prhead(hbuf, fname, pagecnt))
- goto out;
+ if (!linecnt) {
+ if (pgpause)
+ prpause(pagecnt);
+
+ if (!nohead &&
+ prhead(hbuf, fname, pagecnt))
+ goto out;
+ }
/*
* start of new line.
@@ -509,6 +520,9 @@
if (cvc % clcnt)
++pln;
+ if (pgpause)
+ prpause(pagecnt);
+
/*
* print header
*/
@@ -578,8 +592,13 @@
/*
* print header
*/
- if (pln && !nohead && prhead(hbuf, fname, pagecnt))
- goto out;
+ if (pln) {
+ if (pgpause)
+ prpause(pagecnt);
+
+ if (!nohead && prhead(hbuf, fname, pagecnt))
+ goto out;
+ }
/*
* output each line
@@ -731,9 +750,14 @@
*/
if ((j = lstdat - buf) <= offst)
break;
- if (!i && !nohead &&
- prhead(hbuf, fname, pagecnt))
- goto out;
+ if (!i) {
+ if (pgpause)
+ prpause(pagecnt);
+
+ if (!nohead &&
+ prhead(hbuf, fname, pagecnt))
+ goto out;
+ }
/*
* output line
*/
@@ -941,8 +965,13 @@
if ((j = lstdat - buf) <= offst)
break;
- if (!i && !nohead && prhead(hbuf, fname, pagecnt))
- goto out;
+ if (!i) {
+ if (pgpause)
+ prpause(pagecnt);
+
+ if (!nohead && prhead(hbuf, fname, pagecnt))
+ goto out;
+ }
/*
* output line
@@ -1419,6 +1448,32 @@
}
/*
+ * prpause(): pause before printing each page
+ *
+ * pagcnt page number
+ */
+static void
+prpause(int pagcnt)
+{
+
+ if (ttyout) {
+ int c;
+
+ (void)putc('\a', stderr);
+ (void)fflush(stderr);
+
+ while ((c = getc(ttyinf)) != '\n' && c != EOF)
+ ;
+
+ /*
+ * pause ONLY before first page of first file
+ */
+ if (pgpause == FIRSTPAGE && pagcnt == 1)
+ pgpause = NO_PAUSE;
+ }
+}
+
+/*
* prhead(): prints the top of page header
*
* buf buffer with time field (and offset)
@@ -1561,7 +1616,7 @@
(void)fputs(
" [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",errf);
(void)fputs(
- " [-s[ch]] [-w width] [-] [file ...]\n", errf);
+ " [-s[ch]] [-w width] [-fp] [-] [file ...]\n", errf);
}
/*
@@ -1577,6 +1632,8 @@
int wflag = 0;
int cflag = 0;
+ ttyinf = stdin;
+
if (isatty(fileno(stdout))) {
/*
* defer diagnostics until processing is done
@@ -1585,9 +1642,10 @@
(void)fputs("Cannot defer diagnostic messages\n",stderr);
return(1);
}
+ ttyout = 1;
} else
errf = stderr;
- while ((c = egetopt(argc, argv, "#adFmrte?h:i?l:n?o:s?T:w:")) != -1) {
+ while ((c = egetopt(argc, argv, "#adFfmrte?h:i?l:n?o:ps?T:w:")) != -1) {
switch (c) {
case '+':
if ((pgnm = atoi(eoptarg)) < 1) {
@@ -1633,6 +1691,9 @@
} else
ingap = INGAP;
break;
+ case 'f':
+ pgpause |= FIRSTPAGE;
+ /*FALLTHROUGH*/
case 'F':
++formfeed;
break;
@@ -1701,6 +1762,9 @@
return(1);
}
break;
+ case 'p':
+ pgpause |= EACHPAGE;
+ break;
case 'r':
++nodiag;
break;
@@ -1819,5 +1883,16 @@
}
}
+ /*
+ * open /dev/tty if we are to pause before each page
+ * but only if stdout is a terminal and stdin is not a terminal
+ */
Home |
Main Index |
Thread Index |
Old Index