From owner-svn-src-all@FreeBSD.ORG Mon Feb 13 14:40:15 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CE669106566B; Mon, 13 Feb 2012 14:40:15 +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 B25008FC13; Mon, 13 Feb 2012 14:40:15 +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 q1DEeFVS046755; Mon, 13 Feb 2012 14:40:15 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q1DEeFmH046752; Mon, 13 Feb 2012 14:40:15 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201202131440.q1DEeFmH046752@svn.freebsd.org> From: Gleb Smirnoff Date: Mon, 13 Feb 2012 14:40:15 +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: r231586 - head/usr.bin/write 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: Mon, 13 Feb 2012 14:40:16 -0000 Author: glebius Date: Mon Feb 13 14:40:15 2012 New Revision: 231586 URL: http://svn.freebsd.org/changeset/base/231586 Log: Fix write(1) to support wide characters. Submitted by: amdmi3 PR: bin/164317 Modified: head/usr.bin/write/write.1 head/usr.bin/write/write.c Modified: head/usr.bin/write/write.1 ============================================================================== --- head/usr.bin/write/write.1 Mon Feb 13 13:07:56 2012 (r231585) +++ head/usr.bin/write/write.1 Mon Feb 13 14:40:15 2012 (r231586) @@ -31,7 +31,7 @@ .\" @(#)write.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd July 17, 2004 +.Dd February 13, 2012 .Dt WRITE 1 .Os .Sh NAME @@ -107,7 +107,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/write/write.c ============================================================================== --- head/usr.bin/write/write.c Mon Feb 13 13:07:56 2012 (r231585) +++ head/usr.bin/write/write.c Mon Feb 13 14:40:15 2012 (r231586) @@ -60,12 +60,14 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include void done(int); void do_write(char *, char *, uid_t); static void usage(void); int term_chk(char *, int *, time_t *, int); -void wr_fputs(unsigned char *s); +void wr_fputs(wchar_t *s); void search_utmp(char *, char *, char *, uid_t); int utmp_chk(char *, char *); @@ -243,7 +245,8 @@ do_write(char *tty, char *mytty, uid_t m char *nows; struct passwd *pwd; time_t now; - char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512]; + char path[MAXPATHLEN], host[MAXHOSTNAMELEN]; + wchar_t line[512]; /* Determine our login name before we reopen() stdout */ if ((login = getlogin()) == NULL) { @@ -269,7 +272,7 @@ do_write(char *tty, char *mytty, uid_t m (void)printf("\r\n\007\007\007Message from %s@%s on %s at %s ...\r\n", login, host, mytty, nows + 11); - while (fgets(line, sizeof(line), stdin) != NULL) + while (fgetws(line, sizeof(line)/sizeof(wchar_t), stdin) != NULL) wr_fputs(line); } @@ -288,30 +291,20 @@ done(int n __unused) * turns \n into \r\n */ void -wr_fputs(unsigned char *s) +wr_fputs(wchar_t *s) { -#define PUTC(c) if (putchar(c) == EOF) err(1, NULL); +#define PUTC(c) if (putwchar(c) == WEOF) err(1, NULL); - for (; *s != '\0'; ++s) { - if (*s == '\n') { - PUTC('\r'); - } else if (((*s & 0x80) && *s < 0xA0) || - /* disable upper controls */ - (!isprint(*s) && !isspace(*s) && - *s != '\a' && *s != '\b') - ) { - if (*s & 0x80) { - *s &= ~0x80; - PUTC('M'); - PUTC('-'); - } - if (iscntrl(*s)) { - *s ^= 0x40; - PUTC('^'); - } + for (; *s != L'\0'; ++s) { + if (*s == L'\n') { + PUTC(L'\r'); + PUTC(L'\n'); + } else if (iswprint(*s) || iswspace(*s)) { + PUTC(*s); + } else { + wprintf(L"<0x%X>", *s); } - PUTC(*s); } return; #undef PUTC