tasn pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=cbb6e9b20f3d85b41b0c3c525fd3ae68864118b1
commit cbb6e9b20f3d85b41b0c3c525fd3ae68864118b1 Author: Vincent Torri <vincent dot torri at gmail dot com> Date: Fri Nov 27 18:43:54 2015 +0100 Evil: add support for LC_MESSAGES for setlocale() LC_MESSAGES is an extension to C ANSI and does not exist on Windows. So add LC_MESSAGES API and overload setlocale() to support it @feature --- src/Makefile_Evil.am | 2 ++ src/lib/evil/Evil.h | 3 +++ src/lib/evil/evil_locale.c | 55 +++++++++++++++++++++++++++++++++++++++ src/lib/evil/evil_locale.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) diff --git a/src/Makefile_Evil.am b/src/Makefile_Evil.am index 4f9ae3f..5c27eca 100644 --- a/src/Makefile_Evil.am +++ b/src/Makefile_Evil.am @@ -10,6 +10,7 @@ lib/evil/Evil.h \ lib/evil/evil_fcntl.h \ lib/evil/evil_inet.h \ lib/evil/evil_langinfo.h \ +lib/evil/evil_locale.h \ lib/evil/evil_macro.h \ lib/evil/evil_macro_pop.h \ lib/evil/evil_main.h \ @@ -35,6 +36,7 @@ lib/evil/evil_fnmatch.c \ lib/evil/evil_fnmatch_list_of_states.c \ lib/evil/evil_inet.c \ lib/evil/evil_langinfo.c \ +lib/evil/evil_locale.c \ lib/evil/evil_link_xp.cpp \ lib/evil/evil_main.c \ lib/evil/evil_mman.c \ diff --git a/src/lib/evil/Evil.h b/src/lib/evil/Evil.h index 780b8b0..6a69f7b 100644 --- a/src/lib/evil/Evil.h +++ b/src/lib/evil/Evil.h @@ -73,6 +73,8 @@ * @li @ref Evil_Mman * @li @ref Evil_Unistd_Group * @li @ref Evil_Dlfcn + * @li @ref Evil_Langinfo_Group + * @li @ref Evil_Locale_Group * @li @ref Evil_Pwd_Group * @li @ref Evil_Stdio_Group * @li @ref Evil_Main_Group @@ -115,6 +117,7 @@ typedef unsigned long gid_t; #include "evil_fcntl.h" #include "evil_inet.h" #include "evil_langinfo.h" +#include "evil_locale.h" #include "evil_main.h" #include "evil_stdlib.h" #include "evil_stdio.h" diff --git a/src/lib/evil/evil_locale.c b/src/lib/evil/evil_locale.c new file mode 100644 index 0000000..d243ad8 --- /dev/null +++ b/src/lib/evil/evil_locale.c @@ -0,0 +1,55 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <string.h> +#include <locale.h> +#include <errno.h> + +#ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include <windows.h> +#undef WIN32_LEAN_AND_MEAN + +#include "evil_macro.h" +#include "evil_locale.h" +#include "evil_private.h" + +/* + * LOCALE_SISO639LANGNAME and LOCALE_SISO3166CTRYNAME need at least a buffer + * of 9 char each (including NULL char). So we need 2*8 + the trailing NULL + * char + '_', so 18 char. + */ +static char _evil_locale_buf[18]; + +char *evil_setlocale(int category, const char *locale) +{ + char buf[9]; + int l1; + int l2; + + if (category != LC_MESSAGES) + return setlocale(category, locale); + + if (locale != NULL) + { + errno = EINVAL; + return NULL; + } + + l1 = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, + buf, sizeof(buf)); + if (!l1) return NULL; + + memcpy(_evil_locale_buf, buf, l1 - 1); + _evil_locale_buf[l1 - 1] = '_'; + + l2 = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME, + buf, sizeof(buf)); + if (!l2) return NULL; + + memcpy(_evil_locale_buf + l1, buf, l2); + + return _evil_locale_buf; +} diff --git a/src/lib/evil/evil_locale.h b/src/lib/evil/evil_locale.h new file mode 100644 index 0000000..6196800 --- /dev/null +++ b/src/lib/evil/evil_locale.h @@ -0,0 +1,65 @@ +#ifndef __EVIL_LOCALE_H__ +#define __EVIL_LOCALE_H__ + + +/** + * @file evil_locale.h + * @brief The file that provides functions ported from Unix in locale.h. + * @defgroup Evil_Locale_Group locale.h functions. + * @ingroup Evil + * + * This header provides functions ported from Unix in locale.h. + * + * @{ + */ + + +/** + * @def LC_MESSAGES + * + * New locale value, based on the one in libintl.h + */ +#ifdef LC_MESSAGES +# undef LC_MESSAGES +#endif +#define LC_MESSAGES 1729 + +/** + * @brief Return the string associated to the given locale and category. + * + * @param category The category affected by locale. + * @param locale The locale specifier. + * @return The string associated to the specified locale and category. + * + * This function returns the string associated to @p locale and + * @p category. If @p category is LC_ALL, LC_COLLATE, LC_CTYPE, + * LC_MONETARY, LC_NUMERIC or LC_TIME, it just returns the standard + * setlocale() function. If @p category is #LC_MESSAGES, then if @p locale + * is not @c NULL, errno is set to EINVAL and @c NULL is returned, otherwise + * the string <language>_<country> is returned. This string is a static buffer + * and must not be freed. It will also be rewritten each time @category is + * #LC_MESSAGES and @p locale is @c NULL. + * + * Conformity: Non applicable. + * + * Supported OS: Windows XP. + */ +EAPI char *evil_setlocale(int category, const char *locale); + +/** + * @def setlocale(cat, loc) + * + * Wrapper around evil_setlocale(). + */ +#ifdef setlocale /* libintl.h defines setlocale() but always returns "C" */ +# undef setlocale +#endif +#define setlocale(cat, loc) evil_setlocale(cat, loc) + + +/** + * @} + */ + + +#endif /*__EVIL_LOCALE_H__ */ --