[patch 1.4.1] return uid-8 encoded strings from get_primary_uid()

Motohiko Takemura takemura at pharmaco.crl.hyo-med.ac.jp
Sat Jun 11 12:59:39 CEST 2005


Hi!

In g10/getkey.c: get_primary_uid(), the comment says that the returned
value should be in utf-8 encoding.  Also, get_user_id() returns 
user id if one found, which is in utf-8 encoding.  The following patch
tells gettext() used in these two functions to return a string
in utf-8 encoding.  With this patch, output of --list-sigs is legible
even if i do not have a key used for signing.  Please consider for
inclusion.

Thanks

Motohiko Takemura <takemura at pharmaco.crl.hyo-med.ac.jp>
GPG key: 0xb25de95f

--- gnupg-1.4.1/g10/getkey.c.ORIG	Sat Feb  5 09:00:35 2005
+++ gnupg-1.4.1/g10/getkey.c	Sat May  7 19:09:26 2005
@@ -25,6 +25,9 @@
 #include <string.h>
 #include <assert.h>
 #include <ctype.h>
+#ifdef HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
 #include "util.h"
 #include "packet.h"
 #include "memory.h"
@@ -172,6 +175,7 @@
 {
     KBNODE k;
     const char *s;
+    char *orig_codeset = NULL;
 
     for (k=keyblock; k; k=k->next ) {
         if ( k->pkt->pkttype == PKT_USER_ID
@@ -183,7 +187,24 @@
     } 
     /* fixme: returning translatable constants instead of a user ID is 
      * not good because they are probably not utf-8 encoded. */
+    /* Then, how about using bind_textdomain_codeset ?
+       copyed from passphrase.c */
+#ifdef ENABLE_NLS
+    orig_codeset = bind_textdomain_codeset(PACKAGE, NULL);
+#ifdef HAVE_LANGINFO_CODESET
+    if (!orig_codeset)
+	orig_codeset = nl_langinfo(CODESET);
+#endif
+    if (orig_codeset) {
+	if (!bind_textdomain_codeset(PACKAGE, "utf-8"))
+	    orig_codeset = NULL;
+    }
+#endif /* ENABLE_NLS */
     s = _("[User ID not found]");
+#ifdef ENABLE_NLS
+    if (orig_codeset)
+	bind_textdomain_codeset(PACKAGE, orig_codeset);
+#endif
     *uidlen = strlen (s);
     return s;
 }
@@ -2732,6 +2753,7 @@
     user_id_db_t r;
     char *p;
     int pass=0;
+    char *orig_codeset = NULL;
 
     /* try it two times; second pass reads from key resources */
     do {
@@ -2747,7 +2769,22 @@
             }
         }
     } while( ++pass < 2 && !get_pubkey( NULL, keyid ) );
+#ifdef ENABLE_NLS
+    orig_codeset = bind_textdomain_codeset(PACKAGE, NULL);
+#ifdef HAVE_LANGINFO_CODESET
+    if (!orig_codeset)
+	orig_codeset = nl_langinfo(CODESET);
+#endif
+    if (orig_codeset) {
+	if (!bind_textdomain_codeset(PACKAGE, "utf-8"))
+	    orig_codeset = NULL;
+    }
+#endif /* ENABLE_NLS */
     p = m_strdup( _("[User ID not found]") );
+#ifdef ENABLE_NLS
+    if (orig_codeset)
+	bind_textdomain_codeset(PACKAGE, orig_codeset);
+#endif
     *rn = strlen(p);
     return p;
 }
-------------- next part --------------
--- gnupg-1.4.1/g10/getkey.c.ORIG	Sat Feb  5 09:00:35 2005
+++ gnupg-1.4.1/g10/getkey.c	Sat May  7 19:09:26 2005
@@ -25,6 +25,9 @@
 #include <string.h>
 #include <assert.h>
 #include <ctype.h>
+#ifdef HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
 #include "util.h"
 #include "packet.h"
 #include "memory.h"
@@ -172,6 +175,7 @@
 {
     KBNODE k;
     const char *s;
+    char *orig_codeset = NULL;
 
     for (k=keyblock; k; k=k->next ) {
         if ( k->pkt->pkttype == PKT_USER_ID
@@ -183,7 +187,24 @@
     } 
     /* fixme: returning translatable constants instead of a user ID is 
      * not good because they are probably not utf-8 encoded. */
+    /* Then, how about using bind_textdomain_codeset ?
+       copyed from passphrase.c */
+#ifdef ENABLE_NLS
+    orig_codeset = bind_textdomain_codeset(PACKAGE, NULL);
+#ifdef HAVE_LANGINFO_CODESET
+    if (!orig_codeset)
+	orig_codeset = nl_langinfo(CODESET);
+#endif
+    if (orig_codeset) {
+	if (!bind_textdomain_codeset(PACKAGE, "utf-8"))
+	    orig_codeset = NULL;
+    }
+#endif /* ENABLE_NLS */
     s = _("[User ID not found]");
+#ifdef ENABLE_NLS
+    if (orig_codeset)
+	bind_textdomain_codeset(PACKAGE, orig_codeset);
+#endif
     *uidlen = strlen (s);
     return s;
 }
@@ -2732,6 +2753,7 @@
     user_id_db_t r;
     char *p;
     int pass=0;
+    char *orig_codeset = NULL;
 
     /* try it two times; second pass reads from key resources */
     do {
@@ -2747,7 +2769,22 @@
             }
         }
     } while( ++pass < 2 && !get_pubkey( NULL, keyid ) );
+#ifdef ENABLE_NLS
+    orig_codeset = bind_textdomain_codeset(PACKAGE, NULL);
+#ifdef HAVE_LANGINFO_CODESET
+    if (!orig_codeset)
+	orig_codeset = nl_langinfo(CODESET);
+#endif
+    if (orig_codeset) {
+	if (!bind_textdomain_codeset(PACKAGE, "utf-8"))
+	    orig_codeset = NULL;
+    }
+#endif /* ENABLE_NLS */
     p = m_strdup( _("[User ID not found]") );
+#ifdef ENABLE_NLS
+    if (orig_codeset)
+	bind_textdomain_codeset(PACKAGE, orig_codeset);
+#endif
     *rn = strlen(p);
     return p;
 }


More information about the Gnupg-devel mailing list