svn commit: r223970 - stable/7/usr.bin/wall

David E. O'Brien obrien at FreeBSD.org
Tue Jul 12 23:48:58 UTC 2011


Author: obrien
Date: Tue Jul 12 23:48:57 2011
New Revision: 223970
URL: http://svn.freebsd.org/changeset/base/223970

Log:
  MFC:
  + r223940 (as r223969): If one's message is longer than the buffer size,
  then we reset 'cnt' at the wrong point and the actual column # get out of
  sync across the buffer size.
  + r175346: Handle wrapping correctly when \r appears in the input,
  and don't remove the \r from the output.  For lines longer than 79
  characters, don't drop every 80th character.

Modified:
  stable/7/usr.bin/wall/wall.c
Directory Properties:
  stable/7/usr.bin/wall/   (props changed)

Modified: stable/7/usr.bin/wall/wall.c
==============================================================================
--- stable/7/usr.bin/wall/wall.c	Tue Jul 12 23:39:56 2011	(r223969)
+++ stable/7/usr.bin/wall/wall.c	Tue Jul 12 23:48:57 2011	(r223970)
@@ -251,17 +251,26 @@ makemsg(char *fname)
 			err(1, "can't read %s", fname);
 		setegid(egid);
 	}
-	while (fgets(lbuf, sizeof(lbuf), stdin))
-		for (cnt = 0, p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) {
+	cnt = 0;
+	while (fgets(lbuf, sizeof(lbuf), stdin)) {
+		for (p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) {
 			if (ch == '\r') {
+				putc('\r', fp);
 				cnt = 0;
-			} else if (cnt == 79 || ch == '\n') {
+				continue;
+			} else if (ch == '\n') {
 				for (; cnt < 79; ++cnt)
 					putc(' ', fp);
 				putc('\r', fp);
 				putc('\n', fp);
+				break;
+			}
+			if (cnt == 79) {
+				putc('\r', fp);
+				putc('\n', fp);
 				cnt = 0;
-			} else if (((ch & 0x80) && ch < 0xA0) ||
+			}
+			if (((ch & 0x80) && ch < 0xA0) ||
 				   /* disable upper controls */
 				   (!isprint(ch) && !isspace(ch) &&
 				    ch != '\a' && ch != '\b')
@@ -290,11 +299,10 @@ makemsg(char *fname)
 						cnt = 0;
 					}
 				}
-				putc(ch, fp);
-			} else {
-				putc(ch, fp);
 			}
+			putc(ch, fp);
 		}
+	}
 	(void)fprintf(fp, "%79s\r\n", " ");
 	rewind(fp);
 


More information about the svn-src-stable-7 mailing list