[svn] gpg-error - r147 - in trunk: . src
svn author marcus
cvs at cvs.gnupg.org
Sun Oct 23 22:01:05 CEST 2005
Author: marcus
Date: 2005-10-23 22:01:04 +0200 (Sun, 23 Oct 2005)
New Revision: 147
Added:
trunk/src/init.c
Modified:
trunk/ChangeLog
trunk/NEWS
trunk/src/Makefile.am
trunk/src/gpg-error.c
trunk/src/gpg-error.def
trunk/src/gpg-error.h.in
Log:
2005-10-23 Marcus Brinkmann <marcus at g10code.de>
* src/Makefile.am (libgpg_error_la_SOURCES): Add init.c.
* src/init.c: New file.
* src/gpg-error.h.in (gpg_error_init): New function.
* src/gpg-error.def: Add gpg_err_init.
* src/gpg-error.c: Remove SIMPLE_GETTEXT stuff.
(i18n_init): Don't bind text domain.
(main): Call gpg_err_init.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2005-10-20 12:52:39 UTC (rev 146)
+++ trunk/ChangeLog 2005-10-23 20:01:04 UTC (rev 147)
@@ -1,3 +1,13 @@
+2005-10-23 Marcus Brinkmann <marcus at g10code.de>
+
+ * src/Makefile.am (libgpg_error_la_SOURCES): Add init.c.
+ * src/init.c: New file.
+ * src/gpg-error.h.in (gpg_error_init): New function.
+ * src/gpg-error.def: Add gpg_err_init.
+ * src/gpg-error.c: Remove SIMPLE_GETTEXT stuff.
+ (i18n_init): Don't bind text domain.
+ (main): Call gpg_err_init.
+
2005-10-20 Marcus Brinkmann <marcus at g10code.de>
* configure.ac: Instead checking for windres and dlltool, invoke
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2005-10-20 12:52:39 UTC (rev 146)
+++ trunk/NEWS 2005-10-23 20:01:04 UTC (rev 147)
@@ -1,6 +1,9 @@
Noteworthy changes in version 1.2 (unreleased)
----------------------------------------------
+ * New function gpg_err_init, which binds the locale directory to
+ the text domain.
+
* "./autogen.sh --build-w32" does now also build a DLL for W32.
Translations are not yet provided for this platform.
@@ -15,6 +18,7 @@
GPG_ERR_UNKNOWN_EXTN NEW
GPG_ERR_UNKNOWN_CRIT_EXTN NEW
GPG_ERR_LOCKED NEW
+gpg_err_init NEW
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Noteworthy changes in version 1.1 (2005-06-20)
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2005-10-20 12:52:39 UTC (rev 146)
+++ trunk/src/Makefile.am 2005-10-23 20:01:04 UTC (rev 147)
@@ -85,12 +85,11 @@
$(no_undefined) $(export_symbols)
libgpg_error_la_SOURCES = gpg-error.h gettext.h \
- strsource.c strerror.c code-to-errno.c code-from-errno.c
-
+ init.c strsource.c strerror.c code-to-errno.c code-from-errno.c
+libgpg_error_la_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\"
libgpg_error_la_LIBADD = @LTLIBINTL@
gpg_error_SOURCES = strsource-sym.c strerror-sym.c gpg-error.c
-gpg_error_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\"
gpg_error_LDADD = ./libgpg-error.la
err-sources.h: Makefile mkstrtable.awk err-sources.h.in
Modified: trunk/src/gpg-error.c
===================================================================
--- trunk/src/gpg-error.c 2005-10-20 12:52:39 UTC (rev 146)
+++ trunk/src/gpg-error.c 2005-10-23 20:01:04 UTC (rev 147)
@@ -29,28 +29,21 @@
#include <limits.h>
#include <stdio.h>
-#ifdef USE_SIMPLE_GETTEXT
- int set_gettext_file( const char *filename );
- const char *gettext( const char *msgid );
+#ifdef HAVE_LOCALE_H
+# include <locale.h>
+#endif
+#ifdef ENABLE_NLS
+# include <libintl.h>
# define _(a) gettext (a)
-# define N_(a) (a)
-#else
-# ifdef HAVE_LOCALE_H
-# include <locale.h>
-# endif
-# ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(a) gettext (a)
-# ifdef gettext_noop
-# define N_(a) gettext_noop (a)
-# else
-# define N_(a) (a)
-# endif
+# ifdef gettext_noop
+# define N_(a) gettext_noop (a)
# else
-# define _(a) (a)
# define N_(a) (a)
# endif
-#endif /*!USE_SIMPLE_GETTEXT*/
+#else
+# define _(a) (a)
+# define N_(a) (a)
+#endif
#include <gpg-error.h>
@@ -249,22 +242,21 @@
static void
-i18n_init(void)
+i18n_init (void)
{
-#ifdef USE_SIMPLE_GETTEXT
- set_gettext_file (PACKAGE);
-#else
-# ifdef ENABLE_NLS
-# ifdef HAVE_LC_MESSAGES
+#ifdef ENABLE_NLS
+# ifdef HAVE_LC_MESSAGES
setlocale (LC_TIME, "");
setlocale (LC_MESSAGES, "");
-# else
+# else
setlocale (LC_ALL, "" );
-# endif
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
# endif
#endif
+
+ /* We have the same text domain as the library. Thus, we don't need
+ to bind our text domain to our locale directory (this is done by
+ gpg_err_init). We just need to set our text domain. */
+ textdomain (PACKAGE);
}
@@ -273,9 +265,10 @@
{
int i = 1;
- /* Setup I18N. */
- i18n_init();
+ gpg_err_init ();
+ i18n_init ();
+
if (argc == 1)
{
fprintf (stderr, _("Usage: %s GPG-ERROR [...]\n"), argv[0]);
Modified: trunk/src/gpg-error.def
===================================================================
--- trunk/src/gpg-error.def 2005-10-20 12:52:39 UTC (rev 146)
+++ trunk/src/gpg-error.def 2005-10-23 20:01:04 UTC (rev 147)
@@ -5,4 +5,4 @@
gpg_strsource @3
gpg_err_code_from_errno @4
gpg_err_code_to_errno @5
-
+ gpg_err_init @6
Modified: trunk/src/gpg-error.h.in
===================================================================
--- trunk/src/gpg-error.h.in 2005-10-20 12:52:39 UTC (rev 146)
+++ trunk/src/gpg-error.h.in 2005-10-23 20:01:04 UTC (rev 147)
@@ -114,6 +114,12 @@
#define GPG_ERR_SOURCE_SHIFT 24
+/* Initialization function. */
+
+/* Initialize the library. This function should be run early. */
+gpg_error_t gpg_err_init (void);
+
+
/* Constructor and accessor functions. */
/* Construct an error value from an error code and source. Within a
@@ -209,4 +215,5 @@
}
#endif
+
#endif /* GPG_ERROR_H */
Added: trunk/src/init.c
===================================================================
--- trunk/src/init.c 2005-10-20 12:52:39 UTC (rev 146)
+++ trunk/src/init.c 2005-10-23 20:01:04 UTC (rev 147)
@@ -0,0 +1,224 @@
+/* init.c - Initialize the GnuPG error library.
+ Copyright (C) 2005 g10 Code GmbH
+
+ This file is part of libgpg-error.
+
+ libgpg-error is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ libgpg-error is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with libgpg-error; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <gpg-error.h>
+
+#include "gettext.h"
+
+
+/* Locale directory support. */
+
+#if HAVE_W32_SYSTEM
+/* The implementation follows below. */
+static char *get_locale_dir (void);
+static void drop_locale_dir (char *locale_dir);
+#else
+#define get_locale_dir() LOCALEDIR
+#define drop_locale_dir(dir)
+#endif
+
+
+/* Initialize the library. This function should be run early. */
+gpg_error_t
+gpg_err_init (void)
+{
+ char *locale_dir;
+
+ /* We only have to bind our locale directory to our text domain. */
+
+ locale_dir = get_locale_dir ();
+ if (locale_dir)
+ {
+ bindtextdomain (PACKAGE, locale_dir);
+ drop_locale_dir (locale_dir);
+ }
+
+ return 0;
+}
+
+
+
+#ifdef HAVE_W32_SYSTEM
+
+#include <windows.h>
+
+static HKEY
+get_root_key(const char *root)
+{
+ HKEY root_key;
+
+ if( !root )
+ root_key = HKEY_CURRENT_USER;
+ else if( !strcmp( root, "HKEY_CLASSES_ROOT" ) )
+ root_key = HKEY_CLASSES_ROOT;
+ else if( !strcmp( root, "HKEY_CURRENT_USER" ) )
+ root_key = HKEY_CURRENT_USER;
+ else if( !strcmp( root, "HKEY_LOCAL_MACHINE" ) )
+ root_key = HKEY_LOCAL_MACHINE;
+ else if( !strcmp( root, "HKEY_USERS" ) )
+ root_key = HKEY_USERS;
+ else if( !strcmp( root, "HKEY_PERFORMANCE_DATA" ) )
+ root_key = HKEY_PERFORMANCE_DATA;
+ else if( !strcmp( root, "HKEY_CURRENT_CONFIG" ) )
+ root_key = HKEY_CURRENT_CONFIG;
+ else
+ return NULL;
+ return root_key;
+}
+
+/****************
+ * Return a string from the Win32 Registry or NULL in case of
+ * error. Caller must release the return value. A NULL for root
+ * is an alias for HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE in turn.
+ * NOTE: The value is allocated with a plain malloc() - use free() and not
+ * the usual xfree()!!!
+ */
+static char *
+read_w32_registry_string( const char *root, const char *dir, const char *name )
+{
+ HKEY root_key, key_handle;
+ DWORD n1, nbytes, type;
+ char *result = NULL;
+
+ if ( !(root_key = get_root_key(root) ) )
+ return NULL;
+
+ if( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) )
+ {
+ if (root)
+ return NULL; /* no need for a RegClose, so return direct */
+ /* It seems to be common practise to fall back to HKLM. */
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle) )
+ return NULL; /* still no need for a RegClose, so return direct */
+ }
+
+ nbytes = 1;
+ if( RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) ) {
+ if (root)
+ goto leave;
+ /* Try to fallback to HKLM also vor a missing value. */
+ RegCloseKey (key_handle);
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle) )
+ return NULL; /* Nope. */
+ if (RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes))
+ goto leave;
+ }
+ result = malloc( (n1=nbytes+1) );
+ if( !result )
+ goto leave;
+ if( RegQueryValueEx( key_handle, name, 0, &type, result, &n1 ) ) {
+ free(result); result = NULL;
+ goto leave;
+ }
+ result[nbytes] = 0; /* make sure it is really a string */
+ if (type == REG_EXPAND_SZ && strchr (result, '%')) {
+ char *tmp;
+
+ n1 += 1000;
+ tmp = malloc (n1+1);
+ if (!tmp)
+ goto leave;
+ nbytes = ExpandEnvironmentStrings (result, tmp, n1);
+ if (nbytes && nbytes > n1) {
+ free (tmp);
+ n1 = nbytes;
+ tmp = malloc (n1 + 1);
+ if (!tmp)
+ goto leave;
+ nbytes = ExpandEnvironmentStrings (result, tmp, n1);
+ if (nbytes && nbytes > n1) {
+ free (tmp); /* oops - truncated, better don't expand at all */
+ goto leave;
+ }
+ tmp[nbytes] = 0;
+ free (result);
+ result = tmp;
+ }
+ else if (nbytes) { /* okay, reduce the length */
+ tmp[nbytes] = 0;
+ free (result);
+ result = malloc (strlen (tmp)+1);
+ if (!result)
+ result = tmp;
+ else {
+ strcpy (result, tmp);
+ free (tmp);
+ }
+ }
+ else { /* error - don't expand */
+ free (tmp);
+ }
+ }
+
+ leave:
+ RegCloseKey( key_handle );
+ return result;
+}
+
+
+#define REGKEY "Software\\GNU\\GnuPG"
+
+static char *
+get_locale_dir (void)
+{
+ char *instdir;
+ char *p;
+ char *dname;
+
+ instdir = read_w32_registry_string ("HKEY_LOCAL_MACHINE", REGKEY,
+ "Install Directory");
+ if (!instdir)
+ return;
+
+ /* Build the key: "<instdir>/share/locale". */
+#define SLDIR "\\share\\locale"
+ dname = malloc (strlen (instdir) + strlen (SLDIR) + 1);
+ if (!dname)
+ {
+ free (instdir);
+ return;
+ }
+ p = dname;
+ strcpy (p, instdir);
+ p += strlen (instdir);
+ strcpy (p, SLDIR);
+
+ free (instdir);
+
+ return dname;
+}
+
+
+static void
+drop_locale_dir (char *locale_dir)
+{
+ free (locale_dir);
+}
+
+#endif /* HAVE_W32_SYSTEM */
More information about the Gnupg-commits
mailing list