From owner-svn-src-all@FreeBSD.ORG Wed Mar 21 08:03:07 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BCE96106566C; Wed, 21 Mar 2012 08:03:07 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A87088FC14; Wed, 21 Mar 2012 08:03:07 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q2L837Kr061040; Wed, 21 Mar 2012 08:03:07 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q2L8374f061037; Wed, 21 Mar 2012 08:03:07 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201203210803.q2L8374f061037@svn.freebsd.org> From: Gleb Smirnoff Date: Wed, 21 Mar 2012 08:03:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r233269 - head/usr.bin/wall X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Mar 2012 08:03:07 -0000 Author: glebius Date: Wed Mar 21 08:03:07 2012 New Revision: 233269 URL: http://svn.freebsd.org/changeset/base/233269 Log: Add multibyte char support. PR: 165429 Submitted by: amdmi3 Modified: head/usr.bin/wall/wall.1 head/usr.bin/wall/wall.c Modified: head/usr.bin/wall/wall.1 ============================================================================== --- head/usr.bin/wall/wall.1 Wed Mar 21 07:49:13 2012 (r233268) +++ head/usr.bin/wall/wall.1 Wed Mar 21 08:03:07 2012 (r233269) @@ -28,7 +28,7 @@ .\" @(#)wall.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd July 17, 2004 +.Dd February 24, 2012 .Dt WALL 1 .Os .Sh NAME @@ -73,7 +73,3 @@ setting is used to determine which chara terminal, not the receiver's (which .Nm has no way of knowing). -.Pp -The -.Nm -utility does not recognize multibyte characters. Modified: head/usr.bin/wall/wall.c ============================================================================== --- head/usr.bin/wall/wall.c Wed Mar 21 07:49:13 2012 (r233268) +++ head/usr.bin/wall/wall.c Wed Mar 21 08:03:07 2012 (r233269) @@ -62,6 +62,8 @@ static const char sccsid[] = "@(#)wall.c #include #include #include +#include +#include #include "ttymsg.h" @@ -185,14 +187,15 @@ void makemsg(char *fname) { int cnt; - unsigned char ch; + wchar_t ch; struct tm *lt; struct passwd *pw; struct stat sbuf; time_t now; FILE *fp; 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 *whom; gid_t egid; @@ -220,78 +223,61 @@ makemsg(char *fname) * Which means that we may leave a non-blank character * in column 80, but that can't be helped. */ - (void)fprintf(fp, "\r%79s\r\n", " "); - (void)snprintf(lbuf, sizeof(lbuf), - "Broadcast Message from %s@%s", + (void)fwprintf(fp, L"\r%79s\r\n", " "); + (void)swprintf(lbuf, sizeof(lbuf)/sizeof(wchar_t), + L"Broadcast Message from %s@%s", whom, hostname); - (void)fprintf(fp, "%-79.79s\007\007\r\n", lbuf); - (void)snprintf(lbuf, sizeof(lbuf), - " (%s) at %d:%02d %s...", tty, + (void)fwprintf(fp, L"%-79.79S\007\007\r\n", lbuf); + (void)swprintf(lbuf, sizeof(lbuf)/sizeof(wchar_t), + L" (%s) at %d:%02d %s...", tty, 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) { egid = getegid(); setegid(getgid()); - if (freopen(fname, "r", stdin) == NULL) + if (freopen(fname, "r", stdin) == NULL) err(1, "can't read %s", fname); setegid(egid); } cnt = 0; - while (fgets(lbuf, sizeof(lbuf), stdin)) { - for (p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) { - if (ch == '\r') { - putc('\r', fp); + while (fgetws(lbuf, sizeof(lbuf)/sizeof(wchar_t), stdin)) { + for (p = lbuf; (ch = *p) != L'\0'; ++p, ++cnt) { + if (ch == L'\r') { + putwc(L'\r', fp); cnt = 0; continue; - } else if (ch == '\n') { + } else if (ch == L'\n') { for (; cnt < 79; ++cnt) - putc(' ', fp); - putc('\r', fp); - putc('\n', fp); + putwc(L' ', fp); + putwc(L'\r', fp); + putwc(L'\n', fp); break; } if (cnt == 79) { - putc('\r', fp); - putc('\n', fp); + putwc(L'\r', fp); + putwc(L'\n', fp); cnt = 0; } - if (((ch & 0x80) && ch < 0xA0) || - /* disable upper controls */ - (!isprint(ch) && !isspace(ch) && - ch != '\a' && ch != '\b') - ) { - if (ch & 0x80) { - ch &= 0x7F; - putc('M', fp); + if (iswprint(ch) || iswspace(ch) || ch == L'\a' || ch == L'\b') { + putwc(ch, fp); + } else { + (void)swprintf(codebuf, sizeof(codebuf)/sizeof(wchar_t), L"<0x%X>", ch); + for (tmp = codebuf; *tmp != L'\0'; ++tmp) { + putwc(*tmp, 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; - } - } - if (iscntrl(ch)) { - ch ^= 040; - putc('^', fp); - if (++cnt == 79) { - putc('\r', fp); - putc('\n', fp); + putwc(L'\r', fp); + putwc(L'\n', fp); cnt = 0; } } + --cnt; } - putc(ch, fp); } } - (void)fprintf(fp, "%79s\r\n", " "); + (void)fwprintf(fp, L"%79s\r\n", " "); rewind(fp); if (fstat(fd, &sbuf))