| 58 | | extern int libintl_version; |
| 59 | | |
| 60 | | |
| 61 | | /* We redirect the functions to those prefixed with "libintl_". This is |
| 62 | | necessary, because some systems define gettext/textdomain/... in the C |
| 63 | | library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer). |
| 64 | | If we used the unprefixed names, there would be cases where the |
| 65 | | definition in the C library would override the one in the libintl.so |
| 66 | | shared library. Recall that on ELF systems, the symbols are looked |
| 67 | | up in the following order: |
| 68 | | 1. in the executable, |
| 69 | | 2. in the shared libraries specified on the link command line, in order, |
| 70 | | 3. in the dependencies of the shared libraries specified on the link |
| 71 | | command line, |
| 72 | | 4. in the dlopen()ed shared libraries, in the order in which they were |
| 73 | | dlopen()ed. |
| 74 | | The definition in the C library would override the one in libintl.so if |
| 75 | | either |
| 76 | | * -lc is given on the link command line and -lintl isn't, or |
| 77 | | * -lc is given on the link command line before -lintl, or |
| 78 | | * libintl.so is a dependency of a dlopen()ed shared library but not |
| 79 | | linked to the executable at link time. |
| 80 | | Since Solaris gettext() behaves differently than GNU gettext(), this |
| 81 | | would be unacceptable. |
| 82 | | |
| 83 | | The redirection happens by default through macros in C, so that &gettext |
| 84 | | is independent of the compilation unit, but through inline functions in |
| 85 | | C++, in order not to interfere with the name mangling of class fields or |
| 86 | | class methods called 'gettext'. */ |
| 87 | | |
| 88 | | /* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS. |
| 89 | | If he doesn't, we choose the method. A third possible method is |
| 90 | | _INTL_REDIRECT_ASM, supported only by GCC. */ |
| | 57 | extern int libintl_version; |
| | 58 | |
| | 59 | |
| | 60 | /* We redirect the functions to those prefixed with "libintl_". This is |
| | 61 | necessary, because some systems define gettext/textdomain/... in the C |
| | 62 | library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer). |
| | 63 | If we used the unprefixed names, there would be cases where the |
| | 64 | definition in the C library would override the one in the libintl.so |
| | 65 | shared library. Recall that on ELF systems, the symbols are looked |
| | 66 | up in the following order: |
| | 67 | 1. in the executable, |
| | 68 | 2. in the shared libraries specified on the link command line, in order, |
| | 69 | 3. in the dependencies of the shared libraries specified on the link |
| | 70 | command line, |
| | 71 | 4. in the dlopen()ed shared libraries, in the order in which they were |
| | 72 | dlopen()ed. |
| | 73 | The definition in the C library would override the one in libintl.so if |
| | 74 | either |
| | 75 | * -lc is given on the link command line and -lintl isn't, or |
| | 76 | * -lc is given on the link command line before -lintl, or |
| | 77 | * libintl.so is a dependency of a dlopen()ed shared library but not |
| | 78 | linked to the executable at link time. |
| | 79 | Since Solaris gettext() behaves differently than GNU gettext(), this |
| | 80 | would be unacceptable. |
| | 81 | |
| | 82 | The redirection happens by default through macros in C, so that &gettext |
| | 83 | is independent of the compilation unit, but through inline functions in |
| | 84 | C++, in order not to interfere with the name mangling of class fields or |
| | 85 | class methods called 'gettext'. */ |
| | 86 | |
| | 87 | /* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS. |
| | 88 | If he doesn't, we choose the method. A third possible method is |
| | 89 | _INTL_REDIRECT_ASM, supported only by GCC. */ |
| 134 | | extern char *gettext (const char *__msgid) |
| 135 | | _INTL_ASM (libintl_gettext) |
| 136 | | _INTL_MAY_RETURN_STRING_ARG (1); |
| 137 | | #endif |
| 138 | | |
| 139 | | /* Look up MSGID in the DOMAINNAME message catalog for the current |
| 140 | | LC_MESSAGES locale. */ |
| 141 | | #ifdef _INTL_REDIRECT_INLINE |
| 142 | | extern char *libintl_dgettext (const char *__domainname, const char *__msgid) |
| 143 | | _INTL_MAY_RETURN_STRING_ARG (2); |
| 144 | | static inline char *dgettext (const char *__domainname, const char *__msgid) |
| 145 | | { |
| 146 | | return libintl_dgettext (__domainname, __msgid); |
| 147 | | } |
| | 133 | extern char *gettext (const char *__msgid) |
| | 134 | _INTL_ASM (libintl_gettext) |
| | 135 | _INTL_MAY_RETURN_STRING_ARG (1); |
| | 136 | #endif |
| | 137 | |
| | 138 | /* Look up MSGID in the DOMAINNAME message catalog for the current |
| | 139 | LC_MESSAGES locale. */ |
| | 140 | #ifdef _INTL_REDIRECT_INLINE |
| | 141 | extern char *libintl_dgettext (const char *__domainname, const char *__msgid) |
| | 142 | _INTL_MAY_RETURN_STRING_ARG (2); |
| | 143 | static inline char *dgettext (const char *__domainname, const char *__msgid) |
| | 144 | { |
| | 145 | return libintl_dgettext (__domainname, __msgid); |
| | 146 | } |
| 152 | | extern char *dgettext (const char *__domainname, const char *__msgid) |
| 153 | | _INTL_ASM (libintl_dgettext) |
| 154 | | _INTL_MAY_RETURN_STRING_ARG (2); |
| 155 | | #endif |
| 156 | | |
| 157 | | /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY |
| 158 | | locale. */ |
| 159 | | #ifdef _INTL_REDIRECT_INLINE |
| 160 | | extern char *libintl_dcgettext (const char *__domainname, const char *__msgid, |
| 161 | | int __category) |
| 162 | | _INTL_MAY_RETURN_STRING_ARG (2); |
| 163 | | static inline char *dcgettext (const char *__domainname, const char *__msgid, |
| 164 | | int __category) |
| 165 | | { |
| 166 | | return libintl_dcgettext (__domainname, __msgid, __category); |
| 167 | | } |
| | 151 | extern char *dgettext (const char *__domainname, const char *__msgid) |
| | 152 | _INTL_ASM (libintl_dgettext) |
| | 153 | _INTL_MAY_RETURN_STRING_ARG (2); |
| | 154 | #endif |
| | 155 | |
| | 156 | /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY |
| | 157 | locale. */ |
| | 158 | #ifdef _INTL_REDIRECT_INLINE |
| | 159 | extern char *libintl_dcgettext (const char *__domainname, const char *__msgid, |
| | 160 | int __category) |
| | 161 | _INTL_MAY_RETURN_STRING_ARG (2); |
| | 162 | static inline char *dcgettext (const char *__domainname, const char *__msgid, |
| | 163 | int __category) |
| | 164 | { |
| | 165 | return libintl_dcgettext (__domainname, __msgid, __category); |
| | 166 | } |
| 172 | | extern char *dcgettext (const char *__domainname, const char *__msgid, |
| 173 | | int __category) |
| 174 | | _INTL_ASM (libintl_dcgettext) |
| 175 | | _INTL_MAY_RETURN_STRING_ARG (2); |
| 176 | | #endif |
| 177 | | |
| 178 | | |
| 179 | | /* Similar to `gettext' but select the plural form corresponding to the |
| 180 | | number N. */ |
| 181 | | #ifdef _INTL_REDIRECT_INLINE |
| 182 | | extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2, |
| 183 | | unsigned long int __n) |
| 184 | | _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); |
| 185 | | static inline char *ngettext (const char *__msgid1, const char *__msgid2, |
| 186 | | unsigned long int __n) |
| 187 | | { |
| 188 | | return libintl_ngettext (__msgid1, __msgid2, __n); |
| 189 | | } |
| | 171 | extern char *dcgettext (const char *__domainname, const char *__msgid, |
| | 172 | int __category) |
| | 173 | _INTL_ASM (libintl_dcgettext) |
| | 174 | _INTL_MAY_RETURN_STRING_ARG (2); |
| | 175 | #endif |
| | 176 | |
| | 177 | |
| | 178 | /* Similar to `gettext' but select the plural form corresponding to the |
| | 179 | number N. */ |
| | 180 | #ifdef _INTL_REDIRECT_INLINE |
| | 181 | extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2, |
| | 182 | unsigned long int __n) |
| | 183 | _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); |
| | 184 | static inline char *ngettext (const char *__msgid1, const char *__msgid2, |
| | 185 | unsigned long int __n) |
| | 186 | { |
| | 187 | return libintl_ngettext (__msgid1, __msgid2, __n); |
| | 188 | } |
| 194 | | extern char *ngettext (const char *__msgid1, const char *__msgid2, |
| 195 | | unsigned long int __n) |
| 196 | | _INTL_ASM (libintl_ngettext) |
| 197 | | _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); |
| 198 | | #endif |
| 199 | | |
| 200 | | /* Similar to `dgettext' but select the plural form corresponding to the |
| 201 | | number N. */ |
| 202 | | #ifdef _INTL_REDIRECT_INLINE |
| 203 | | extern char *libintl_dngettext (const char *__domainname, const char *__msgid1, |
| 204 | | const char *__msgid2, unsigned long int __n) |
| 205 | | _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
| 206 | | static inline char *dngettext (const char *__domainname, const char *__msgid1, |
| 207 | | const char *__msgid2, unsigned long int __n) |
| 208 | | { |
| 209 | | return libintl_dngettext (__domainname, __msgid1, __msgid2, __n); |
| 210 | | } |
| | 193 | extern char *ngettext (const char *__msgid1, const char *__msgid2, |
| | 194 | unsigned long int __n) |
| | 195 | _INTL_ASM (libintl_ngettext) |
| | 196 | _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); |
| | 197 | #endif |
| | 198 | |
| | 199 | /* Similar to `dgettext' but select the plural form corresponding to the |
| | 200 | number N. */ |
| | 201 | #ifdef _INTL_REDIRECT_INLINE |
| | 202 | extern char *libintl_dngettext (const char *__domainname, const char *__msgid1, |
| | 203 | const char *__msgid2, unsigned long int __n) |
| | 204 | _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
| | 205 | static inline char *dngettext (const char *__domainname, const char *__msgid1, |
| | 206 | const char *__msgid2, unsigned long int __n) |
| | 207 | { |
| | 208 | return libintl_dngettext (__domainname, __msgid1, __msgid2, __n); |
| | 209 | } |
| 215 | | extern char *dngettext (const char *__domainname, |
| 216 | | const char *__msgid1, const char *__msgid2, |
| 217 | | unsigned long int __n) |
| 218 | | _INTL_ASM (libintl_dngettext) |
| 219 | | _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
| 220 | | #endif |
| 221 | | |
| 222 | | /* Similar to `dcgettext' but select the plural form corresponding to the |
| 223 | | number N. */ |
| 224 | | #ifdef _INTL_REDIRECT_INLINE |
| 225 | | extern char *libintl_dcngettext (const char *__domainname, |
| 226 | | const char *__msgid1, const char *__msgid2, |
| 227 | | unsigned long int __n, int __category) |
| 228 | | _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
| 229 | | static inline char *dcngettext (const char *__domainname, |
| 230 | | const char *__msgid1, const char *__msgid2, |
| 231 | | unsigned long int __n, int __category) |
| 232 | | { |
| 233 | | return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category); |
| 234 | | } |
| | 214 | extern char *dngettext (const char *__domainname, |
| | 215 | const char *__msgid1, const char *__msgid2, |
| | 216 | unsigned long int __n) |
| | 217 | _INTL_ASM (libintl_dngettext) |
| | 218 | _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
| | 219 | #endif |
| | 220 | |
| | 221 | /* Similar to `dcgettext' but select the plural form corresponding to the |
| | 222 | number N. */ |
| | 223 | #ifdef _INTL_REDIRECT_INLINE |
| | 224 | extern char *libintl_dcngettext (const char *__domainname, |
| | 225 | const char *__msgid1, const char *__msgid2, |
| | 226 | unsigned long int __n, int __category) |
| | 227 | _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
| | 228 | static inline char *dcngettext (const char *__domainname, |
| | 229 | const char *__msgid1, const char *__msgid2, |
| | 230 | unsigned long int __n, int __category) |
| | 231 | { |
| | 232 | return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category); |
| | 233 | } |
| 239 | | extern char *dcngettext (const char *__domainname, |
| 240 | | const char *__msgid1, const char *__msgid2, |
| 241 | | unsigned long int __n, int __category) |
| 242 | | _INTL_ASM (libintl_dcngettext) |
| 243 | | _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
| 244 | | #endif |
| 245 | | |
| 246 | | |
| 247 | | |
| 248 | | /* Set the current default message catalog to DOMAINNAME. |
| 249 | | If DOMAINNAME is null, return the current default. |
| 250 | | If DOMAINNAME is "", reset to the default of "messages". */ |
| 251 | | #ifdef _INTL_REDIRECT_INLINE |
| 252 | | extern char *libintl_textdomain (const char *__domainname); |
| 253 | | static inline char *textdomain (const char *__domainname) |
| 254 | | { |
| 255 | | return libintl_textdomain (__domainname); |
| 256 | | } |
| | 238 | extern char *dcngettext (const char *__domainname, |
| | 239 | const char *__msgid1, const char *__msgid2, |
| | 240 | unsigned long int __n, int __category) |
| | 241 | _INTL_ASM (libintl_dcngettext) |
| | 242 | _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
| | 243 | #endif |
| | 244 | |
| | 245 | |
| | 246 | |
| | 247 | /* Set the current default message catalog to DOMAINNAME. |
| | 248 | If DOMAINNAME is null, return the current default. |
| | 249 | If DOMAINNAME is "", reset to the default of "messages". */ |
| | 250 | #ifdef _INTL_REDIRECT_INLINE |
| | 251 | extern char *libintl_textdomain (const char *__domainname); |
| | 252 | static inline char *textdomain (const char *__domainname) |
| | 253 | { |
| | 254 | return libintl_textdomain (__domainname); |
| | 255 | } |
| 261 | | extern char *textdomain (const char *__domainname) |
| 262 | | _INTL_ASM (libintl_textdomain); |
| 263 | | #endif |
| 264 | | |
| 265 | | /* Specify that the DOMAINNAME message catalog will be found |
| 266 | | in DIRNAME rather than in the system locale data base. */ |
| 267 | | #ifdef _INTL_REDIRECT_INLINE |
| 268 | | extern char *libintl_bindtextdomain (const char *__domainname, |
| 269 | | const char *__dirname); |
| 270 | | static inline char *bindtextdomain (const char *__domainname, |
| 271 | | const char *__dirname) |
| 272 | | { |
| 273 | | return libintl_bindtextdomain (__domainname, __dirname); |
| 274 | | } |
| | 260 | extern char *textdomain (const char *__domainname) |
| | 261 | _INTL_ASM (libintl_textdomain); |
| | 262 | #endif |
| | 263 | |
| | 264 | /* Specify that the DOMAINNAME message catalog will be found |
| | 265 | in DIRNAME rather than in the system locale data base. */ |
| | 266 | #ifdef _INTL_REDIRECT_INLINE |
| | 267 | extern char *libintl_bindtextdomain (const char *__domainname, |
| | 268 | const char *__dirname); |
| | 269 | static inline char *bindtextdomain (const char *__domainname, |
| | 270 | const char *__dirname) |
| | 271 | { |
| | 272 | return libintl_bindtextdomain (__domainname, __dirname); |
| | 273 | } |
| 279 | | extern char *bindtextdomain (const char *__domainname, const char *__dirname) |
| 280 | | _INTL_ASM (libintl_bindtextdomain); |
| 281 | | #endif |
| 282 | | |
| 283 | | /* Specify the character encoding in which the messages from the |
| 284 | | DOMAINNAME message catalog will be returned. */ |
| 285 | | #ifdef _INTL_REDIRECT_INLINE |
| 286 | | extern char *libintl_bind_textdomain_codeset (const char *__domainname, |
| 287 | | const char *__codeset); |
| 288 | | static inline char *bind_textdomain_codeset (const char *__domainname, |
| 289 | | const char *__codeset) |
| 290 | | { |
| 291 | | return libintl_bind_textdomain_codeset (__domainname, __codeset); |
| 292 | | } |
| | 278 | extern char *bindtextdomain (const char *__domainname, const char *__dirname) |
| | 279 | _INTL_ASM (libintl_bindtextdomain); |
| | 280 | #endif |
| | 281 | |
| | 282 | /* Specify the character encoding in which the messages from the |
| | 283 | DOMAINNAME message catalog will be returned. */ |
| | 284 | #ifdef _INTL_REDIRECT_INLINE |
| | 285 | extern char *libintl_bind_textdomain_codeset (const char *__domainname, |
| | 286 | const char *__codeset); |
| | 287 | static inline char *bind_textdomain_codeset (const char *__domainname, |
| | 288 | const char *__codeset) |
| | 289 | { |
| | 290 | return libintl_bind_textdomain_codeset (__domainname, __codeset); |
| | 291 | } |
| 297 | | extern char *bind_textdomain_codeset (const char *__domainname, |
| 298 | | const char *__codeset) |
| 299 | | _INTL_ASM (libintl_bind_textdomain_codeset); |
| 300 | | #endif |
| 301 | | |
| 302 | | |
| 303 | | |
| 304 | | /* Support for format strings with positions in *printf(), following the |
| 305 | | POSIX/XSI specification. |
| 306 | | Note: These replacements for the *printf() functions are visible only |
| 307 | | in source files that #include <libintl.h> or #include "gettext.h". |
| 308 | | Packages that use *printf() in source files that don't refer to _() |
| 309 | | or gettext() but for which the format string could be the return value |
| 310 | | of _() or gettext() need to add this #include. Oh well. */ |
| 311 | | |
| 312 | | #if 0 |
| | 296 | extern char *bind_textdomain_codeset (const char *__domainname, |
| | 297 | const char *__codeset) |
| | 298 | _INTL_ASM (libintl_bind_textdomain_codeset); |
| | 299 | #endif |
| | 300 | |
| | 301 | |
| | 302 | |
| | 303 | /* Support for format strings with positions in *printf(), following the |
| | 304 | POSIX/XSI specification. |
| | 305 | Note: These replacements for the *printf() functions are visible only |
| | 306 | in source files that #include <libintl.h> or #include "gettext.h". |
| | 307 | Packages that use *printf() in source files that don't refer to _() |
| | 308 | or gettext() but for which the format string could be the return value |
| | 309 | of _() or gettext() need to add this #include. Oh well. */ |
| | 310 | |
| | 311 | #if !0 |
| 431 | | WIDE_LIBINTL_STATIC_INLINE |
| 432 | | const wchar_t* wgettext_(const char* msgid, const wchar_t* wmsgid) { |
| 433 | | const char* translated = gettext(msgid); |
| 434 | | return translated != msgid ? (const wchar_t*)translated : wmsgid; |
| 435 | | } |
| 436 | | |
| 437 | | WIDE_LIBINTL_STATIC_INLINE |
| 438 | | const wchar_t* dwgettext_(const char *domainname, const char* msgid, const wchar_t* wmsgid) { |
| 439 | | const char* translated = dgettext(domainname, msgid); |
| 440 | | return translated != msgid ? (const wchar_t*)translated : wmsgid; |
| 441 | | } |
| 442 | | |
| 443 | | WIDE_LIBINTL_STATIC_INLINE |
| 444 | | const wchar_t* dcwgettext_(const char *domainname, const char* msgid, int category, const wchar_t* wmsgid) { |
| 445 | | const char* translated = dcgettext(domainname, msgid, category); |
| 446 | | return translated != msgid ? (const wchar_t*)translated : wmsgid; |
| 447 | | } |
| 448 | | |
| 449 | | WIDE_LIBINTL_STATIC_INLINE |
| 450 | | const wchar_t* nwgettext_(const char* msgid1, const char* msgid2, unsigned long n, const wchar_t* wmsgid1, const wchar_t* wmsgid2) { |
| 451 | | const char* translated = ngettext(msgid1, msgid2, n); |
| 452 | | return translated == msgid1 ? wmsgid1 : (translated == msgid2 ? wmsgid2 : (const wchar_t*)translated); |
| 453 | | } |
| 454 | | |
| 455 | | WIDE_LIBINTL_STATIC_INLINE |
| 456 | | const wchar_t* dnwgettext_(const char* domainname, const char* msgid1, const char* msgid2, unsigned long n, const wchar_t* wmsgid1, const wchar_t* wmsgid2) { |
| 457 | | const char* translated = dngettext(domainname, msgid1, msgid2, n); |
| 458 | | return translated == msgid1 ? wmsgid1 : (translated == msgid2 ? wmsgid2 : (const wchar_t*)translated); |
| 459 | | } |
| 460 | | |
| 461 | | WIDE_LIBINTL_STATIC_INLINE |
| 462 | | const wchar_t* dcnwgettext_(const char* domainname, const char* msgid1, const char* msgid2, unsigned long n, const wchar_t* wmsgid1, const wchar_t* wmsgid2, int category) { |
| 463 | | const char* translated = dcngettext(domainname, msgid1, msgid2, n, category); |
| 464 | | return translated == msgid1 ? wmsgid1 : (translated == msgid2 ? wmsgid2 : (const wchar_t*)translated); |
| 465 | | } |
| | 428 | WCHAR_LIBINTL_STATIC_INLINE |
| | 429 | const wchar_t *wgettext_ (const char *msgid, const wchar_t *wmsgid) |
| | 430 | { |
| | 431 | const char *translated = gettext (msgid); |
| | 432 | return translated != msgid ? (const wchar_t *)translated : wmsgid; |
| | 433 | } |
| | 434 | |
| | 435 | WCHAR_LIBINTL_STATIC_INLINE |
| | 436 | const wchar_t *dwgettext_ (const char *domainname, const char *msgid, const wchar_t *wmsgid) |
| | 437 | { |
| | 438 | const char *translated = dgettext (domainname, msgid); |
| | 439 | return translated != msgid ? (const wchar_t *)translated : wmsgid; |
| | 440 | } |
| | 441 | |
| | 442 | WCHAR_LIBINTL_STATIC_INLINE |
| | 443 | const wchar_t *dcwgettext_ (const char *domainname, const char *msgid, int category, const wchar_t *wmsgid) |
| | 444 | { |
| | 445 | const char *translated = dcgettext (domainname, msgid, category); |
| | 446 | return translated != msgid ? (const wchar_t *)translated : wmsgid; |
| | 447 | } |
| | 448 | |
| | 449 | WCHAR_LIBINTL_STATIC_INLINE |
| | 450 | const wchar_t *nwgettext_ (const char *msgid1, const char *msgid2, unsigned long n, const wchar_t *wmsgid1, const wchar_t *wmsgid2) |
| | 451 | { |
| | 452 | const char *translated = ngettext (msgid1, msgid2, n); |
| | 453 | return translated == msgid1 ? wmsgid1 : (translated == msgid2 ? wmsgid2 : (const wchar_t *)translated); |
| | 454 | } |
| | 455 | |
| | 456 | WCHAR_LIBINTL_STATIC_INLINE |
| | 457 | const wchar_t *dnwgettext_ (const char *domainname, const char *msgid1, const char *msgid2, unsigned long n, const wchar_t *wmsgid1, const wchar_t *wmsgid2) |
| | 458 | { |
| | 459 | const char *translated = dngettext (domainname, msgid1, msgid2, n); |
| | 460 | return translated == msgid1 ? wmsgid1 : (translated == msgid2 ? wmsgid2 : (const wchar_t *)translated); |
| | 461 | } |
| | 462 | |
| | 463 | WCHAR_LIBINTL_STATIC_INLINE |
| | 464 | const wchar_t *dcnwgettext_ (const char *domainname, const char *msgid1, const char *msgid2, unsigned long n, const wchar_t *wmsgid1, const wchar_t *wmsgid2, int category) |
| | 465 | { |
| | 466 | const char *translated = dcngettext (domainname, msgid1, msgid2, n, category); |
| | 467 | return translated == msgid1 ? wmsgid1 : (translated == msgid2 ? wmsgid2 : (const wchar_t *)translated); |
| | 468 | } |
| 488 | | WIDE_LIBINTL_STATIC_INLINE |
| 489 | | const wchar_t* windows_wbindtextdomain(const char* domainname, const wchar_t* dirname16) { |
| 490 | | char* dirname8 = NULL; |
| 491 | | unsigned int num_elements = 0; |
| 492 | | |
| 493 | | num_elements = WideCharToMultiByte(CP_UTF8, 0, dirname16, -1, NULL, 0, 0, 0); |
| 494 | | if (num_elements == 0 || num_elements >= MAX_PATH) { |
| 495 | | return NULL; |
| 496 | | } |
| 497 | | |
| 498 | | #ifdef _MSC_VER |
| 499 | | if (num_elements > _ALLOCA_S_THRESHOLD) { |
| 500 | | return NULL; |
| 501 | | } |
| 502 | | __try { |
| 503 | | dirname8 = (char*)alloca(num_elements); |
| 504 | | } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ? |
| 505 | | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { |
| 506 | | return NULL; |
| 507 | | } |
| 508 | | #else |
| 509 | | dirname8 = (char*)alloca(num_elements); |
| 510 | | #endif |
| 511 | | if (0 == WideCharToMultiByte(CP_UTF8, 0, dirname16, -1, dirname8, num_elements, 0, 0)) { |
| 512 | | return NULL; |
| 513 | | } |
| 514 | | |
| 515 | | if (libintl_bindtextdomain(domainname, dirname8) == NULL) { |
| 516 | | return NULL; |
| 517 | | } |
| 518 | | |
| 519 | | return dirname16; |
| 520 | | } |
| 521 | | |
| 522 | | WIDE_LIBINTL_STATIC_INLINE |
| 523 | | const char* windows_bindtextdomain(const char* domainname, const char* dirname) { |
| 524 | | wchar_t* dirname16 = NULL; |
| 525 | | unsigned int num_elements = 0; |
| 526 | | UINT acp = 0; |
| 527 | | |
| 528 | | acp = GetACP(); |
| 529 | | |
| 530 | | num_elements = MultiByteToWideChar(acp, 0, dirname, -1, NULL, 0); |
| 531 | | if (num_elements == 0 || num_elements >= MAX_PATH) { |
| 532 | | return NULL; |
| 533 | | } |
| 534 | | |
| 535 | | #ifdef _MSC_VER |
| 536 | | { |
| 537 | | const size_t dirname16_bytes = num_elements*sizeof(wchar_t); |
| 538 | | if (dirname16_bytes > _ALLOCA_S_THRESHOLD) { |
| 539 | | return NULL; |
| 540 | | } |
| 541 | | __try { |
| 542 | | dirname16 = (wchar_t*)alloca(dirname16_bytes); |
| 543 | | } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ? |
| 544 | | EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { |
| 545 | | return NULL; |
| 546 | | } |
| 547 | | } |
| 548 | | #else |
| 549 | | dirname16 = (wchar_t*)alloca(num_elements*sizeof(wchar_t)); |
| 550 | | #endif |
| 551 | | if (0 == MultiByteToWideChar(acp, 0, dirname, -1, dirname16, num_elements)) { |
| 552 | | return NULL; |
| 553 | | } |
| 554 | | |
| 555 | | if (windows_wbindtextdomain(domainname, dirname16) == NULL) { |
| 556 | | return NULL; |
| 557 | | } |
| 558 | | |
| 559 | | return dirname; |
| 560 | | } |
| | 489 | /* http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx */ |
| | 490 | #define WCHAR_LIBINTL_MAX_PATH 33000 |
| | 491 | |
| | 492 | WCHAR_LIBINTL_STATIC_INLINE |
| | 493 | const wchar_t *windows_wbindtextdomain (const char *domainname, const wchar_t *dirname16) |
| | 494 | { |
| | 495 | char *dirname8 = NULL; |
| | 496 | unsigned int num_elements = 0; |
| | 497 | |
| | 498 | |
| | 499 | if (wcslen (dirname16) >= WCHAR_LIBINTL_MAX_PATH) |
| | 500 | { |
| | 501 | return NULL; |
| | 502 | } |
| | 503 | |
| | 504 | num_elements = WideCharToMultiByte (CP_UTF8, 0, dirname16, -1, NULL, 0, 0, 0); |
| | 505 | if (num_elements == 0) |
| | 506 | { |
| | 507 | return NULL; |
| | 508 | } |
| | 509 | |
| | 510 | dirname8 = (char *)malloc (num_elements); |
| | 511 | if (!dirname8) |
| | 512 | { |
| | 513 | return NULL; |
| | 514 | } |
| | 515 | |
| | 516 | if (0 == WideCharToMultiByte (CP_UTF8, 0, dirname16, -1, dirname8, num_elements, 0, 0)) |
| | 517 | { |
| | 518 | free (dirname8); |
| | 519 | return NULL; |
| | 520 | } |
| | 521 | |
| | 522 | if (libintl_bindtextdomain (domainname, dirname8) == NULL) |
| | 523 | { |
| | 524 | free (dirname8); |
| | 525 | return NULL; |
| | 526 | } |
| | 527 | |
| | 528 | free (dirname8); |
| | 529 | |
| | 530 | return dirname16; |
| | 531 | } |
| | 532 | |
| | 533 | WCHAR_LIBINTL_STATIC_INLINE |
| | 534 | const char *windows_bindtextdomain(const char *domainname, const char *dirname) |
| | 535 | { |
| | 536 | wchar_t *dirname16 = NULL; |
| | 537 | unsigned int num_elements = 0; |
| | 538 | UINT acp = 0; |
| | 539 | |
| | 540 | acp = GetACP (); |
| | 541 | |
| | 542 | num_elements = MultiByteToWideChar (acp, 0, dirname, -1, NULL, 0); |
| | 543 | if (num_elements == 0) |
| | 544 | { |
| | 545 | return NULL; |
| | 546 | } |
| | 547 | |
| | 548 | if (num_elements >= WCHAR_LIBINTL_MAX_PATH) |
| | 549 | { |
| | 550 | return NULL; |
| | 551 | } |
| | 552 | |
| | 553 | dirname16 = (wchar_t *)malloc (num_elements * sizeof(wchar_t)); |
| | 554 | |
| | 555 | if (0 == MultiByteToWideChar (acp, 0, dirname, -1, |
| | 556 | dirname16, num_elements)) |
| | 557 | { |
| | 558 | free (dirname16); |
| | 559 | return NULL; |
| | 560 | } |
| | 561 | |
| | 562 | if (windows_wbindtextdomain (domainname, dirname16) == NULL) |
| | 563 | { |
| | 564 | free (dirname16); |
| | 565 | return NULL; |
| | 566 | } |
| | 567 | |
| | 568 | free (dirname16); |
| | 569 | |
| | 570 | return dirname; |
| | 571 | } |