pcsxr-1.9.92
[pcsx_rearmed.git] / win32 / intl / gettext.c
CommitLineData
ef79bbde
P
1/* Implementation of gettext(3) function.
2 Copyright (C) 1995, 1997 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. */
17
18#include "intlconfig.h"
19
20#ifdef _LIBC
21# define __need_NULL
22# include <stddef.h>
23#else
24# ifdef STDC_HEADERS
25# include <stdlib.h> /* Just for NULL. */
26# else
27# ifdef HAVE_STRING_H
28# include <string.h>
29# else
30# define NULL ((void *) 0)
31# endif
32# endif
33#endif
34
35#ifdef _LIBC
36# include <libintl.h>
37#else
38# include "libgettext.h"
39#endif
40
41/* @@ end of prolog @@ */
42
43/* Names for the libintl functions are a problem. They must not clash
44 with existing names and they should follow ANSI C. But this source
45 code is also used in GNU C Library where the names have a __
46 prefix. So we have to make a difference here. */
47#ifdef _LIBC
48# define GETTEXT __gettext
49# define DGETTEXT __dgettext
50#else
51# define GETTEXT gettext__
52# define DGETTEXT dgettext__
53#endif
54
55#include <windows.h> // Added by Wei Mingzhi 5-4-2010
56
57/* Look up MSGID in the current default message catalog for the current
58 LC_MESSAGES locale. If not found, returns MSGID itself (the default
59 text). */
60char *
61GETTEXT (msgid)
62 const char *msgid;
63{
64// return DGETTEXT (NULL, msgid);
65
66 // 5-24-2010 Wei Mingzhi
67 // Hack for UTF-8 support
68 char *t = DGETTEXT(NULL, msgid);
69 char buf[16384];
70 static char bufout[16384];
71
72 if (MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)t, -1, (LPWSTR)buf, sizeof(buf)) == 0) {
73 return t;
74 }
75
76 if (WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)buf, -1, (LPSTR)bufout, sizeof(bufout), NULL, NULL) == 0) {
77 return t;
78 }
79
80 return bufout;
81}
82
83#ifdef _LIBC
84/* Alias for function name in GNU C Library. */
85weak_alias (__gettext, gettext);
86#endif