Module Name:    src
Committed By:   christos
Date:           Thu Feb 14 14:00:01 UTC 2013

Modified Files:
        src/usr.bin/vis: vis.1 vis.c

Log Message:
do the encoding character by character instead of failing on encoding mismatch


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/vis/vis.1
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/vis/vis.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/vis/vis.1
diff -u src/usr.bin/vis/vis.1:1.16 src/usr.bin/vis/vis.1:1.17
--- src/usr.bin/vis/vis.1:1.16	Thu Feb 14 03:56:59 2013
+++ src/usr.bin/vis/vis.1	Thu Feb 14 09:00:00 2013
@@ -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 
 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

Index: src/usr.bin/vis/vis.c
diff -u src/usr.bin/vis/vis.c:1.19 src/usr.bin/vis/vis.c:1.20
--- src/usr.bin/vis/vis.c:1.19	Wed Feb 13 17:28:41 2013
+++ src/usr.bin/vis/vis.c	Thu Feb 14 09:00:01 2013
@@ -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, 19
 #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

Reply via email to