summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2008-01-15 07:40:30 +0000
committerdas <das@FreeBSD.org>2008-01-15 07:40:30 +0000
commit409fbbd08fad855cfd3efaab185d2f4091e931f9 (patch)
treeedbd340be87137a8910327db7ba6fb8a17dd18f2 /usr.bin
parentc41cd4bf35f4da7e4e9e2f36779c90ddbc25640b (diff)
downloadFreeBSD-src-409fbbd08fad855cfd3efaab185d2f4091e931f9.zip
FreeBSD-src-409fbbd08fad855cfd3efaab185d2f4091e931f9.tar.gz
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 <niclas.zeising@gmail.com> (earlier version)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/wall/wall.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/usr.bin/wall/wall.c b/usr.bin/wall/wall.c
index 1a1d2a3..be5329a 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);
OpenPOWER on IntegriCloud