aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/ChangeLog13
-rw-r--r--util/argparse.c2
-rw-r--r--util/simple-gettext.c83
-rw-r--r--util/strgutil.c47
4 files changed, 109 insertions, 36 deletions
diff --git a/util/ChangeLog b/util/ChangeLog
index 89f1f59cb..11fc41b8d 100644
--- a/util/ChangeLog
+++ b/util/ChangeLog
@@ -1,3 +1,16 @@
+2005-01-20 Werner Koch <[email protected]>
+
+ * simple-gettext.c (set_gettext_file): Use MO files depending on
+ the installation directory. Add new arg REGKEY.
+
+2005-01-18 Werner Koch <[email protected]>
+
+ * argparse.c (default_strusage): Changed default copyright year to
+ 2005.
+
+ * strgutil.c (handle_iconv_error): Print error messages only once.
+ (native_to_utf8, utf8_to_native): Ditto.
+
2005-01-11 Werner Koch <[email protected]>
* strgutil.c (set_native_charset) [W32]: Use the alias table from
diff --git a/util/argparse.c b/util/argparse.c
index 30b403fd1..becfb4d06 100644
--- a/util/argparse.c
+++ b/util/argparse.c
@@ -914,7 +914,7 @@ default_strusage( int level )
switch( level ) {
case 11: p = "foo"; break;
case 13: p = "0.0"; break;
- case 14: p = "Copyright (C) 2004 Free Software Foundation, Inc."; break;
+ case 14: p = "Copyright (C) 2005 Free Software Foundation, Inc."; break;
case 15: p =
"This program comes with ABSOLUTELY NO WARRANTY.\n"
"This is free software, and you are welcome to redistribute it\n"
diff --git a/util/simple-gettext.c b/util/simple-gettext.c
index ed658fa59..d5db6f8fa 100644
--- a/util/simple-gettext.c
+++ b/util/simple-gettext.c
@@ -1,5 +1,6 @@
/* simple-gettext.c - a simplified version of gettext.
- * Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
+ * Copyright (C) 1995, 1996, 1997, 1999,
+ * 2005 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -231,13 +232,14 @@ load_domain( const char *filename )
/****************
- * Set the file used for translations. Pass a NULL to disable
- * translation. A new filename may be set at anytime.
- * WARNING: After changing the filename you should not access any data
- * retrieved by gettext().
+ * Set the file used for translations. Pass a NULL to disable
+ * translation. A new filename may be set at anytime. If REGKEY is
+ * not NULL, the function tries to selected the language the registry
+ * key "Lang" below that key. WARNING: After changing the filename you
+ * should not access any data retrieved by gettext().
*/
int
-set_gettext_file( const char *filename )
+set_gettext_file ( const char *filename, const char *regkey )
{
struct loaded_domain *domain = NULL;
@@ -252,30 +254,57 @@ set_gettext_file( const char *filename )
/* absolute path - use it as is */
domain = load_domain( filename );
}
- else { /* relative path - append ".mo" and get dir from the environment */
- char *buf = NULL;
- char *dir;
+ else if (regkey) { /* Standard. */
+ char *instdir, *langid, *fname;
char *p;
- dir = read_w32_registry_string( NULL,
- "Control Panel\\Mingw32\\NLS",
- "MODir" );
- if( dir && (buf=malloc(strlen(dir)+strlen(filename)+1+3+1)) ) {
- strcpy(stpcpy(stpcpy(stpcpy( buf, dir),"\\"), filename),".mo");
- /* Better make sure that we don't mix forward and
- backward slashes. It seems that some Windoze
- versions don't accept this. */
- for (p=buf; *p; p++)
- {
- if (*p == '/')
- *p = '\\';
- }
- domain = load_domain( buf );
- free(buf);
- }
- free(dir);
+ instdir = read_w32_registry_string ("HKEY_LOCAL_MACHINE",
+ regkey,
+ "Install Directory");
+ if (!instdir)
+ return -1;
+ langid = read_w32_registry_string (NULL, /* HKCU then HKLM */
+ regkey,
+ "Lang");
+ if (!langid) {
+ free (instdir);
+ return -1;
+ }
+ /* Strip stuff after a dot in case the user tried to enter
+ * the entire locale synatcs as usual for POSIX. */
+ p = strchr (langid, '.');
+ if (p)
+ *p = 0;
+
+ /* Build the key: "<instdir>/<domain>.nls/<langid>.mo" We
+ use a directory below the installation directory with
+ the domain included in case the software has been
+ insalled with other software altogether at the same
+ place. */
+ fname = malloc (strlen (instdir) + 1 + strlen (filename) + 5
+ + strlen (langid) + 3 + 1);
+ if (!fname) {
+ free (instdir);
+ free (langid);
+ return -1;
+ }
+ strcpy (stpcpy (stpcpy (stpcpy (stpcpy ( stpcpy (fname,
+ instdir),"\\"), filename), ".nls\\"), langid), ".mo");
+ free (instdir);
+ free (langid);
+
+ /* Better make sure that we don't mix forward and
+ backward slashes. It seems that some Windoze
+ versions don't accept this. */
+ for (p=fname; *p; p++) {
+ if (*p == '/')
+ *p = '\\';
+ }
+ domain = load_domain (fname);
+ free(fname);
}
- if( !domain )
+
+ if (!domain)
return -1;
}
diff --git a/util/strgutil.c b/util/strgutil.c
index 515132f95..5389d0694 100644
--- a/util/strgutil.c
+++ b/util/strgutil.c
@@ -1,6 +1,6 @@
/* strgutil.c - string utilities
* Copyright (C) 1994, 1998, 1999, 2000, 2001,
- * 2003 Free Software Foundation, Inc.
+ * 2003, 2004, 2005 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -453,10 +453,33 @@ static void
handle_iconv_error (const char *to, const char *from, int use_fallback)
{
if (errno == EINVAL)
- log_info (_("conversion from `%s' to `%s' not available\n"),
- from, to);
+ {
+ static int shown1, shown2;
+ int x;
+
+ if (to && !strcmp (to, "utf-8"))
+ {
+ x = shown1;
+ shown1 = 1;
+ }
+ else
+ {
+ x = shown2;
+ shown2 = 1;
+ }
+
+ if (!x)
+ log_info (_("conversion from `%s' to `%s' not available\n"),
+ from, to);
+ }
else
- log_info (_("iconv_open failed: %s\n"), strerror (errno));
+ {
+ static int shown;
+
+ if (!shown)
+ log_info (_("iconv_open failed: %s\n"), strerror (errno));
+ shown = 1;
+ }
if (use_fallback)
{
@@ -706,8 +729,12 @@ native_to_utf8( const char *string )
if ( iconv (cd, (ICONV_CONST char **)&inptr, &inbytes,
&outptr, &outbytes) == (size_t)-1)
{
- log_info (_("conversion from `%s' to `%s' failed: %s\n"),
- active_charset_name, "utf-8", strerror (errno));
+ static int shown;
+
+ if (!shown)
+ log_info (_("conversion from `%s' to `%s' failed: %s\n"),
+ active_charset_name, "utf-8", strerror (errno));
+ shown = 1;
/* We don't do any conversion at all but use the strings as is. */
strcpy (buffer, string);
}
@@ -980,8 +1007,12 @@ utf8_to_native( const char *string, size_t length, int delim )
outbuf = outptr = m_alloc (outbytes);
if ( iconv (cd, (ICONV_CONST char **)&inptr, &inbytes,
&outptr, &outbytes) == (size_t)-1) {
- log_info (_("conversion from `%s' to `%s' failed: %s\n"),
- "utf-8", active_charset_name, strerror (errno));
+ static int shown;
+
+ if (!shown)
+ log_info (_("conversion from `%s' to `%s' failed: %s\n"),
+ "utf-8", active_charset_name, strerror (errno));
+ shown = 1;
/* Didn't worked out. Temporary disable the use of
* iconv and fall back to our old code. */
m_free (buffer);