Nikita V. Youshchenko wrote:

Hi,

>  - why SLsmg_write_char() puts garbage into buffer when gets (whar_t)1040?
> 

I asked google about the SLsmg_write_char function and it seems the
first link it returns,
http://mail.gnome.org/archives/mc-devel/2006-June/msg00020.html,
contains a fix for the bug. At least it works for me, so I'm attaching a
 patch from the above page, slightly adjusted for the current Debian
package.

Best Regards,
robert


diff -Nur mc-4.6.1/edit/editdraw.c mc-4.6.1.new/edit/editdraw.c
--- mc-4.6.1/edit/editdraw.c	2006-06-23 23:11:15.000000000 +0200
+++ mc-4.6.1.new/edit/editdraw.c	2006-06-23 23:11:46.000000000 +0200
@@ -239,7 +239,7 @@
 	    lowlevel_set_color (color);
 	}
 #ifdef UTF8
-	SLsmg_write_char(textchar);
+	SLsmg_write_nwchars(&textchar, 1);
 #else
 	addch (textchar);
 #endif
diff -Nur mc-4.6.1/src/help.c mc-4.6.1.new/src/help.c
--- mc-4.6.1/src/help.c	2006-06-23 23:11:15.000000000 +0200
+++ mc-4.6.1.new/src/help.c	2006-06-23 23:11:46.000000000 +0200
@@ -461,7 +461,7 @@
 		    len = mbrtowc(&wc, p, MB_CUR_MAX, &mbs);
 		    if (len <= 0) len = 1; /* skip broken multibyte chars */
 
-            	    SLsmg_write_char(wc);
+            	    SLsmg_write_nwchars(&wc, 1);
 		    p += len - 1;
 		} else
 #endif
diff -Nur mc-4.6.1/src/util.c mc-4.6.1.new/src/util.c
--- mc-4.6.1/src/util.c	2006-06-23 23:11:15.000000000 +0200
+++ mc-4.6.1.new/src/util.c	2006-06-23 23:12:51.000000000 +0200
@@ -59,8 +59,26 @@
 #if SLANG_VERSION >= 20000
 void SLsmg_write_nwchars(wchar_t *s, size_t n)
 {
- while(n--)
-    SLsmg_write_char(*s++);
+     if (SLsmg_is_utf8_mode()) { /* slang can handle it directly */
+ 	while(n-- && *s)
+ 	    SLsmg_write_char(*s++);
+     }
+     else { /* convert wchars back to 8bit encoding */
+         mbstate_t mbs;
+ 	memset (&mbs, 0, sizeof (mbs));
+ 	while (n-- && *s) {
+ 	    char buf[MB_LEN_MAX + 1]; /* should use 1 char, but to be sure */
+ 	    if (*s < 0x80) {
+ 		SLsmg_write_char(*s++); /* ASCII */
+ 	    }
+ 	    else {
+ 		if (wcrtomb(buf, *s++, &mbs) == 1)
+ 		    SLsmg_write_char((wchar_t)(buf[0]));
+ 		else
+ 		    SLsmg_write_char('?'); /* should not happen */
+ 	    }
+ 	} 
+     }
 }
 #endif
 
diff -Nur mc-4.6.1/src/view.c mc-4.6.1.new/src/view.c
--- mc-4.6.1/src/view.c	2006-06-23 23:11:15.000000000 +0200
+++ mc-4.6.1.new/src/view.c	2006-06-23 23:11:46.000000000 +0200
@@ -856,7 +856,7 @@
 #ifndef UTF8
 #define view_add_character(view,c) addch (c)
 #else /* UTF8 */
-#define view_add_character(view,c) SLsmg_write_char(c)
+#define view_add_character(view,c) {wchar_t tmp=c; SLsmg_write_nwchars(&tmp, 1);}
 #endif /* UTF8 */
 #define view_add_one_vline()       one_vline()
 #define view_add_string(view,s)    addstr (s)

Reply via email to