summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2002-03-31 18:44:36 +0000
committerjmallett <jmallett@FreeBSD.org>2002-03-31 18:44:36 +0000
commitcace3f9d081619c267182e7e1c926cafabc283e2 (patch)
tree02a08d1645bdc41e4c0c2ad249f5707e83a9e02d
parent77d700702cc9a30522135da39f2c704d0e8bfa0b (diff)
downloadFreeBSD-src-cace3f9d081619c267182e7e1c926cafabc283e2.zip
FreeBSD-src-cace3f9d081619c267182e7e1c926cafabc283e2.tar.gz
Add P1003.1-2001 -f and -p options.
PR: standards/36243 Submitted by: Tim J. Robbins <tim@robbins.dropbear.id.au> Reviewed by: mike MFC after: 2 weeks
-rw-r--r--usr.bin/pr/pr.113
-rw-r--r--usr.bin/pr/pr.c43
2 files changed, 52 insertions, 4 deletions
diff --git a/usr.bin/pr/pr.1 b/usr.bin/pr/pr.1
index 51111f6..3ebd87a 100644
--- a/usr.bin/pr/pr.1
+++ b/usr.bin/pr/pr.1
@@ -50,7 +50,7 @@
.Bk -words
.Op Fl Ar column
.Ek
-.Op Fl adFmrt
+.Op Fl adFfmprt
.Bk -words
.Oo
.Op Fl e
@@ -197,6 +197,10 @@ instead of the default behavior that uses a
sequence of
.Em <newline>
characters.
+.It Fl f
+Same as
+.Fl F
+but pause before beginning the first page if standard output is a terminal.
.It Fl h Ar header
Use the string
.Ar header
@@ -293,6 +297,11 @@ If the
.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 each page if the standard output is a terminal.
+.Nm
+will write an alert character to standard error and wait for a carriage
+return to be read on the terminal.
.It Fl r
Write no diagnostic reports on failure to open a file.
.It Fl s Ar char
@@ -373,7 +382,7 @@ file printing is complete (when printing to a terminal).
The
.Nm
utility is
-.St -p1003.2
+.St -p1003.1-2001
compatible.
.Sh HISTORY
A
diff --git a/usr.bin/pr/pr.c b/usr.bin/pr/pr.c
index 941b8fe..754c7db 100644
--- a/usr.bin/pr/pr.c
+++ b/usr.bin/pr/pr.c
@@ -84,6 +84,8 @@ int across; /* mult col flag; write across page */
int dspace; /* double space flag */
char inchar; /* expand input char */
int ingap; /* expand input gap */
+int pausefst; /* Pause before first page */
+int pauseall; /* Pause before each page */
int formfeed; /* use formfeed as trailer */
char *header; /* header name instead of file name */
char ochar; /* contract output char */
@@ -139,6 +141,28 @@ main(argc, argv)
}
/*
+ * Check if we should pause and write an alert character and wait for a
+ * carriage return on /dev/tty.
+ */
+void
+ttypause(pagecnt)
+ int pagecnt;
+{
+ int pch;
+ FILE *ttyfp;
+
+ if ((pauseall || (pausefst && pagecnt == 1)) &&
+ isatty(STDOUT_FILENO)) {
+ if ((ttyfp = fopen("/dev/tty", "r")) != NULL) {
+ (void)putc('\a', stderr);
+ while ((pch = getc(ttyfp)) != '\n' && pch != EOF)
+ ;
+ (void)fclose(ttyfp);
+ }
+ }
+}
+
+/*
* onecol: print files with only one column of output.
* Line length is unlimited.
*/
@@ -222,6 +246,8 @@ onecol(argc, argv)
ips = 0;
cps = 0;
+ ttypause(pagecnt);
+
/*
* loop by line
*/
@@ -410,6 +436,8 @@ vertcol(argc, argv)
* loop by page
*/
for(;;) {
+ ttypause(pagecnt);
+
/*
* loop by column
*/
@@ -666,6 +694,8 @@ horzcol(argc, argv)
* loop by page
*/
for(;;) {
+ ttypause(pagecnt);
+
/*
* loop by line
*/
@@ -856,6 +886,8 @@ mulfile(argc, argv)
* continue to loop while any file still has data
*/
while (actf > 0) {
+ ttypause(pagecnt);
+
/*
* loop by line
*/
@@ -1561,7 +1593,8 @@ void
usage()
{
(void)fputs(
- "usage: pr [+page] [-col] [-adFmrt] [-e[ch][gap]] [-h header]\n",err);
+ "usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n",
+ err);
(void)fputs(
" [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err);
(void)fputs(
@@ -1596,7 +1629,7 @@ setup(argc, argv)
}
} else
err = stderr;
- while ((c = egetopt(argc, argv, "#adFmrte?h:i?L:l:n?o:s?w:")) != -1) {
+ while ((c = egetopt(argc, argv, "#adFfmrte?h:i?L:l:n?o:ps?w:")) != -1) {
switch (c) {
case '+':
if ((pgnm = atoi(eoptarg)) < 1) {
@@ -1640,6 +1673,9 @@ setup(argc, argv)
} else
ingap = INGAP;
break;
+ case 'f':
+ ++pausefst;
+ /*FALLTHROUGH*/
case 'F':
++formfeed;
break;
@@ -1705,6 +1741,9 @@ setup(argc, argv)
return(1);
}
break;
+ case 'p':
+ ++pauseall;
+ break;
case 'r':
++nodiag;
break;
OpenPOWER on IntegriCloud