diff options
| author | christos <christos@NetBSD.org> | 2013-02-14 14:00:00 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2013-02-14 14:00:00 +0000 |
| commit | 9f68b7d700d81c6641be80f96e6ff09d329c11c8 (patch) | |
| tree | e783001f0b74b35c77bb552a4071fb7c946c8d9a | |
| parent | a5b79c700406d7ac3e608e8f344a9eabbfbe0846 (diff) | |
do the encoding character by character instead of failing on encoding mismatch
| -rw-r--r-- | usr.bin/vis/vis.1 | 7 | ||||
| -rw-r--r-- | usr.bin/vis/vis.c | 30 |
2 files changed, 22 insertions, 15 deletions
diff --git a/usr.bin/vis/vis.1 b/usr.bin/vis/vis.1 index d13df700fd4..1b0b5edf4a8 100644 --- a/usr.bin/vis/vis.1 +++ b/usr.bin/vis/vis.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: vis.1,v 1.16 2013/02/14 08:56:59 wiz Exp $ +.\" $NetBSD: vis.1,v 1.17 2013/02/14 14:00:00 christos Exp $ .\" .\" Copyright (c) 1989, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -149,11 +149,6 @@ must be set to the correct locale or to the C locale. If the locales of the data and the conversion are mismatched, multibyte character recognition may fail and encoding will be performed byte-by-byte instead. -The result of encoding using -.Nm -followed by decoding using -.Xr unvis 3 -is unlikely to return the same input data in this case. .Sh ENVIRONMENT .Bl -tag -width ".Ev LC_CTYPE" .It Ev LC_CTYPE diff --git a/usr.bin/vis/vis.c b/usr.bin/vis/vis.c index 9d8ce1a6690..ded3a04fa5a 100644 --- a/usr.bin/vis/vis.c +++ b/usr.bin/vis/vis.c @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.19 2013/02/13 22:28:41 christos Exp $ */ +/* $NetBSD: vis.c,v 1.20 2013/02/14 14:00:01 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\ #if 0 static char sccsid[] = "@(#)vis.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: vis.c,v 1.19 2013/02/13 22:28:41 christos Exp $"); +__RCSID("$NetBSD: vis.c,v 1.20 2013/02/14 14:00:01 christos Exp $"); #endif /* not lint */ #include <stdio.h> @@ -161,17 +161,21 @@ process(FILE *fp) static char nul[] = "\0"; char *cp = nul + 1; /* so *(cp-1) starts out != '\n' */ wint_t c, c1, rachar; - wchar_t ibuff[3]; /* room for c + rachar + NUL */ char mbibuff[13]; /* ((sizeof(ibuff) - 1) * MB_LEN_MAX) + NUL */ char buff[5]; /* max vis-encoding length for one char + NUL */ + int mbilen, cerr = 0, raerr = 0; c = getwc(fp); - if (c == WEOF && errno == EILSEQ) + if (c == WEOF && errno == EILSEQ) { c = (wint_t)getc(fp); + cerr = 1; + } while (c != WEOF) { rachar = getwc(fp); - if (rachar == WEOF && errno == EILSEQ) + if (rachar == WEOF && errno == EILSEQ) { rachar = (wint_t)getc(fp); + raerr = 1; + } if (none) { cp = buff; *cp++ = c; @@ -189,10 +193,16 @@ process(FILE *fp) c1 = rachar; if (c1 == WEOF) c1 = L'\0'; - swprintf(ibuff, 3, L"%lc%lc", c, c1); - wcstombs(mbibuff, ibuff, - (wcslen(ibuff) * MB_LEN_MAX) + 1); - (void) strsvisx(buff, mbibuff, 1, eflags, extra); + if (cerr) { + *mbibuff = c; + mbilen = 1; + } else + mbilen = wctomb(mbibuff, c); + if (raerr) + mbibuff[mbilen] = c1; + else + wctomb(mbibuff + mbilen, c1); + (void)strsvisx(buff, mbibuff, mbilen, eflags, extra); } cp = buff; @@ -211,6 +221,8 @@ process(FILE *fp) (void)putchar(*cp); } while (*++cp); c = rachar; + cerr = raerr; + raerr = 0; } /* * terminate partial line with a hidden newline |
