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)
This commit is contained in:
David Schultz 2008-01-15 07:40:30 +00:00
parent 00a32d0ca9
commit 3c58f6ddbd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=175346

View File

@ -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);