Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: self-insert with bad multibyte input



Playing around with the Solaris problems, I noticed that handling
of bad character input is poor.  selfinsert() tries to grab the rest of
a wide character.  It assumes, quite reasonably, that we already have
something to insert because it only gets called with real input,
although that may be an incomplete character.  However, we currently set
the wide character to WEOF in this case, which self-insert inserts; this
isn't a very good solution.  This patch checks for the return value when
reading the key and beeps when necessary.  It doesn't fix the problems
inputting multibyte characters, but it prevents any consequent problems.

Multibyte editing appears to be OK on the Solaris 8 systems here as long
as the characters don't come from the keyboard: this is basically
consistent with the problem I was seeing before.

Index: Src/Zle/zle_hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_hist.c,v
retrieving revision 1.33
diff -u -r1.33 zle_hist.c
--- Src/Zle/zle_hist.c	12 Dec 2005 18:35:47 -0000	1.33
+++ Src/Zle/zle_hist.c	6 Jan 2006 14:01:33 -0000
@@ -1107,7 +1107,10 @@
 	    } else if (cmd == Th(z_selfinsert)) {
 #ifdef MULTIBYTE_SUPPORT
 		if (!lastchar_wide_valid)
-		    getrestchar(lastchar);
+		    if (getrestchar(lastchar) == WEOF) {
+			handlefeep(zlenoargs);
+			continue;
+		    }
 #else
 		;
 #endif
@@ -1303,7 +1306,10 @@
 	    } else {
 #ifdef MULTIBYTE_SUPPORT
 		if (!lastchar_wide_valid)
-		    getrestchar(lastchar);
+		    if (getrestchar(lastchar) == WEOF) {
+			handlefeep(zlenoargs);
+			continue;
+		    }
 #else
 		;
 #endif
Index: Src/Zle/zle_misc.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_misc.c,v
retrieving revision 1.38
diff -u -r1.38 zle_misc.c
--- Src/Zle/zle_misc.c	30 Nov 2005 16:49:44 -0000	1.38
+++ Src/Zle/zle_misc.c	6 Jan 2006 14:01:36 -0000
@@ -64,7 +64,8 @@
 
 #ifdef MULTIBYTE_SUPPORT
     if (!lastchar_wide_valid)
-	getrestchar(lastchar);
+	if (getrestchar(lastchar) == WEOF)
+	    return 1;
 #endif
     tmp = LASTFULLCHAR;
     doinsert(&tmp, 1);
@@ -1018,6 +1019,9 @@
 #ifdef MULTIBYTE_SUPPORT
 		    if (!lastchar_wide_valid)
 			getrestchar(lastchar);
+		    if (lastchar_wide == WEOF)
+			feep = 1;
+		    else
 #endif
 		    if (ZC_icntrl(LASTFULLCHAR))
 			feep = 1;

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


Your mail client is unable to display the latest news from CSR. To access our news copy this link into a web browser:  http://www.csr.com/email_sig.html



Messages sorted by: Reverse Date, Date, Thread, Author