diff options
Diffstat (limited to 'gl/gettext.h')
| -rw-r--r-- | gl/gettext.h | 114 |
1 files changed, 90 insertions, 24 deletions
diff --git a/gl/gettext.h b/gl/gettext.h index 39d5ae4d..0650abc9 100644 --- a/gl/gettext.h +++ b/gl/gettext.h | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | /* Convenience header for conditional use of GNU <libintl.h>. | 1 | /* Convenience header for conditional use of GNU <libintl.h>. |
| 2 | Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2024 Free Software | 2 | Copyright (C) 1995-2025 Free Software Foundation, Inc. |
| 3 | Foundation, Inc. | ||
| 4 | 3 | ||
| 5 | This file is free software: you can redistribute it and/or modify | 4 | This file is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU Lesser General Public License as | 5 | it under the terms of the GNU Lesser General Public License as |
| @@ -18,6 +17,7 @@ | |||
| 18 | #ifndef _LIBGETTEXT_H | 17 | #ifndef _LIBGETTEXT_H |
| 19 | #define _LIBGETTEXT_H 1 | 18 | #define _LIBGETTEXT_H 1 |
| 20 | 19 | ||
| 20 | |||
| 21 | /* NLS can be disabled through the configure --disable-nls option | 21 | /* NLS can be disabled through the configure --disable-nls option |
| 22 | or through "#define ENABLE NLS 0" before including this file. */ | 22 | or through "#define ENABLE NLS 0" before including this file. */ |
| 23 | #if defined ENABLE_NLS && ENABLE_NLS | 23 | #if defined ENABLE_NLS && ENABLE_NLS |
| @@ -45,32 +45,90 @@ | |||
| 45 | as well because people using "gettext.h" will not include <libintl.h>, | 45 | as well because people using "gettext.h" will not include <libintl.h>, |
| 46 | and also including <libintl.h> would fail on SunOS 4, whereas <locale.h> | 46 | and also including <libintl.h> would fail on SunOS 4, whereas <locale.h> |
| 47 | is OK. */ | 47 | is OK. */ |
| 48 | #if defined(__sun) | 48 | # if defined(__sun) |
| 49 | # include <locale.h> | 49 | # include <locale.h> |
| 50 | #endif | 50 | # endif |
| 51 | 51 | ||
| 52 | /* Many header files from the libstdc++ coming with g++ 3.3 or newer include | 52 | /* Many header files from the libstdc++ coming with g++ 3.3 or newer include |
| 53 | <libintl.h>, which chokes if dcgettext is defined as a macro. So include | 53 | <libintl.h>, which chokes if dcgettext is defined as a macro. So include |
| 54 | it now, to make later inclusions of <libintl.h> a NOP. */ | 54 | it now, to make later inclusions of <libintl.h> a NOP. */ |
| 55 | #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) | 55 | # if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) |
| 56 | # include <cstdlib> | 56 | # include <cstdlib> |
| 57 | # if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H | 57 | # if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H |
| 58 | # include <libintl.h> | 58 | # include <libintl.h> |
| 59 | # endif | ||
| 59 | # endif | 60 | # endif |
| 60 | #endif | ||
| 61 | 61 | ||
| 62 | /* Disabled NLS. | 62 | /* Disabled NLS. */ |
| 63 | The casts to 'const char *' serve the purpose of producing warnings | 63 | # if defined __GNUC__ && !defined __clang__ && !defined __cplusplus |
| 64 | for invalid uses of the value returned from these functions. | 64 | /* Use inline functions, to avoid warnings |
| 65 | On pre-ANSI systems without 'const', the config.h file is supposed to | 65 | warning: format not a string literal and no format arguments |
| 66 | contain "#define const". */ | 66 | that don't occur with enabled NLS. */ |
| 67 | # undef gettext | 67 | /* The return type 'const char *' serves the purpose of producing warnings |
| 68 | # define gettext(Msgid) ((const char *) (Msgid)) | 68 | for invalid uses of the value returned from these functions. */ |
| 69 | # undef dgettext | 69 | # if __GNUC__ >= 9 |
| 70 | # define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) | 70 | # pragma GCC diagnostic push |
| 71 | # undef dcgettext | 71 | # pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch" |
| 72 | # define dcgettext(Domainname, Msgid, Category) \ | 72 | # endif |
| 73 | ((void) (Category), dgettext (Domainname, Msgid)) | 73 | # if __GNUC__ + (__GNUC_MINOR__ >= 2) > 4 |
| 74 | __attribute__ ((__always_inline__, __gnu_inline__)) | ||
| 75 | # else | ||
| 76 | __attribute__ ((__always_inline__)) | ||
| 77 | # endif | ||
| 78 | extern inline | ||
| 79 | # if !defined(__sun) | ||
| 80 | const | ||
| 81 | # endif | ||
| 82 | char * | ||
| 83 | gettext (const char *msgid) | ||
| 84 | { | ||
| 85 | return msgid; | ||
| 86 | } | ||
| 87 | # if __GNUC__ + (__GNUC_MINOR__ >= 2) > 4 | ||
| 88 | __attribute__ ((__always_inline__, __gnu_inline__)) | ||
| 89 | # else | ||
| 90 | __attribute__ ((__always_inline__)) | ||
| 91 | # endif | ||
| 92 | extern inline | ||
| 93 | # if !defined(__sun) | ||
| 94 | const | ||
| 95 | # endif | ||
| 96 | char * | ||
| 97 | dgettext (const char *domain, const char *msgid) | ||
| 98 | { | ||
| 99 | (void) domain; | ||
| 100 | return msgid; | ||
| 101 | } | ||
| 102 | # if __GNUC__ + (__GNUC_MINOR__ >= 2) > 4 | ||
| 103 | __attribute__ ((__always_inline__, __gnu_inline__)) | ||
| 104 | # else | ||
| 105 | __attribute__ ((__always_inline__)) | ||
| 106 | # endif | ||
| 107 | extern inline | ||
| 108 | # if !defined(__sun) | ||
| 109 | const | ||
| 110 | # endif | ||
| 111 | char * | ||
| 112 | dcgettext (const char *domain, const char *msgid, int category) | ||
| 113 | { | ||
| 114 | (void) domain; | ||
| 115 | (void) category; | ||
| 116 | return msgid; | ||
| 117 | } | ||
| 118 | # if __GNUC__ >= 9 | ||
| 119 | # pragma GCC diagnostic pop | ||
| 120 | # endif | ||
| 121 | # else | ||
| 122 | /* The casts to 'const char *' serve the purpose of producing warnings | ||
| 123 | for invalid uses of the value returned from these functions. */ | ||
| 124 | # undef gettext | ||
| 125 | # define gettext(Msgid) ((const char *) (Msgid)) | ||
| 126 | # undef dgettext | ||
| 127 | # define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) | ||
| 128 | # undef dcgettext | ||
| 129 | # define dcgettext(Domainname, Msgid, Category) \ | ||
| 130 | ((void) (Category), dgettext (Domainname, Msgid)) | ||
| 131 | # endif | ||
| 74 | # undef ngettext | 132 | # undef ngettext |
| 75 | # define ngettext(Msgid1, Msgid2, N) \ | 133 | # define ngettext(Msgid1, Msgid2, N) \ |
| 76 | ((N) == 1 \ | 134 | ((N) == 1 \ |
| @@ -93,12 +151,14 @@ | |||
| 93 | 151 | ||
| 94 | #endif | 152 | #endif |
| 95 | 153 | ||
| 154 | |||
| 96 | /* Prefer gnulib's setlocale override over libintl's setlocale override. */ | 155 | /* Prefer gnulib's setlocale override over libintl's setlocale override. */ |
| 97 | #ifdef GNULIB_defined_setlocale | 156 | #ifdef GNULIB_defined_setlocale |
| 98 | # undef setlocale | 157 | # undef setlocale |
| 99 | # define setlocale rpl_setlocale | 158 | # define setlocale rpl_setlocale |
| 100 | #endif | 159 | #endif |
| 101 | 160 | ||
| 161 | |||
| 102 | /* A pseudo function call that serves as a marker for the automated | 162 | /* A pseudo function call that serves as a marker for the automated |
| 103 | extraction of messages, but does not call gettext(). The run-time | 163 | extraction of messages, but does not call gettext(). The run-time |
| 104 | translation is done at a different place in the code. | 164 | translation is done at a different place in the code. |
| @@ -108,6 +168,7 @@ | |||
| 108 | initializer for static 'char[]' or 'const char[]' variables. */ | 168 | initializer for static 'char[]' or 'const char[]' variables. */ |
| 109 | #define gettext_noop(String) String | 169 | #define gettext_noop(String) String |
| 110 | 170 | ||
| 171 | |||
| 111 | /* The separator between msgctxt and msgid in a .mo file. */ | 172 | /* The separator between msgctxt and msgid in a .mo file. */ |
| 112 | #define GETTEXT_CONTEXT_GLUE "\004" | 173 | #define GETTEXT_CONTEXT_GLUE "\004" |
| 113 | 174 | ||
| @@ -115,6 +176,9 @@ | |||
| 115 | MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be | 176 | MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be |
| 116 | short and rarely need to change. | 177 | short and rarely need to change. |
| 117 | The letter 'p' stands for 'particular' or 'special'. */ | 178 | The letter 'p' stands for 'particular' or 'special'. */ |
| 179 | |||
| 180 | #include <locale.h> /* for LC_MESSAGES */ | ||
| 181 | |||
| 118 | #ifdef DEFAULT_TEXT_DOMAIN | 182 | #ifdef DEFAULT_TEXT_DOMAIN |
| 119 | # define pgettext(Msgctxt, Msgid) \ | 183 | # define pgettext(Msgctxt, Msgid) \ |
| 120 | pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) | 184 | pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) |
| @@ -178,11 +242,12 @@ npgettext_aux (const char *domain, | |||
| 178 | return translation; | 242 | return translation; |
| 179 | } | 243 | } |
| 180 | 244 | ||
| 245 | |||
| 181 | /* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID | 246 | /* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID |
| 182 | can be arbitrary expressions. But for string literals these macros are | 247 | can be arbitrary expressions. But for string literals these macros are |
| 183 | less efficient than those above. */ | 248 | less efficient than those above. */ |
| 184 | 249 | ||
| 185 | #include <string.h> | 250 | #include <string.h> /* for memcpy */ |
| 186 | 251 | ||
| 187 | /* GNULIB_NO_VLA can be defined to disable use of VLAs even if supported. | 252 | /* GNULIB_NO_VLA can be defined to disable use of VLAs even if supported. |
| 188 | This relates to the -Wvla and -Wvla-larger-than warnings, enabled in | 253 | This relates to the -Wvla and -Wvla-larger-than warnings, enabled in |
| @@ -199,7 +264,7 @@ npgettext_aux (const char *domain, | |||
| 199 | #endif | 264 | #endif |
| 200 | 265 | ||
| 201 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS | 266 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS |
| 202 | #include <stdlib.h> | 267 | # include <stdlib.h> /* for malloc, free */ |
| 203 | #endif | 268 | #endif |
| 204 | 269 | ||
| 205 | #define pgettext_expr(Msgctxt, Msgid) \ | 270 | #define pgettext_expr(Msgctxt, Msgid) \ |
| @@ -297,4 +362,5 @@ dcnpgettext_expr (const char *domain, | |||
| 297 | return (n == 1 ? msgid : msgid_plural); | 362 | return (n == 1 ? msgid : msgid_plural); |
| 298 | } | 363 | } |
| 299 | 364 | ||
| 365 | |||
| 300 | #endif /* _LIBGETTEXT_H */ | 366 | #endif /* _LIBGETTEXT_H */ |
