From 3c58f6ddbdbd50799590aa5ac8ae1909140d52c8 Mon Sep 17 00:00:00 2001 From: David Schultz Date: Tue, 15 Jan 2008 07:40:30 +0000 Subject: [PATCH] Fix some bugs in wall(1): - 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. - Style: Braces around compound while statement. PR: 114498 Submitted by: Niclas Zeising (earlier version) --- usr.bin/wall/wall.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/usr.bin/wall/wall.c b/usr.bin/wall/wall.c index 1a1d2a383732..be5329aca566 100644 --- a/usr.bin/wall/wall.c +++ b/usr.bin/wall/wall.c @@ -251,17 +251,25 @@ makemsg(char *fname) err(1, "can't read %s", fname); setegid(egid); } - while (fgets(lbuf, sizeof(lbuf), stdin)) + while (fgets(lbuf, sizeof(lbuf), stdin)) { for (cnt = 0, 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 +298,10 @@ makemsg(char *fname) cnt = 0; } } - putc(ch, fp); - } else { - putc(ch, fp); } + putc(ch, fp); } + } (void)fprintf(fp, "%79s\r\n", " "); rewind(fp);