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
This commit is contained in:
Juli Mallett 2002-03-31 18:44:36 +00:00
parent 9a0c70235d
commit 032b32ada6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=93481
2 changed files with 52 additions and 4 deletions

View File

@ -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

View File

@ -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 */
@ -138,6 +140,28 @@ main(argc, argv)
return(0);
}
/*
* 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;