Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Sep 2001 22:01:55 +0900
From:      SASAKI Katuhiro <sahiro@crest.ocn.ne.jp>
To:        gnome@FreeBSD.org
Cc:        ports@freebsd.org
Subject:   utf8 menu patch for x11/gnomelibs
Message-ID:  <3baddc12.6416%sahiro@crest.ocn.ne.jp>

next in thread | raw e-mail | index | archive | help
Hi.

How is adding a patch which is called "utf8menu" patch to 
x11/gnomelibs?

Still now, gnome-libs has problems in i18n implementation. One 
of them is a problem with handling of menu itmes which are 
written in UTF-8 encoding. 
This problem often appears when one who uses GNOME with KDE2 
chooses "KDE menus" from "Main Menu" under non-English 
environment. Menu itmes which are displyed will not make 
sense. It would discourage people who uses GNOME on FreeBSD.
To make away with this problem, some Linux distributor(e.g Red 
Hat) applies a patch which is called "utf8menu" patch. The 
patch enables to convert UTF-8 strings which appear in a 
GnomeDesktopEntry to strings encoded in character-set which is 
specified by LOCALE. So, displaying menu items which are written 
in UTF-8 will be fine now.
I slightly changed the original patch to use locale_charset() 
which is implemented by libiconv(converters/libiconv) when 
nl_langinfo() is not available. The reason why I did so is that 
the original patch realizes convrsion using iconv()(which is 
implemented by libiconv, too.) and nl_langinfo(), and 
nl_langinfo() is not yet supported in 4-STABLE.

Please let me show cahged version "utf8menu" patch. This 
contains patch to configure.in and acconfig.h, so processing by 
autoheader and autoconf is needed.


Thank you.


diff -urN gnome-libs-1.4.1.2.orig/acconfig.h gnome-libs-1.4.1.2/acconfig.h
--- gnome-libs-1.4.1.2.orig/acconfig.h	Thu Sep 21 20:43:37 2000
+++ gnome-libs-1.4.1.2/acconfig.h	Sun Sep 23 13:40:45 2001
@@ -63,6 +63,8 @@
 #undef KDE_ICONDIR
 #undef KDE_MINI_ICONDIR
 
+#undef HAVE_LIBGICONV
+
 #undef PREFER_DB1
 
 /* define if needed to include sa_len member in struct sockaddr */
diff -urN gnome-libs-1.4.1.2.orig/configure.in gnome-libs-1.4.1.2/configure.in
--- gnome-libs-1.4.1.2.orig/configure.in	Wed Aug 22 06:40:46 2001
+++ gnome-libs-1.4.1.2/configure.in	Sun Sep 23 13:50:45 2001
@@ -436,6 +436,33 @@
 AC_DEFINE_UNQUOTED(KDE_MINI_ICONDIR, "$kde_datadir/icons/mini")
 
 dnl
+dnl Checks for iconv
+dnl
+AC_CHECK_FUNCS(iconv, iconv_ok=yes, iconv_ok=no)
+if test "$iconv_ok" = yes; then
+  AC_CHECK_HEADERS(iconv.h)
+else
+  AC_CHECK_HEADERS(giconv.h, giconv_ok=yes, giconv_ok=no)
+  if test "$giconv_ok" = yes; then
+    LIBS="-lgiconv $LIBS"; AC_DEFINE(HAVE_LIBGICONV)
+  else
+    AC_CHECK_LIB(iconv, iconv, , AC_MSG_ERROR(iconv() is not available.))
+    AC_CHECK_HEADERS(iconv.h)
+  fi
+fi
+
+dnl
+dnl Checks for nl_langinfo/locale_charset
+dnl
+AC_CHECK_FUNCS(nl_langinfo, langinfo_ok=yes, langinfo_ok=no)
+if test "$langinfo_ok" = yes; then
+  AC_CHECK_HEADERS(langinfo.h)
+else
+  AC_CHECK_LIB(charset, locale_charset, , AC_MSG_ERROR(nl_langinfo() nor locale_charse() is not available.))
+  AC_CHECK_HEADERS(libcharset.h)
+fi
+
+dnl
 dnl Substitutions
 dnl
 
diff -urN gnome-libs-1.4.1.2.orig/libgnome/gnome-dentry.c gnome-libs-1.4.1.2/libgnome/gnome-dentry.c
--- gnome-libs-1.4.1.2.orig/libgnome/gnome-dentry.c	Fri Jun 15 07:21:01 2001
+++ gnome-libs-1.4.1.2/libgnome/gnome-dentry.c	Sun Sep 23 13:53:15 2001
@@ -13,6 +13,19 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <locale.h>
+#ifdef HAVE_ICONV_H
+#include <iconv.h>
+#endif
+#ifdef HAVE_GICONV_H
+#include <giconv.h>
+#endif
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#ifdef HAVE_LIBCHARSET_H
+#include <libcharset.h>
+#endif
 #include "gnome-defs.h"
 #include "gnome-util.h"
 #include "gnome-url.h"
@@ -194,7 +207,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;
@@ -808,4 +823,136 @@
 		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, "");
+
+#ifdef HAVE_NL_LANGINFO
+		locale = nl_langinfo (CODESET);
+#endif
+#ifdef HAVE_LIBCHARSET
+		locale = locale_charset();
+#endif
+		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;
+			}
+		}
+	}
 }


================================================================
                       SASAKI Katuhiro

                mailto: sahiro@crest.ocn.ne.jp
================================================================

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3baddc12.6416%sahiro>