Add multibyte char support.
PR: 165429 Submitted by: amdmi3
This commit is contained in:
parent
4e2158bf53
commit
586fbee643
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=233269
@ -28,7 +28,7 @@
|
|||||||
.\" @(#)wall.1 8.1 (Berkeley) 6/6/93
|
.\" @(#)wall.1 8.1 (Berkeley) 6/6/93
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 17, 2004
|
.Dd February 24, 2012
|
||||||
.Dt WALL 1
|
.Dt WALL 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -73,7 +73,3 @@ setting is used to determine which characters are safe to write to a
|
|||||||
terminal, not the receiver's (which
|
terminal, not the receiver's (which
|
||||||
.Nm
|
.Nm
|
||||||
has no way of knowing).
|
has no way of knowing).
|
||||||
.Pp
|
|
||||||
The
|
|
||||||
.Nm
|
|
||||||
utility does not recognize multibyte characters.
|
|
||||||
|
@ -62,6 +62,8 @@ static const char sccsid[] = "@(#)wall.c 8.2 (Berkeley) 11/16/93";
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <utmpx.h>
|
#include <utmpx.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <wctype.h>
|
||||||
|
|
||||||
#include "ttymsg.h"
|
#include "ttymsg.h"
|
||||||
|
|
||||||
@ -185,14 +187,15 @@ void
|
|||||||
makemsg(char *fname)
|
makemsg(char *fname)
|
||||||
{
|
{
|
||||||
int cnt;
|
int cnt;
|
||||||
unsigned char ch;
|
wchar_t ch;
|
||||||
struct tm *lt;
|
struct tm *lt;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
time_t now;
|
time_t now;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int fd;
|
int fd;
|
||||||
char *p, hostname[MAXHOSTNAMELEN], lbuf[256], tmpname[64];
|
char hostname[MAXHOSTNAMELEN], tmpname[64];
|
||||||
|
wchar_t *p, *tmp, lbuf[256], codebuf[13];
|
||||||
const char *tty;
|
const char *tty;
|
||||||
const char *whom;
|
const char *whom;
|
||||||
gid_t egid;
|
gid_t egid;
|
||||||
@ -220,78 +223,61 @@ makemsg(char *fname)
|
|||||||
* Which means that we may leave a non-blank character
|
* Which means that we may leave a non-blank character
|
||||||
* in column 80, but that can't be helped.
|
* in column 80, but that can't be helped.
|
||||||
*/
|
*/
|
||||||
(void)fprintf(fp, "\r%79s\r\n", " ");
|
(void)fwprintf(fp, L"\r%79s\r\n", " ");
|
||||||
(void)snprintf(lbuf, sizeof(lbuf),
|
(void)swprintf(lbuf, sizeof(lbuf)/sizeof(wchar_t),
|
||||||
"Broadcast Message from %s@%s",
|
L"Broadcast Message from %s@%s",
|
||||||
whom, hostname);
|
whom, hostname);
|
||||||
(void)fprintf(fp, "%-79.79s\007\007\r\n", lbuf);
|
(void)fwprintf(fp, L"%-79.79S\007\007\r\n", lbuf);
|
||||||
(void)snprintf(lbuf, sizeof(lbuf),
|
(void)swprintf(lbuf, sizeof(lbuf)/sizeof(wchar_t),
|
||||||
" (%s) at %d:%02d %s...", tty,
|
L" (%s) at %d:%02d %s...", tty,
|
||||||
lt->tm_hour, lt->tm_min, lt->tm_zone);
|
lt->tm_hour, lt->tm_min, lt->tm_zone);
|
||||||
(void)fprintf(fp, "%-79.79s\r\n", lbuf);
|
(void)fwprintf(fp, L"%-79.79S\r\n", lbuf);
|
||||||
}
|
}
|
||||||
(void)fprintf(fp, "%79s\r\n", " ");
|
(void)fwprintf(fp, L"%79s\r\n", " ");
|
||||||
|
|
||||||
if (fname) {
|
if (fname) {
|
||||||
egid = getegid();
|
egid = getegid();
|
||||||
setegid(getgid());
|
setegid(getgid());
|
||||||
if (freopen(fname, "r", stdin) == NULL)
|
if (freopen(fname, "r", stdin) == NULL)
|
||||||
err(1, "can't read %s", fname);
|
err(1, "can't read %s", fname);
|
||||||
setegid(egid);
|
setegid(egid);
|
||||||
}
|
}
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
while (fgets(lbuf, sizeof(lbuf), stdin)) {
|
while (fgetws(lbuf, sizeof(lbuf)/sizeof(wchar_t), stdin)) {
|
||||||
for (p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) {
|
for (p = lbuf; (ch = *p) != L'\0'; ++p, ++cnt) {
|
||||||
if (ch == '\r') {
|
if (ch == L'\r') {
|
||||||
putc('\r', fp);
|
putwc(L'\r', fp);
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
continue;
|
continue;
|
||||||
} else if (ch == '\n') {
|
} else if (ch == L'\n') {
|
||||||
for (; cnt < 79; ++cnt)
|
for (; cnt < 79; ++cnt)
|
||||||
putc(' ', fp);
|
putwc(L' ', fp);
|
||||||
putc('\r', fp);
|
putwc(L'\r', fp);
|
||||||
putc('\n', fp);
|
putwc(L'\n', fp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (cnt == 79) {
|
if (cnt == 79) {
|
||||||
putc('\r', fp);
|
putwc(L'\r', fp);
|
||||||
putc('\n', fp);
|
putwc(L'\n', fp);
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
}
|
}
|
||||||
if (((ch & 0x80) && ch < 0xA0) ||
|
if (iswprint(ch) || iswspace(ch) || ch == L'\a' || ch == L'\b') {
|
||||||
/* disable upper controls */
|
putwc(ch, fp);
|
||||||
(!isprint(ch) && !isspace(ch) &&
|
} else {
|
||||||
ch != '\a' && ch != '\b')
|
(void)swprintf(codebuf, sizeof(codebuf)/sizeof(wchar_t), L"<0x%X>", ch);
|
||||||
) {
|
for (tmp = codebuf; *tmp != L'\0'; ++tmp) {
|
||||||
if (ch & 0x80) {
|
putwc(*tmp, fp);
|
||||||
ch &= 0x7F;
|
|
||||||
putc('M', fp);
|
|
||||||
if (++cnt == 79) {
|
if (++cnt == 79) {
|
||||||
putc('\r', fp);
|
putwc(L'\r', fp);
|
||||||
putc('\n', fp);
|
putwc(L'\n', fp);
|
||||||
cnt = 0;
|
|
||||||
}
|
|
||||||
putc('-', fp);
|
|
||||||
if (++cnt == 79) {
|
|
||||||
putc('\r', fp);
|
|
||||||
putc('\n', fp);
|
|
||||||
cnt = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (iscntrl(ch)) {
|
|
||||||
ch ^= 040;
|
|
||||||
putc('^', fp);
|
|
||||||
if (++cnt == 79) {
|
|
||||||
putc('\r', fp);
|
|
||||||
putc('\n', fp);
|
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
--cnt;
|
||||||
}
|
}
|
||||||
putc(ch, fp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(void)fprintf(fp, "%79s\r\n", " ");
|
(void)fwprintf(fp, L"%79s\r\n", " ");
|
||||||
rewind(fp);
|
rewind(fp);
|
||||||
|
|
||||||
if (fstat(fd, &sbuf))
|
if (fstat(fd, &sbuf))
|
||||||
|
Loading…
Reference in New Issue
Block a user