summaryrefslogtreecommitdiffstats
path: root/gl/gettext.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/gettext.h')
-rw-r--r--gl/gettext.h50
1 files changed, 31 insertions, 19 deletions
diff --git a/gl/gettext.h b/gl/gettext.h
index d0215715..d0462c47 100644
--- a/gl/gettext.h
+++ b/gl/gettext.h
@@ -1,25 +1,26 @@
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-2013 Free Software 2 Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2023 Free Software
3 Foundation, Inc. 3 Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU Lesser General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License along 15 You should have received a copy of the GNU Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _LIBGETTEXT_H 18#ifndef _LIBGETTEXT_H
19#define _LIBGETTEXT_H 1 19#define _LIBGETTEXT_H 1
20 20
21/* NLS can be disabled through the configure --disable-nls option. */ 21/* NLS can be disabled through the configure --disable-nls option
22#if ENABLE_NLS 22 or through "#define ENABLE NLS 0" before including this file. */
23#if defined ENABLE_NLS && ENABLE_NLS
23 24
24/* Get declarations of GNU message catalog functions. */ 25/* Get declarations of GNU message catalog functions. */
25# include <libintl.h> 26# include <libintl.h>
@@ -137,7 +138,7 @@
137#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ 138#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
138 npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) 139 npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
139 140
140#ifdef __GNUC__ 141#if defined __GNUC__ || defined __clang__
141__inline 142__inline
142#else 143#else
143#ifdef __cplusplus 144#ifdef __cplusplus
@@ -156,7 +157,7 @@ pgettext_aux (const char *domain,
156 return translation; 157 return translation;
157} 158}
158 159
159#ifdef __GNUC__ 160#if defined __GNUC__ || defined __clang__
160__inline 161__inline
161#else 162#else
162#ifdef __cplusplus 163#ifdef __cplusplus
@@ -183,8 +184,15 @@ npgettext_aux (const char *domain,
183 184
184#include <string.h> 185#include <string.h>
185 186
186#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \ 187/* GNULIB_NO_VLA can be defined to disable use of VLAs even if supported.
187 /* || __STDC_VERSION__ >= 199901L */ ) 188 This relates to the -Wvla and -Wvla-larger-than warnings, enabled in
189 the default GCC many warnings set. This allows programs to disable use
190 of VLAs, which may be unintended, or may be awkward to support portably,
191 or may have security implications due to non-deterministic stack usage. */
192
193#if (!defined GNULIB_NO_VLA \
194 && defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
195 && !defined __STDC_NO_VLA__)
188# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1 196# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
189#else 197#else
190# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0 198# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
@@ -199,7 +207,7 @@ npgettext_aux (const char *domain,
199#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ 207#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
200 dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) 208 dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
201 209
202#ifdef __GNUC__ 210#if defined __GNUC__ || defined __clang__
203__inline 211__inline
204#else 212#else
205#ifdef __cplusplus 213#ifdef __cplusplus
@@ -225,15 +233,17 @@ dcpgettext_expr (const char *domain,
225 if (msg_ctxt_id != NULL) 233 if (msg_ctxt_id != NULL)
226#endif 234#endif
227 { 235 {
236 int found_translation;
228 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); 237 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
229 msg_ctxt_id[msgctxt_len - 1] = '\004'; 238 msg_ctxt_id[msgctxt_len - 1] = '\004';
230 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); 239 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
231 translation = dcgettext (domain, msg_ctxt_id, category); 240 translation = dcgettext (domain, msg_ctxt_id, category);
241 found_translation = (translation != msg_ctxt_id);
232#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 242#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
233 if (msg_ctxt_id != buf) 243 if (msg_ctxt_id != buf)
234 free (msg_ctxt_id); 244 free (msg_ctxt_id);
235#endif 245#endif
236 if (translation != msg_ctxt_id) 246 if (found_translation)
237 return translation; 247 return translation;
238 } 248 }
239 return msgid; 249 return msgid;
@@ -244,7 +254,7 @@ dcpgettext_expr (const char *domain,
244#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ 254#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
245 dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) 255 dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
246 256
247#ifdef __GNUC__ 257#if defined __GNUC__ || defined __clang__
248__inline 258__inline
249#else 259#else
250#ifdef __cplusplus 260#ifdef __cplusplus
@@ -271,15 +281,17 @@ dcnpgettext_expr (const char *domain,
271 if (msg_ctxt_id != NULL) 281 if (msg_ctxt_id != NULL)
272#endif 282#endif
273 { 283 {
284 int found_translation;
274 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); 285 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
275 msg_ctxt_id[msgctxt_len - 1] = '\004'; 286 msg_ctxt_id[msgctxt_len - 1] = '\004';
276 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); 287 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
277 translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); 288 translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
289 found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
278#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 290#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
279 if (msg_ctxt_id != buf) 291 if (msg_ctxt_id != buf)
280 free (msg_ctxt_id); 292 free (msg_ctxt_id);
281#endif 293#endif
282 if (!(translation == msg_ctxt_id || translation == msgid_plural)) 294 if (found_translation)
283 return translation; 295 return translation;
284 } 296 }
285 return (n == 1 ? msgid : msgid_plural); 297 return (n == 1 ? msgid : msgid_plural);