Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Mar 2002 13:01:27 +1100 (EST)
From:      "Tim J. Robbins" <tim@robbins.dropbear.id.au>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   standards/36243: pr is missing P1003.1-2001 -f and -p options
Message-ID:  <200203240201.g2O21RG14101@descent.robbins.dropbear.id.au>

next in thread | raw e-mail | index | archive | help

>Number:         36243
>Category:       standards
>Synopsis:       pr is missing P1003.1-2001 -f and -p options
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-standards
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 23 18:10:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Tim J. Robbins
>Release:        FreeBSD 4.5-STABLE i386
>Organization:
>Environment:
System: FreeBSD descent.robbins.dropbear.id.au 4.5-STABLE FreeBSD 4.5-STABLE #17: Thu Mar 21 19:48:18 EST 2002 tim@descent.robbins.dropbear.id.au:/usr/obj/usr/src/sys/DESCENT i386


	
>Description:
P1003.1-2001 specifies the -f and -p options, which are not present
in FreeBSD's pr utility.
>How-To-Repeat:
pr -f
>Fix:

Note: I use ++fooflag instead of fooflag = 1 in the getopt() loop and cast
return value of fclose() and putc() to void for consistency, not because
I think they're correct.

This is a slightly modified version of the patch I posted to freebsd-standards
a few months ago.

Index: pr.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/pr/pr.1,v
retrieving revision 1.17
diff -u -r1.17 pr.1
--- pr.1	2001/09/21 02:57:56	1.17
+++ pr.1	2002/03/24 02:05:07
@@ -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
@@ -373,7 +382,7 @@
 The
 .Nm
 utility is
-.St -p1003.2
+.St -p1003.1-2001
 compatible.
 .Sh HISTORY
 A
Index: pr.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/pr/pr.c,v
retrieving revision 1.12
diff -u -r1.12 pr.c
--- pr.c	2002/02/17 20:53:56	1.12
+++ pr.c	2002/03/24 02:05:10
@@ -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)
+			;
+		(void)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(
@@ -1596,7 +1631,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) {
@@ -1640,6 +1675,9 @@
 			} else
 				ingap = INGAP;
 			break;
+		case 'f':
+			++pausefst;
+			/*FALLTHROUGH*/
 		case 'F':
 			++formfeed;
 			break;
@@ -1704,6 +1742,9 @@
 					err);
 				return(1);
 			}
+			break;
+		case 'p':
+			++pauseall;
 			break;
 		case 'r':
 			++nodiag;
>Release-Note:
>Audit-Trail:
>Unformatted:

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?200203240201.g2O21RG14101>