diff --git a/common/ChangeLog b/common/ChangeLog index ab4bec0a4..b458bdd5c 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,8 @@ +2007-04-25 Werner Koch + + * i18n.h (ngettext): New. + * simple-gettext.c (ngettext): New. + 2007-04-20 Werner Koch * miscellaneous.c (my_gcry_logger, my_gcry_outofcore_handler): diff --git a/common/i18n.h b/common/i18n.h index 6881a8a61..56c00abf6 100644 --- a/common/i18n.h +++ b/common/i18n.h @@ -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*/ diff --git a/common/simple-gettext.c b/common/simple-gettext.c index 56a305fd8..6661b2d12 100644 --- a/common/simple-gettext.c +++ b/common/simple-gettext.c @@ -419,6 +419,15 @@ gettext( const char *msgid ) 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; diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog index 3168b8a15..0db89e3c4 100644 --- a/jnlib/ChangeLog +++ b/jnlib/ChangeLog @@ -1,3 +1,7 @@ +2007-04-25 Werner Koch + + * argparse.c (long_opt_strlen): Fixed for utf-8. + 2007-03-07 Werner Koch * argparse.c (strusage): Set copyright year to 2007. diff --git a/jnlib/argparse.c b/jnlib/argparse.c index c9cb7d32e..348a803a9 100644 --- a/jnlib/argparse.c +++ b/jnlib/argparse.c @@ -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 @@ find_long_option( ARGPARSE_ARGS *arg, 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 @@ find_long_option( ARGPARSE_ARGS *arg, } } } - #endif +#endif /* not found, see whether it is an abbreviation */ /* aliases may not be abbreviated */ n = strlen( keyword ); @@ -699,18 +703,28 @@ set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s) 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 @@ main(int argc, char **argv) { 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; diff --git a/jnlib/utf8conv.c b/jnlib/utf8conv.c index 9a2a98b3b..d7c0d44ba 100644 --- a/jnlib/utf8conv.c +++ b/jnlib/utf8conv.c @@ -256,6 +256,13 @@ get_native_charset () 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. */ diff --git a/jnlib/utf8conv.h b/jnlib/utf8conv.h index f0eb4ec0f..9e1ce9530 100644 --- a/jnlib/utf8conv.h +++ b/jnlib/utf8conv.h @@ -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);