[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][TOP]
KDE menu patch
たごうです.
KDE 2.0などのUTF-8なメニューをGNOMEでちゃんと表示できるように
するためのパッチです.
--
Akira TAGOH :: at@xxxxxxxxx
tagoh@xxxxxxxxxxx / Japan GNOME Users Group
tagoh@xxxxxxxxxxxx / GNOME-DB Project
tagoh@xxxxxxxxxx / Red Hat, Inc.
diff -ruN gnome-libs-1.2.8.orig/libgnome/gnome-dentry.c gnome-libs-1.2.8/libgnome/gnome-dentry.c
--- gnome-libs-1.2.8.orig/libgnome/gnome-dentry.c Mon Jan 29 01:25:07 2001
+++ gnome-libs-1.2.8/libgnome/gnome-dentry.c Mon Jan 29 04:17:12 2001
@@ -13,6 +13,9 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <locale.h>
+#include <iconv.h>
+#include <langinfo.h>
#include "gnome-defs.h"
#include "gnome-util.h"
#include "gnome-config.h"
@@ -193,7 +196,9 @@
newitem = g_new0 (GnomeDesktopEntry, 1);
newitem->name = name;
+ utf8tolocalechar (&newitem->name);
newitem->comment = gnome_config_get_translated_string ("Comment");
+ utf8tolocalechar (&newitem->comment);
newitem->exec_length = exec_length;
newitem->exec = exec_vector;
newitem->tryexec = try_file;
@@ -784,4 +789,130 @@
g_free(e);
}
if(list) g_list_free(list);
+}
+
+#define F 0 /* character never appears in text */
+#define T 1 /* character appears in plain ASCII text */
+#define I 2 /* character appears in ISO-8859 text */
+#define X 3 /* character appears in non-ISO extended ASCII (Mac, IBM PC) */
+
+static char text_chars[256] = {
+ /* BEL BS HT LF FF CR */
+ F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F, /* 0x0X */
+ /* ESC */
+ F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F, /* 0x1X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x2X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x3X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x4X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x5X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x6X */
+ T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, F, /* 0x7X */
+ /* NEL */
+ X, X, X, X, X, T, X, X, X, X, X, X, X, X, X, X, /* 0x8X */
+ X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, /* 0x9X */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xaX */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xbX */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xcX */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xdX */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xeX */
+ I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I /* 0xfX */
+};
+
+int
+looks_utf8(buf, nbytes, ubuf, ulen)
+ const unsigned char *buf;
+ int nbytes;
+ unsigned long *ubuf;
+ int *ulen;
+{
+ int i, n;
+ unsigned long c;
+ int gotone = 0;
+
+ *ulen = 0;
+
+ for (i = 0; i < nbytes; i++) {
+ if ((buf[i] & 0x80) == 0) { /* 0xxxxxxx is plain ASCII */
+ /*
+ * Even if the whole file is valid UTF-8 sequences,
+ * still reject it if it uses weird control characters.
+ */
+
+ if (text_chars[buf[i]] != T)
+ return 0;
+
+ if (ubuf != NULL)
+ ubuf[(*ulen)++] = buf[i];
+ } else if ((buf[i] & 0x40) == 0) { /* 10xxxxxx never 1st byte */
+ return 0;
+ } else { /* 11xxxxxx begins UTF-8 */
+ int following;
+
+ if ((buf[i] & 0x20) == 0) { /* 110xxxxx */
+ c = buf[i] & 0x1f;
+ following = 1;
+ } else if ((buf[i] & 0x10) == 0) { /* 1110xxxx */
+ c = buf[i] & 0x0f;
+ following = 2;
+ } else if ((buf[i] & 0x08) == 0) { /* 11110xxx */
+ c = buf[i] & 0x07;
+ following = 3;
+ } else if ((buf[i] & 0x04) == 0) { /* 111110xx */
+ c = buf[i] & 0x03;
+ following = 4;
+ } else if ((buf[i] & 0x02) == 0) { /* 1111110x */
+ c = buf[i] & 0x01;
+ following = 5;
+ } else
+ return 0;
+
+ for (n = 0; n < following; n++) {
+ i++;
+ if (i >= nbytes)
+ goto done;
+
+ if ((buf[i] & 0x80) == 0 || (buf[i] & 0x40))
+ return 0;
+
+ c = (c << 6) + (buf[i] & 0x3f);
+ }
+
+ if (ubuf != NULL)
+ ubuf[(*ulen)++] = c;
+ gotone = 1;
+ }
+ }
+done:
+ return gotone; /* don't claim it's UTF-8 if it's all 7-bit */
+}
+
+void
+utf8tolocalechar (char **value)
+{
+ static gchar *locale;
+ static gboolean initialized = FALSE;
+ gchar *pout, *pin, *str;
+ gint len, ulen = 0, ib, ob;
+ iconv_t fd;
+
+ if (!initialized) {
+ setlocale (LC_CTYPE, "");
+ locale = nl_langinfo (CODESET);
+ initialized = TRUE;
+ }
+ if (*value) {
+ len = strlen (*value);
+ if (looks_utf8 (*value, len, NULL, &ulen)) {
+ if ((fd = iconv_open (locale, "UTF-8")) != (iconv_t)-1) {
+ ib = len;
+ ob = ib * 3;
+ pout = str = g_new0 (gchar, ob);
+ pin = *value;
+ iconv (fd, &pin, &ib, &pout, &ob);
+ iconv_close (fd);
+ g_free (*value);
+ *value = str;
+ }
+ }
+ }
}