Re: utf8 patch for mc, slang 2 version



On Saturday 12 November 2005 20:59, Leonard den Ottolander wrote:
> Hi Bart, list,
>
> On Tue, 2005-09-20 at 08:14 +1200, Bart Oldeman wrote:
> > Basically you'd need to apply Fedora's patch, and then (sorry no proper
> > patch here but it's not a big deal)
>
> Attached you'll find a proper patch. I've moved the hunk from global.h
> to myslang.h (and dropped the inclusion of slang.h as it is redundant).
>
> Jindrich, please merge this patch with the UTF8 patch. You might even
> consider to build the next mc for FC --with-screen=mcslang, as I see the
> FC development tree does not yet feature slang-2.
>
Hi all,

In non-UTF-8 mode slang2 behaves a bit different than the patched slang1.
As a result, mc does work with 8bit encodings, like 8859-2 or KOI8.
The attached patch fixes the SLsmg_write_nwchars() function to be fully
compatible with the slang1 version and uses it consistently instead of
SLsmg_write_char(). It should be applied on top of all the previous patches.


-- 
Vladimir Nadvornik
developer
---------------------------------------------------------------------  
SuSE CR, s.r.o.                             e-mail: nadvornik suse cz
Drahobejlova 27                             tel:+420 2 9654 2373 
190 00 Praha 9                              fax:+420 2 9654 2374   
Ceska republika                             http://www.suse.cz    
diff -ruN mc-4.6.1.orig/edit/editdraw.c mc-4.6.1/edit/editdraw.c
--- mc-4.6.1.orig/edit/editdraw.c	2006-06-07 11:57:19.000000000 +0200
+++ mc-4.6.1/edit/editdraw.c	2006-06-07 11:56:30.000000000 +0200
@@ -234,7 +234,7 @@
 	    lowlevel_set_color (color);
 	}
 #ifdef UTF8
-	SLsmg_write_char(textchar);
+	SLsmg_write_nwchars(&textchar, 1);
 #else
 	addch (textchar);
 #endif
diff -ruN mc-4.6.1.orig/src/help.c mc-4.6.1/src/help.c
--- mc-4.6.1.orig/src/help.c	2006-06-07 11:57:19.000000000 +0200
+++ mc-4.6.1/src/help.c	2006-06-07 11:56:30.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 -ruN mc-4.6.1.orig/src/util.c mc-4.6.1/src/util.c
--- mc-4.6.1.orig/src/util.c	2006-06-07 11:57:19.000000000 +0200
+++ mc-4.6.1/src/util.c	2006-06-07 11:56:30.000000000 +0200
@@ -58,8 +58,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 -ruN mc-4.6.1.orig/src/view.c mc-4.6.1/src/view.c
--- mc-4.6.1.orig/src/view.c	2006-06-07 11:57:19.000000000 +0200
+++ mc-4.6.1/src/view.c	2006-06-07 11:56:30.000000000 +0200
@@ -852,7 +852,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)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]