diff options
author | ache <ache@FreeBSD.org> | 1997-09-15 01:03:16 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1997-09-15 01:03:16 +0000 |
commit | be830b8d98bb3ad060dafa3a07bcd60a800bd7e1 (patch) | |
tree | 9cc7347177a002b12647504b8e617c85e7c3b2bf /usr.bin | |
parent | 2b00c45114fc897afa8e0e7e974b0da6ac989e72 (diff) | |
download | FreeBSD-src-be830b8d98bb3ad060dafa3a07bcd60a800bd7e1.zip FreeBSD-src-be830b8d98bb3ad060dafa3a07bcd60a800bd7e1.tar.gz |
Change manual declarations of some functions to proper includes
Rewrote allowed character test to be more efficient
Fix screen position calculations: control and 8bit characters was
not counted properly
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/wall/wall.c | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/usr.bin/wall/wall.c b/usr.bin/wall/wall.c index a079b97..04a4823 100644 --- a/usr.bin/wall/wall.c +++ b/usr.bin/wall/wall.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)wall.c 8.2 (Berkeley) 11/16/93"; #endif static const char rcsid[] = - "$Id$"; + "$Id: wall.c,v 1.8 1997/08/25 06:43:22 charnier Exp $"; #endif /* not lint */ /* @@ -52,7 +52,6 @@ static const char rcsid[] = #include <sys/param.h> #include <sys/stat.h> -#include <sys/time.h> #include <sys/uio.h> #include <ctype.h> @@ -63,6 +62,7 @@ static const char rcsid[] = #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> #include <utmp.h> @@ -141,11 +141,10 @@ makemsg(fname) struct tm *lt; struct passwd *pw; struct stat sbuf; - time_t now, time(); + time_t now; FILE *fp; int fd; char *p, *whom, hostname[MAXHOSTNAMELEN], lbuf[100], tmpname[15]; - char *getlogin(), *strcpy(), *ttyname(); (void)strcpy(tmpname, _PATH_TMP); (void)strcat(tmpname, "/wall.XXXXXX"); @@ -181,27 +180,43 @@ makemsg(fname) errx(1, "can't read %s", fname); while (fgets(lbuf, sizeof(lbuf), stdin)) for (cnt = 0, p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) { - again: if (cnt == 79 || ch == '\n') { for (; cnt < 79; ++cnt) putc(' ', fp); putc('\r', fp); putc('\n', fp); cnt = 0; - } else if ( ( (ch & 0x7F) < ' ' /* locale-independent */ - || (!isprint(ch) && !isspace(ch)) - ) - && strchr("\a\f\t\v\b\r\n", ch) == NULL + } else if (((ch & 0x80) && ch < 0xA0) || + /* disable upper controls */ + (!isprint(ch) && !isspace(ch) && + ch != '\a' && ch != '\b') ) { if (ch & 0x80) { ch &= 0x7F; - (void)fprintf(fp, "M-"); - goto again; + putc('M', fp); + if (++cnt == 79) { + putc('\r', fp); + putc('\n', fp); + cnt = 0; + } + putc('-', fp); + if (++cnt == 79) { + putc('\r', fp); + putc('\n', fp); + cnt = 0; + } } - putc('^', fp); - putc(ch^0x40, fp); /* DEL to ?, others to alpha */ - } else - putc(ch, fp); + if (iscntrl(ch)) { + ch ^= 040; + putc('^', fp); + if (++cnt == 79) { + putc('\r', fp); + putc('\n', fp); + cnt = 0; + } + } + } + putc(ch, fp); } (void)fprintf(fp, "%79s\r\n", " "); rewind(fp); |