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

Bug#404503: Wrong characters typed using dead keys



reassign 404503 kbd
clone 404503 -1
reassign -1 console-tools
thanks

Pavel Vávra, le Fri 17 Oct 2008 23:18:14 +0200, a écrit :
> (1) unmaintained console-tools exist in lenny and this package is installed by default

And kbd doesn't yet include the patch anyway...
http://bugzilla.kernel.org/attachment.cgi?id=12359

Attached is a console-tools port of the patch, could you please check
that it works?  You should just need to

$ apt-get source console-tools
$ sudo apt-get build-dep console-tools
$ cd console-tools-version
$ ./debian/rules stampdir/patchapply
$ (cd build-tree/console-tools-version ; patch -p1 < ~/patch-console-tools)
$ fakeroot ./debian/rules binary-arch

and install console-tools_version_arch.deb

Samuel
diff -ur console-tools-0.2.3-orig/include/lct/ksyms.h console-tools-0.2.3/include/lct/ksyms.h
--- console-tools-0.2.3-orig/include/lct/ksyms.h	2008-12-01 23:48:27.000000000 +0100
+++ console-tools-0.2.3/include/lct/ksyms.h	2008-12-01 23:54:50.000000000 +0100
@@ -21,6 +21,7 @@
 extern const int charsets_size;
 
 extern int set_charset(const char *name);
+extern const char *chosen_charset;
 extern int add_number(int code);
 extern int add_capslock(int code);
 extern const char *codetoksym(int code);
diff -ur console-tools-0.2.3-orig/kbdtools/loadkeys.y console-tools-0.2.3/kbdtools/loadkeys.y
--- console-tools-0.2.3-orig/kbdtools/loadkeys.y	2008-12-01 23:48:27.000000000 +0100
+++ console-tools-0.2.3/kbdtools/loadkeys.y	2008-12-01 23:56:36.000000000 +0100
@@ -70,6 +70,7 @@
 #include <linux/keyboard.h>
 #include <sys/ioctl.h>
 #include <ctype.h>
+#include <iconv.h>
 #include <sysexits.h>
 #include <signal.h>
 
@@ -111,7 +112,11 @@
 /* the kernel structures we want to set or print */
 u_short *key_map[MAX_NR_KEYMAPS];
 char *func_table[MAX_NR_FUNC];
+#ifdef KDSKBDIACRUC
+struct kbdiacruc accent_table[MAX_DIACR];
+#else
 struct kbdiacr accent_table[MAX_DIACR];
+#endif
 unsigned int accent_table_size = 0;
 
 char key_is_constant[512]; // 512 == Max. value of NR_KEYS across kernels  <= 2.6.1
@@ -692,7 +697,7 @@
      
 static void compose(int diacr, int base, int res)
 {
-  struct kbdiacr *p;
+  typeof(*accent_table) *p;
   if (accent_table_size == MAX_DIACR)
     {
       fprintf(stderr, _("compose table overflow\n"));
@@ -860,11 +865,80 @@
   return ct;
 }
 
+#ifdef KDSKBDIACRUC
+static wchar_t convert_char(iconv_t conv, unsigned char c) {
+	wchar_t wc;
+	char *i = (void*)&c;
+	size_t is = sizeof(c);
+	char *o = (void*)&wc;
+	size_t os = sizeof(wc);
+	if (iconv(conv, &i, &is, &o, &os) == (size_t) -1) {
+	    perror("iconv");
+	    fprintf(stderr, _("Couldn't convert character %u from charset %s to unicode\n"), c, chosen_charset);
+	    wc = 0;
+	}
+	return wc;
+}
+static int
+defdiacsuc(int fd){
+        struct kbdiacrsuc kd;
+	int i;
+	iconv_t conv;
+
+	if (!chosen_charset)
+	    return 0;
+
+	kd.kb_cnt = accent_table_size;
+	if (kd.kb_cnt > MAX_DIACR) {
+	    kd.kb_cnt = MAX_DIACR;
+	    fprintf(stderr, _("too many compose definitions\n"));
+	}
+	conv = iconv_open("WCHAR_T", chosen_charset);
+	if (conv == (iconv_t)(-1)) {
+	    perror("iconv_open");
+	    fprintf(stderr, _("Can't convert from charset %s to unicode\n"), chosen_charset);
+	    return 0;
+	}
+	for (i = 0; i < kd.kb_cnt; i++) {
+	    wchar_t wc;
+	    wc = convert_char(conv, accent_table[i].diacr);
+	    if (!wc)
+		goto err;
+	    kd.kbdiacruc[i].diacr = wc;
+	    wc = convert_char(conv, accent_table[i].base);
+	    if (!wc)
+		goto err;
+	    kd.kbdiacruc[i].base = wc;
+	    wc = convert_char(conv, accent_table[i].result);
+	    if (!wc)
+		goto err;
+	    kd.kbdiacruc[i].result = wc;
+	}
+
+	if(ioctl(fd, KDSKBDIACRUC, (unsigned long) &kd)) {
+	    if (errno == EINVAL)
+		return 0;
+	    perror("KDSKBDIACR");
+	    exit(1);
+	}
+	return kd.kb_cnt;
+err:
+	iconv_close(conv);
+	return 0;
+}
+
+#endif
 static int defdiacs(int fd)
 {
   struct kbdiacrs kd;
   unsigned i;
 
+#ifdef KDSKBDIACRUC
+  int cnt = defdiacsuc(fd);
+  if (cnt)
+    return cnt;
+#endif
+
   kd.kb_cnt = accent_table_size;
   if (kd.kb_cnt > MAX_DIACR) 
     {
@@ -872,7 +946,11 @@
       fprintf(stderr, _("too many compose definitions\n"));
     }
   for (i = 0; i < kd.kb_cnt; i++)
-      kd.kbdiacr[i] = accent_table[i];
+    {
+      kd.kbdiacr[i].diacr = accent_table[i].diacr;
+      kd.kbdiacr[i].base = accent_table[i].base;
+      kd.kbdiacr[i].result = accent_table[i].result;
+    }
   
   if(ioctl(fd, KDSKBDIACR, (unsigned long) &kd)) 
     {
diff -ur console-tools-0.2.3-orig/lib/ksyms.c console-tools-0.2.3/lib/ksyms.c
--- console-tools-0.2.3-orig/lib/ksyms.c	2008-12-01 23:48:27.000000000 +0100
+++ console-tools-0.2.3/lib/ksyms.c	2008-12-01 23:53:43.000000000 +0100
@@ -1647,6 +1647,7 @@
 /* Functions for both dumpkeys and loadkeys. */
 
 static int prefer_unicode = 0;
+const char *chosen_charset = NULL;
 
 void
 list_charsets(FILE *f) {
@@ -1700,6 +1701,7 @@
 				if(p->name[0])
 					syms[0].table[i] = p->name;
 			}
+			chosen_charset = strdup(charset);
 			return 0;
 		}
 	}

Reply to: