summaryrefslogtreecommitdiff
path: root/intl/loadmsgcat.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-08-20 19:52:54 +0000
committerUlrich Drepper <drepper@redhat.com>1999-08-20 19:52:54 +0000
commit6570e194e60822d81d6df31e260985e6a13b0f2a (patch)
tree505bc4144874d98bb1a19417ac3e69fe95debae9 /intl/loadmsgcat.c
parentbe7d999a0931203c5541714a255635459ee6dde2 (diff)
Update.
* intl/gettextP.h (struct loaded_domain): Add conv element. * intl/dcgettext.c (find_msg): Rename to _nl_find_msg and make public. Instead of returning found message directly convert it using iconv if a conversion was found when opening the file. * intl/loadinfo.h: Protect against multiple inclusion. Declare _nl_find_msg. * intl/loadmsgcat.c (_nl_load_domain): Try to determine charset used in the message file and if necessary find approrpiate conversion to match currently selected charset.
Diffstat (limited to 'intl/loadmsgcat.c')
-rw-r--r--intl/loadmsgcat.c55
1 files changed, 52 insertions, 3 deletions
diff --git a/intl/loadmsgcat.c b/intl/loadmsgcat.c
index 76887e8b4f..23d738882b 100644
--- a/intl/loadmsgcat.c
+++ b/intl/loadmsgcat.c
@@ -31,10 +31,23 @@
# include <stdlib.h>
#endif
+#if defined HAVE_STRING_H || defined _LIBC
+# ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+# endif
+# include <string.h>
+#else
+# include <strings.h>
+#endif
+
#if defined HAVE_UNISTD_H || defined _LIBC
# include <unistd.h>
#endif
+#ifdef _LIBC
+# include <langinfo.h>
+#endif
+
#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
|| (defined _LIBC && defined _POSIX_MAPPED_FILES)
# include <sys/mman.h>
@@ -47,6 +60,10 @@
#include "gettext.h"
#include "gettextP.h"
+#ifdef _LIBC
+# include "../locale/localeinfo.h"
+#endif
+
/* @@ end of prolog @@ */
#ifdef _LIBC
@@ -79,6 +96,7 @@ _nl_load_domain (domain_file)
struct mo_file_header *data = (struct mo_file_header *) -1;
int use_mmap = 0;
struct loaded_domain *domain;
+ char *nullentry;
domain_file->decided = 1;
domain_file->data = NULL;
@@ -200,9 +218,40 @@ _nl_load_domain (domain_file)
return;
}
- /* Show that one domain is changed. This might make some cached
- translations invalid. */
- ++_nl_msg_cat_cntr;
+ /* Now find out about the character set the file is encoded with.
+ This can be found (in textual form) in the entry "". If this
+ entry does not exist or if this does not contain the `charset='
+ information, we will assume the charset matches the one the
+ current locale and we don't have to perform any conversion. */
+#if HAVE_ICONV || defined _LIBC
+ domain->conv = (iconv_t) -1;
+#endif
+ nullentry = _nl_find_msg (domain_file, "");
+ if (nullentry != NULL)
+ {
+ char *charsetstr = strstr (nullentry, "charset=");
+
+ if (charsetstr != NULL)
+ {
+ size_t len;
+ char *charset;
+
+ charsetstr += strlen ("charset=");
+ len = strcspn (charsetstr, " \t\n");
+
+ charset = (char *) alloca (len + 1);
+#if defined _LIBC || HAVE_MEMPCPY
+ *((char *) mempcpy (charset, charsetstr, len)) = '\0';
+#else
+ memcpy (charset, charsetstr, len);
+ charset[len] = '\0';
+#endif
+
+#if HAVE_ICONV || defined _LIBC
+ domain->conv = iconv_open ((*_nl_current[LC_CTYPE])->values[_NL_ITEM_INDEX (CODESET)].string, charset);
+#endif
+ }
+ }
}