From 6570e194e60822d81d6df31e260985e6a13b0f2a Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 20 Aug 1999 19:52:54 +0000 Subject: 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. --- intl/loadmsgcat.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'intl/loadmsgcat.c') 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 #endif +#if defined HAVE_STRING_H || defined _LIBC +# ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +# endif +# include +#else +# include +#endif + #if defined HAVE_UNISTD_H || defined _LIBC # include #endif +#ifdef _LIBC +# include +#endif + #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \ || (defined _LIBC && defined _POSIX_MAPPED_FILES) # include @@ -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 + } + } } -- cgit 1.4.1