pcsxr-1.9.92
[pcsx_rearmed.git] / win32 / intl / dcgettext.c
Content-type: text/html notaz's git - pcsx_rearmed.git/blame - win32/intl/dcgettext.c


500 - Internal Server Error

Malformed UTF-8 character (fatal) at (eval 6) line 1, <$fd> line 541.
CommitLineData
ef79bbde
P
1/* Implementation of the dcgettext(3) function.
2 Copyright (C) 1995, 1996, 1997, 1998 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#include <sys/types.h>
21
22#ifdef __GNUC__
23# define alloca __builtin_alloca
24# define HAVE_ALLOCA 1
25#else
26# if defined HAVE_ALLOCA_H || defined _LIBC
27# include <alloca.h>
28# else
29# ifdef _AIX
30 #pragma alloca
31# else
32# ifndef alloca
33char *alloca ();
34# endif
35# endif
36# endif
37#endif
38
39#include <errno.h>
40#ifndef errno
41extern int errno;
42#endif
43#ifndef __set_errno
44# define __set_errno(val) errno = (val)
45#endif
46
47#if defined STDC_HEADERS || defined _LIBC
48# include <stdlib.h>
49#else
50char *getenv ();
51# ifdef HAVE_MALLOC_H
52# include <malloc.h>
53# else
54void free ();
55# endif
56#endif
57
58#if defined HAVE_STRING_H || defined _LIBC
59# ifndef _GNU_SOURCE
60# define _GNU_SOURCE 1
61# endif
62# include <string.h>
63#else
64# include <strings.h>
65#endif
66#if !HAVE_STRCHR && !defined _LIBC
67# ifndef strchr
68# define strchr index
69# endif
70#endif
71
72#if defined HAVE_UNISTD_H || defined _LIBC
73# include <unistd.h>
74#endif
75
76#include "gettext.h"
77#include "gettextP.h"
78#ifdef _LIBC
79# include <libintl.h>
80#else
81# include "libgettext.h"
82#endif
83#include "hash-string.h"
84
85/* @@ end of prolog @@ */
86
87#ifdef _LIBC
88/* Rename the non ANSI C functions. This is required by the standard
89 because some ANSI C functions will require linking with this object
90 file and the name space must not be polluted. */
91# define getcwd __getcwd
92# ifndef stpcpy
93# define stpcpy __stpcpy
94# endif
95#else
96# if !defined HAVE_GETCWD
97char *getwd ();
98# define getcwd(buf, max) getwd (buf)
99# else
100char *getcwd ();
101# endif
102# ifndef HAVE_STPCPY
103static char *stpcpy PARAMS ((char *dest, const char *src));
104# endif
105#endif
106
107/* Amount to increase buffer size by in each try. */
108#define PATH_INCR 32
109
110/* The following is from pathmax.h. */
111/* Non-POSIX BSD systems might have gcc's limits.h, which doesn't define
112 PATH_MAX but might cause redefinition warnings when sys/param.h is
113 later included (as on MORE/BSD 4.3). */
114#if defined(_POSIX_VERSION) || (defined(HAVE_LIMITS_H) && !defined(__GNUC__))
115# include <limits.h>
116#endif
117
118#ifndef _POSIX_PATH_MAX
119# define _POSIX_PATH_MAX 255
120#endif
121
122#if !defined(PATH_MAX) && defined(_PC_PATH_MAX)
123# define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf ("/", _PC_PATH_MAX))
124#endif
125
126/* Don't include sys/param.h if it already has been. */
127#if defined(HAVE_SYS_PARAM_H) && !defined(PATH_MAX) && !defined(MAXPATHLEN)
128# include <sys/param.h>
129#endif
130
131#if !defined(PATH_MAX) && defined(MAXPATHLEN)
132# define PATH_MAX MAXPATHLEN
133#endif
134
135#ifndef PATH_MAX
136# define PATH_MAX _POSIX_PATH_MAX
137#endif
138
139/* XPG3 defines the result of `setlocale (category, NULL)' as:
140 ``Directs `setlocale()' to query `category' and return the current
141 setting of `local'.''
142 However it does not specify the exact format. And even worse: POSIX
143 defines this not at all. So we can use this feature only on selected
144 system (e.g. those using GNU C Library). */
145#ifdef _LIBC
146# define HAVE_LOCALE_NULL
147#endif
148
149/* Name of the default domain used for gettext(3) prior any call to
150 textdomain(3). The default value for this is "messages". */
151const char _nl_default_default_domain[] = "messages";
152
153/* Value used as the default domain for gettext(3). */
154const char *_nl_current_default_domain = _nl_default_default_domain;
155
156/* Contains the default location of the message catalogs. */
157const char _nl_default_dirname[] = GNULOCALEDIR;
158
159/* List with bindings of specific domains created by bindtextdomain()
160 calls. */
161struct binding *_nl_domain_bindings;
162
163/* Prototypes for local functions. */
164static char *find_msg PARAMS ((struct loaded_l10nfile *domain_file,
165 const char *msgid)) internal_function;
166static const char *category_to_name PARAMS ((int category)) internal_function;
167static const char *guess_category_value PARAMS ((int category,
168 const char *categoryname))
169 internal_function;
170
171
172/* For those loosing systems which don't have `alloca' we have to add
173 some additional code emulating it. */
174#ifdef HAVE_ALLOCA
175/* Nothing has to be done. */
176# define ADD_BLOCK(list, address) /* nothing */
177# define FREE_BLOCKS(list) /* nothing */
178#else
179struct block_list
180{
181 void *address;
182 struct block_list *next;
183};
184# define ADD_BLOCK(list, addr) \
185 do { \
186 struct block_list *newp = (struct block_list *) malloc (sizeof (*newp)); \
187 /* If we cannot get a free block we cannot add the new element to \
188 the list. */ \
189 if (newp != NULL) { \
190 newp->address = (addr); \
191 newp->next = (list); \
192 (list) = newp; \
193 } \
194 } while (0)
195# define FREE_BLOCKS(list) \
196 do { \
197 while (list != NULL) { \
198 struct block_list *old = list; \
199 list = list->next; \
200 free (old); \
201 } \
202 } while (0)
203# undef alloca
204# define alloca(size) (malloc (size))
205#endif /* have alloca */
206
207
208/* Names for the libintl functions are a problem. They must not clash
209 with existing names and they should follow ANSI C. But this source
210 code is also used in GNU C Library where the names have a __
211 prefix. So we have to make a difference here. */
212#ifdef _LIBC
213# define DCGETTEXT __dcgettext
214#else
215# define DCGETTEXT dcgettext__
216#endif
217
218/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
219 locale. */
220char *
221DCGETTEXT (domainname, msgid, category)
222 const char *domainname;
223 const char *msgid;
224 int category;
225{
226#ifndef HAVE_ALLOCA
227 struct block_list *block_list = NULL;
228#endif
229 struct loaded_l10nfile *domain;
230 struct binding *binding;
231 const char *categoryname;
232 const char *categoryvalue;
233 char *dirname, *xdomainname;
234 char *single_locale;
235 char *retval;
236 int saved_errno = errno;
237
238 /* If no real MSGID is given return NULL. */
239 if (msgid == NULL)
240 return NULL;
241
242 /* If DOMAINNAME is NULL, we are interested in the default domain. If
243 CATEGORY is not LC_MESSAGES this might not make much sense but the
244 defintion left this undefined. */
245 if (domainname == NULL)
246 domainname = _nl_current_default_domain;
247
248 /* First find matching binding. */
249 for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next)
250 {
251 int compare = strcmp (domainname, binding->domainname);
252 if (compare == 0)
253 /* We found it! */
254 break;
255 if (compare < 0)
256 {
257 /* It is not in the list. */
258 binding = NULL;
259 break;
260 }
261 }
262
263 if (binding == NULL)
264 dirname = (char *) _nl_default_dirname;
265