Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wbindtextdomain #5

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 72 additions & 13 deletions libintl.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ static char * (*p_bindtextdomain) (const char *domainname,
static char * (*p_bind_textdomain_codeset) (const char *domainname,
const char *codeset);

#ifdef _WIN32
static wchar_t * (*p_wbindtextdomain) (const char *domainname,
const wchar_t *wdirname);
#endif

static int
use_intl_dll (HMODULE dll)
{
Expand All @@ -94,7 +99,10 @@ use_intl_dll (HMODULE dll)
LOOKUP (textdomain);
LOOKUP (bindtextdomain);
LOOKUP (bind_textdomain_codeset);

#ifdef _WIN32
LOOKUP (wbindtextdomain)
#endif

#undef LOOKUP
#endif /* !STUB_ONLY */
return 1;
Expand All @@ -109,6 +117,15 @@ dummy_##fn parlist \
return (char *) (retval); \
}

#ifdef _WIN32
#define WDUMMY(fn, parlist, retval) \
static wchar_t * \
dummy_##fn parlist \
{ \
return (wchar_t *) (retval); \
}
#endif

DUMMY (gettext,
(const char *msgid),
msgid)
Expand Down Expand Up @@ -175,8 +192,19 @@ DUMMY (bind_textdomain_codeset,
const char *codeset),
codeset)

#ifdef _WIN32
WDUMMY (wbindtextdomain,
(const char *domainname,
const wchar_t *dirname),
L"/dummy")
#endif

#undef DUMMY

#ifdef _WIN32
#undef WDUMMY
#endif

static void
use_dummy (void)
{
Expand All @@ -191,7 +219,11 @@ use_dummy (void)
USE_DUMMY (textdomain);
USE_DUMMY (bindtextdomain);
USE_DUMMY (bind_textdomain_codeset);


#ifdef _WIN32
USE_DUMMY (wbindtextdomain);
#endif

#undef USE_DUMMY

}
Expand All @@ -204,19 +236,25 @@ setup (void)
if (!beenhere)
{
#if !STUB_ONLY
#if defined(_WIN64)
/* On 64-bit Windows we have let libtool choose the default name
* for the DLL, as we don't need the intl.dll name for backward
* compatibility
*/
HMODULE intl_dll = LoadLibrary ("libintl-8.dll");
# elif defined( _WIN32)
HMODULE intl_dll = LoadLibrary ("intl.dll");
# elif defined(__APPLE__) && defined(__MACH__)
HMODULE intl_dll = dlopen ("libintl.dylib", RTLD_LAZY);
# if defined(_WIN32)
# if !defined (_MSC_VER)
HMODULE intl_dll = LoadLibraryW (L"libintl-8.dll");
# if defined (_M_IX86)
/* Also try without libtool naming scheme for
* backward compatibility. That's only needed
* on x86 */
if (intl_dll == NULL) {
intl_dll = LoadLibraryW (L"intl.dll");
}
# endif
# else
HMODULE intl_dll = dlopen ("libintl.so", RTLD_LAZY);
HMODULE intl_dll = LoadLibraryW (L"intl.dll");
# endif
# elif defined(__APPLE__) && defined(__MACH__)
HMODULE intl_dll = dlopen ("libintl.dylib", RTLD_LAZY);
# else
HMODULE intl_dll = dlopen ("libintl.so", RTLD_LAZY);
# endif
#else /* !STUB_ONLY */
HMODULE intl_dll = NULL;
#endif /* STUB_ONLY */
Expand Down Expand Up @@ -249,6 +287,16 @@ g_libintl_ ## fn parlist \
return p_##fn parlist2; \
}

#ifdef _WIN32
#define WIMPLEMENT(fn, parlist, parlist2) \
wchar_t * \
g_libintl_ ## fn parlist \
{ \
setup (); \
return p_##fn parlist2; \
}
#endif

IMPLEMENT (gettext,
(const char *msgid),
(msgid))
Expand Down Expand Up @@ -299,4 +347,15 @@ IMPLEMENT (bind_textdomain_codeset,
const char *codeset),
(domainname, codeset))

#ifdef _WIN32
WIMPLEMENT (wbindtextdomain,
(const char *domainname,
const wchar_t *wdirname),
(domainname, wdirname))
#endif

#undef IMPLEMENT

#ifdef _WIN32
#undef WIMPLEMENT
#endif
13 changes: 13 additions & 0 deletions libintl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#include <locale.h>

#ifdef _WIN32
#include <stddef.h> /* for wchar_t */
#endif

#ifndef LC_MESSAGES
# define LC_MESSAGES 1729 /* Use same value as in GNU gettext */
#endif
Expand Down Expand Up @@ -55,6 +59,10 @@
#define bindtextdomain g_libintl_bindtextdomain
#define bind_textdomain_codeset g_libintl_bind_textdomain_codeset

#ifdef _WIN32
#define wbindtextdomain g_libintl_wbindtextdomain
#endif

/* Define G_INTL_STATIC_COMPILATION to link statically */
#if defined(_WIN32) && !defined(G_INTL_STATIC_COMPILATION)
/* Export when producing library, import when linking against library */
Expand Down Expand Up @@ -103,6 +111,11 @@ G_INTL_EXPORT char *g_libintl_bindtextdomain (const char *domainname,
G_INTL_EXPORT char *g_libintl_bind_textdomain_codeset (const char *domainname,
const char *codeset);

#ifdef _WIN32
G_INTL_EXPORT wchar_t *g_libintl_wbindtextdomain (const char *domainname,
const wchar_t *wdirname);
#endif

#ifdef __cplusplus
}
#endif
Expand Down