[svn] GnuPG - r4493 - in trunk: common jnlib

svn author wk cvs at cvs.gnupg.org
Fri May 4 11:22:47 CEST 2007


Author: wk
Date: 2007-05-04 11:22:18 +0200 (Fri, 04 May 2007)
New Revision: 4493

Modified:
   trunk/common/ChangeLog
   trunk/common/i18n.h
   trunk/common/simple-gettext.c
   trunk/jnlib/ChangeLog
   trunk/jnlib/argparse.c
   trunk/jnlib/utf8conv.c
   trunk/jnlib/utf8conv.h
Log:
UTF-8 Fixes

Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2007-05-03 04:44:12 UTC (rev 4492)
+++ trunk/common/ChangeLog	2007-05-04 09:22:18 UTC (rev 4493)
@@ -1,3 +1,8 @@
+2007-04-25  Werner Koch  <wk at g10code.com>
+
+	* i18n.h (ngettext): New.
+	* simple-gettext.c (ngettext): New.
+
 2007-04-20  Werner Koch  <wk at g10code.com>
 
 	* miscellaneous.c (my_gcry_logger, my_gcry_outofcore_handler):

Modified: trunk/common/i18n.h
===================================================================
--- trunk/common/i18n.h	2007-05-03 04:44:12 UTC (rev 4492)
+++ trunk/common/i18n.h	2007-05-04 09:22:18 UTC (rev 4493)
@@ -17,6 +17,8 @@
 #ifdef USE_SIMPLE_GETTEXT
   int set_gettext_file( const char *filename );
   const char *gettext( const char *msgid );
+  const char *ngettext(const char *msgid1, const char *msgid2,
+                       unsigned long int n);
 # define _(a) gettext (a)
 # define N_(a) (a)
 #else
@@ -34,6 +36,7 @@
 # else
 #  define _(a) (a)
 #  define N_(a) (a)
+#  define ngettext(a,b,c) ((c)==1? (a):(b))
 # endif
 #endif /*!USE_SIMPLE_GETTEXT*/
 

Modified: trunk/common/simple-gettext.c
===================================================================
--- trunk/common/simple-gettext.c	2007-05-03 04:44:12 UTC (rev 4492)
+++ trunk/common/simple-gettext.c	2007-05-04 09:22:18 UTC (rev 4493)
@@ -419,6 +419,15 @@
     return msgid;
 }
 
+
+const char *
+ngettext (const char *msgid1, const char *msgid2, unsigned long int n)
+{
+  /* We use the simple Germanic plural rule. */
+  return gettext (n==1? msgid1 : msgid2);
+}
+
+
 #if 0
        unsigned int cp1, cp2;
 

Modified: trunk/jnlib/ChangeLog
===================================================================
--- trunk/jnlib/ChangeLog	2007-05-03 04:44:12 UTC (rev 4492)
+++ trunk/jnlib/ChangeLog	2007-05-04 09:22:18 UTC (rev 4493)
@@ -1,3 +1,7 @@
+2007-04-25  Werner Koch  <wk at g10code.com>
+
+	* argparse.c (long_opt_strlen): Fixed for utf-8.
+
 2007-03-07  Werner Koch  <wk at g10code.com>
 
 	* argparse.c (strusage): Set copyright year to 2007.

Modified: trunk/jnlib/argparse.c
===================================================================
--- trunk/jnlib/argparse.c	2007-05-03 04:44:12 UTC (rev 4492)
+++ trunk/jnlib/argparse.c	2007-05-04 09:22:18 UTC (rev 4493)
@@ -1,5 +1,6 @@
 /* [argparse.c wk 17.06.97] Argument Parser for option handling
- * Copyright (C) 1998, 1999, 2000, 2001, 2006 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2006
+ *               2007  Free Software Foundation, Inc.
  *
  * This file is part of JNLIB.
  *
@@ -29,6 +30,9 @@
 #include "mischelp.h"
 #include "stringhelp.h"
 #include "logging.h"
+#ifdef JNLIB_NEED_UTF8CONV
+#include "utf8conv.h"
+#endif
 #include "argparse.h"
 
 
@@ -438,7 +442,7 @@
     for(i=0; opts[i].short_opt; i++ )
 	if( opts[i].long_opt && !strcmp( opts[i].long_opt, keyword) )
 	    return i;
-  #if 0
+#if 0
     {
 	ALIAS_DEF a;
 	/* see whether it is an alias */
@@ -450,7 +454,7 @@
 	    }
 	}
     }
-  #endif
+#endif
     /* not found, see whether it is an abbreviation */
     /* aliases may not be abbreviated */
     n = strlen( keyword );
@@ -699,18 +703,28 @@
 static size_t
 long_opt_strlen( ARGPARSE_OPTS *o )
 {
-    size_t n = strlen(o->long_opt);
+  size_t n = strlen (o->long_opt);
 
-    if( o->description && *o->description == '|' ) {
-	const char *s;
-
-	s=o->description+1;
-	if( *s != '=' )
-	    n++;
-	for(; *s && *s != '|'; s++ )
-	    n++;
+  if ( o->description && *o->description == '|' ) 
+    {
+      const char *s;
+#ifdef JNLIB_NEED_UTF8CONV
+      int is_utf8 = is_native_utf8 ();
+#endif
+        
+      s=o->description+1;
+      if ( *s != '=' )
+        n++;
+      /* For a (mostly) correct length calculation we exclude
+         continuation bytes (10xxxxxx) if we are on a native utf8
+         terminal. */
+      for (; *s && *s != '|'; s++ )
+#ifdef JNLIB_NEED_UTF8CONV
+        if ( is_utf8 && (*s&0xc0) != 0x80 )
+#endif
+          n++;
     }
-    return n;
+  return n;
 }
 
 /****************
@@ -954,17 +968,20 @@
 {
     ARGPARSE_OPTS opts[] = {
     { 'v', "verbose",   0 , "Laut sein"},
-    { 'e', "echo"   ,   0 , "Zeile ausgeben, damit wir sehen, was wir einegegeben haben"},
-    { 'd', "debug",     0 , "Debug\nfalls mal etasws\nSchief geht"},
+    { 'e', "echo"   ,   0 , ("Zeile ausgeben, damit wir sehen, was wir ein"
+                             " gegeben haben")},
+    { 'd', "debug",     0 , "Debug\nfalls mal etwas\nschief geht"},
     { 'o', "output",    2   },
     { 'c', "cross-ref", 2|8, "cross-reference erzeugen\n" },
+    /* Note that on a non-utf8 terminal the ß might garble the output. */
+    { 's', "street",  0,     "|Straße|set the name of the street to Straße" },
     { 'm', "my-option", 1|8 },
     { 500, "a-long-option", 0 },
     {0} };
     ARGPARSE_ARGS pargs = { &argc, &argv, 2|4|32 };
     int i;
 
-    while( ArgParse( &pargs, opts) ) {
+    while( arg_parse ( &pargs, opts) ) {
 	switch( pargs.r_opt ) {
 	  case -1 : printf( "arg=`%s'\n", pargs.r.ret_str); break;
 	  case 'v': opt.verbose++; break;

Modified: trunk/jnlib/utf8conv.c
===================================================================
--- trunk/jnlib/utf8conv.c	2007-05-03 04:44:12 UTC (rev 4492)
+++ trunk/jnlib/utf8conv.c	2007-05-04 09:22:18 UTC (rev 4493)
@@ -256,7 +256,14 @@
   return active_charset_name;
 }
 
+/* Return true if the native charset is utf-8.  */
+int 
+is_native_utf8 (void)
+{
+  return no_translation;
+}
 
+
 /* Convert string, which is in native encoding to UTF8 and return a
    new allocated UTF-8 string.  */
 char *

Modified: trunk/jnlib/utf8conv.h
===================================================================
--- trunk/jnlib/utf8conv.h	2007-05-03 04:44:12 UTC (rev 4492)
+++ trunk/jnlib/utf8conv.h	2007-05-04 09:22:18 UTC (rev 4493)
@@ -24,6 +24,7 @@
 
 int set_native_charset (const char *newset);
 const char *get_native_charset (void);
+int is_native_utf8 (void);
 
 char *native_to_utf8 (const char *string);
 char *utf8_to_native (const char *string, size_t length, int delim);




More information about the Gnupg-commits mailing list