Date: Wed, 30 Jan 2002 19:43:55 +1100 From: "Tim J. Robbins" <tim@robbins.dropbear.id.au> To: freebsd-standards@FreeBSD.ORG Subject: Patch for pr -f and -p options Message-ID: <20020130194355.A8993@descent.robbins.dropbear.id.au>
next in thread | raw e-mail | index | archive | help
--SUOF0GtieIMvvwua Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This patch adds the -f and -p options to pr. Tim --SUOF0GtieIMvvwua Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="pr.diff" Index: pr/pr.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/pr/pr.1,v retrieving revision 1.17 diff -u -r1.17 pr.1 --- pr/pr.1 2001/09/21 02:57:56 1.17 +++ pr/pr.1 2002/01/30 08:45:17 @@ -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 @@ 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 @@ .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 Index: pr/pr.c =================================================================== RCS file: /home/ncvs/src/usr.bin/pr/pr.c,v retrieving revision 1.11 diff -u -r1.11 pr.c --- pr/pr.c 2001/03/21 14:32:02 1.11 +++ pr/pr.c 2002/01/30 08:45:23 @@ -84,6 +84,8 @@ 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,23 @@ } /* + * Write an alert character and wait for a carriage return on /dev/tty. + */ +void +ttypause(void) +{ + int pch; + FILE *ttyfp; + + if ((ttyfp = fopen("/dev/tty", "r")) != NULL) { + (void)putc('\a', stderr); + while ((pch = getc(ttyfp)) != '\n' && pch != EOF) + ; + fclose(ttyfp); + } +} + +/* * onecol: print files with only one column of output. * Line length is unlimited. */ @@ -222,6 +241,10 @@ ips = 0; cps = 0; + if ((pauseall || (pausefst && pagecnt == 1)) && + isatty(STDOUT_FILENO)) + ttypause(); + /* * loop by line */ @@ -410,6 +433,9 @@ * loop by page */ for(;;) { + if ((pauseall || (pausefst && pagecnt == 1)) && + isatty(STDOUT_FILENO)) + ttypause(); /* * loop by column */ @@ -666,6 +692,10 @@ * loop by page */ for(;;) { + if ((pauseall || (pausefst && pagecnt == 1)) && + isatty(STDOUT_FILENO)) + ttypause(); + /* * loop by line */ @@ -856,6 +886,10 @@ * continue to loop while any file still has data */ while (actf > 0) { + if ((pauseall || (pausefst && pagecnt == 1)) && + isatty(STDOUT_FILENO)) + ttypause(); + /* * loop by line */ @@ -1561,7 +1595,8 @@ 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( @@ -1595,7 +1630,7 @@ } } 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) { @@ -1639,6 +1674,9 @@ } else ingap = INGAP; break; + case 'f': + ++pausefst; + /*FALLTHROUGH*/ case 'F': ++formfeed; break; @@ -1703,6 +1741,9 @@ err); return(1); } + break; + case 'p': + ++pauseall; break; case 'r': ++nodiag; --SUOF0GtieIMvvwua-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020130194355.A8993>