Coverage Report

Created: 2025-07-12 06:05

/src/gdbm/src/gettext.h
Line
Count
Source (jump to first uncovered line)
1
/* Convenience header for conditional use of GNU <libintl.h>.
2
   Copyright (C) 1995-2025 Free Software Foundation, Inc.
3
4
   This program is free software; you can redistribute it and/or modify it
5
   under the terms of the GNU General Public License as published
6
   by the Free Software Foundation; either version 3, 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 GNU
12
   Library General Public License for more details.
13
14
   You should have received a copy of the GNU General Public
15
   License along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17
#ifndef _LIBGETTEXT_H
18
#define _LIBGETTEXT_H 1
19
20
/* NLS can be disabled through the configure --disable-nls option.  */
21
#if ENABLE_NLS
22
23
/* Get declarations of GNU message catalog functions.  */
24
# include <libintl.h>
25
26
/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
27
   the gettext() and ngettext() macros.  This is an alternative to calling
28
   textdomain(), and is useful for libraries.  */
29
# ifdef DEFAULT_TEXT_DOMAIN
30
#  undef gettext
31
#  define gettext(Msgid) \
32
     dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
33
#  undef ngettext
34
#  define ngettext(Msgid1, Msgid2, N) \
35
     dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
36
# endif
37
38
#else
39
40
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
41
   chokes if dcgettext is defined as a macro.  So include it now, to make
42
   later inclusions of <locale.h> a NOP.  We don't include <libintl.h>
43
   as well because people using "gettext.h" will not include <libintl.h>,
44
   and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
45
   is OK.  */
46
#if defined(__sun)
47
# include <locale.h>
48
#endif
49
50
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
51
   <libintl.h>, which chokes if dcgettext is defined as a macro.  So include
52
   it now, to make later inclusions of <libintl.h> a NOP.  */
53
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
54
# include <cstdlib>
55
# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
56
#  include <libintl.h>
57
# endif
58
#endif
59
60
/* Disabled NLS.
61
   The casts to 'const char *' serve the purpose of producing warnings
62
   for invalid uses of the value returned from these functions.
63
   On pre-ANSI systems without 'const', the config.h file is supposed to
64
   contain "#define const".  */
65
# undef gettext
66
235k
# define gettext(Msgid) ((const char *) (Msgid))
67
# undef dgettext
68
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
69
# undef dcgettext
70
# define dcgettext(Domainname, Msgid, Category) \
71
    ((void) (Category), dgettext (Domainname, Msgid))
72
# undef ngettext
73
# define ngettext(Msgid1, Msgid2, N) \
74
134
    ((N) == 1 \
75
134
     ? ((void) (Msgid2), (const char *) (Msgid1)) \
76
134
     : ((void) (Msgid1), (const char *) (Msgid2)))
77
# undef dngettext
78
# define dngettext(Domainname, Msgid1, Msgid2, N) \
79
    ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
80
# undef dcngettext
81
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
82
    ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
83
# undef textdomain
84
# define textdomain(Domainname) ((const char *) (Domainname))
85
# undef bindtextdomain
86
# define bindtextdomain(Domainname, Dirname) \
87
    ((void) (Domainname), (const char *) (Dirname))
88
# undef bind_textdomain_codeset
89
# define bind_textdomain_codeset(Domainname, Codeset) \
90
    ((void) (Domainname), (const char *) (Codeset))
91
92
#endif
93
94
/* A pseudo function call that serves as a marker for the automated
95
   extraction of messages, but does not call gettext().  The run-time
96
   translation is done at a different place in the code.
97
   The argument, String, should be a literal string.  Concatenated strings
98
   and other string expressions won't work.
99
   The macro's expansion is not parenthesized, so that it is suitable as
100
   initializer for static 'char[]' or 'const char[]' variables.  */
101
#define gettext_noop(String) String
102
103
/* The separator between msgctxt and msgid in a .mo file.  */
104
#define GETTEXT_CONTEXT_GLUE "\004"
105
106
/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
107
   MSGID.  MSGCTXT and MSGID must be string literals.  MSGCTXT should be
108
   short and rarely need to change.
109
   The letter 'p' stands for 'particular' or 'special'.  */
110
#ifdef DEFAULT_TEXT_DOMAIN
111
# define pgettext(Msgctxt, Msgid) \
112
   pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
113
#else
114
# define pgettext(Msgctxt, Msgid) \
115
   pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
116
#endif
117
#define dpgettext(Domainname, Msgctxt, Msgid) \
118
  pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
119
#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
120
  pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
121
#ifdef DEFAULT_TEXT_DOMAIN
122
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
123
   npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
124
#else
125
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
126
   npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
127
#endif
128
#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
129
  npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
130
#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
131
  npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
132
133
#ifdef __GNUC__
134
__inline
135
#else
136
#ifdef __cplusplus
137
inline
138
#endif
139
#endif
140
static const char *
141
pgettext_aux (const char *domain,
142
              const char *msg_ctxt_id, const char *msgid,
143
              int category)
144
0
{
145
0
  const char *translation = dcgettext (domain, msg_ctxt_id, category);
146
0
  if (translation == msg_ctxt_id)
147
0
    return msgid;
148
0
  else
149
0
    return translation;
150
0
}
Unexecuted instantiation: gdbm_fuzzer.c:pgettext_aux
Unexecuted instantiation: mem.c:pgettext_aux
Unexecuted instantiation: progname.c:pgettext_aux
Unexecuted instantiation: gram.c:pgettext_aux
Unexecuted instantiation: lex.c:pgettext_aux
Unexecuted instantiation: gdbmshell.c:pgettext_aux
Unexecuted instantiation: var.c:pgettext_aux
Unexecuted instantiation: util.c:pgettext_aux
Unexecuted instantiation: wordwrap.c:pgettext_aux
Unexecuted instantiation: err.c:pgettext_aux
Unexecuted instantiation: pagerfile.c:pgettext_aux
Unexecuted instantiation: datconv.c:pgettext_aux
Unexecuted instantiation: input-file.c:pgettext_aux
Unexecuted instantiation: input-null.c:pgettext_aux
Unexecuted instantiation: gdbmclose.c:pgettext_aux
Unexecuted instantiation: gdbmcount.c:pgettext_aux
Unexecuted instantiation: gdbmdelete.c:pgettext_aux
Unexecuted instantiation: gdbmdump.c:pgettext_aux
Unexecuted instantiation: gdbmerrno.c:pgettext_aux
Unexecuted instantiation: gdbmexp.c:pgettext_aux
Unexecuted instantiation: gdbmfdesc.c:pgettext_aux
Unexecuted instantiation: gdbmfetch.c:pgettext_aux
Unexecuted instantiation: gdbmload.c:pgettext_aux
Unexecuted instantiation: gdbmopen.c:pgettext_aux
Unexecuted instantiation: gdbmimp.c:pgettext_aux
Unexecuted instantiation: gdbmreorg.c:pgettext_aux
Unexecuted instantiation: gdbmseq.c:pgettext_aux
Unexecuted instantiation: gdbmsetopt.c:pgettext_aux
Unexecuted instantiation: gdbmstore.c:pgettext_aux
Unexecuted instantiation: gdbmsync.c:pgettext_aux
Unexecuted instantiation: avail.c:pgettext_aux
Unexecuted instantiation: base64.c:pgettext_aux
Unexecuted instantiation: bucket.c:pgettext_aux
Unexecuted instantiation: falloc.c:pgettext_aux
Unexecuted instantiation: findkey.c:pgettext_aux
Unexecuted instantiation: fullio.c:pgettext_aux
Unexecuted instantiation: hash.c:pgettext_aux
Unexecuted instantiation: lock.c:pgettext_aux
Unexecuted instantiation: mmap.c:pgettext_aux
Unexecuted instantiation: recover.c:pgettext_aux
Unexecuted instantiation: update.c:pgettext_aux
Unexecuted instantiation: debug.c:pgettext_aux
151
152
#ifdef __GNUC__
153
__inline
154
#else
155
#ifdef __cplusplus
156
inline
157
#endif
158
#endif
159
static const char *
160
npgettext_aux (const char *domain,
161
               const char *msg_ctxt_id, const char *msgid,
162
               const char *msgid_plural, unsigned long int n,
163
               int category)
164
0
{
165
0
  const char *translation =
166
0
    dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
167
0
  if (translation == msg_ctxt_id || translation == msgid_plural)
168
0
    return (n == 1 ? msgid : msgid_plural);
169
0
  else
170
0
    return translation;
171
0
}
Unexecuted instantiation: gdbm_fuzzer.c:npgettext_aux
Unexecuted instantiation: mem.c:npgettext_aux
Unexecuted instantiation: progname.c:npgettext_aux
Unexecuted instantiation: gram.c:npgettext_aux
Unexecuted instantiation: lex.c:npgettext_aux
Unexecuted instantiation: gdbmshell.c:npgettext_aux
Unexecuted instantiation: var.c:npgettext_aux
Unexecuted instantiation: util.c:npgettext_aux
Unexecuted instantiation: wordwrap.c:npgettext_aux
Unexecuted instantiation: err.c:npgettext_aux
Unexecuted instantiation: pagerfile.c:npgettext_aux
Unexecuted instantiation: datconv.c:npgettext_aux
Unexecuted instantiation: input-file.c:npgettext_aux
Unexecuted instantiation: input-null.c:npgettext_aux
Unexecuted instantiation: gdbmclose.c:npgettext_aux
Unexecuted instantiation: gdbmcount.c:npgettext_aux
Unexecuted instantiation: gdbmdelete.c:npgettext_aux
Unexecuted instantiation: gdbmdump.c:npgettext_aux
Unexecuted instantiation: gdbmerrno.c:npgettext_aux
Unexecuted instantiation: gdbmexp.c:npgettext_aux
Unexecuted instantiation: gdbmfdesc.c:npgettext_aux
Unexecuted instantiation: gdbmfetch.c:npgettext_aux
Unexecuted instantiation: gdbmload.c:npgettext_aux
Unexecuted instantiation: gdbmopen.c:npgettext_aux
Unexecuted instantiation: gdbmimp.c:npgettext_aux
Unexecuted instantiation: gdbmreorg.c:npgettext_aux
Unexecuted instantiation: gdbmseq.c:npgettext_aux
Unexecuted instantiation: gdbmsetopt.c:npgettext_aux
Unexecuted instantiation: gdbmstore.c:npgettext_aux
Unexecuted instantiation: gdbmsync.c:npgettext_aux
Unexecuted instantiation: avail.c:npgettext_aux
Unexecuted instantiation: base64.c:npgettext_aux
Unexecuted instantiation: bucket.c:npgettext_aux
Unexecuted instantiation: falloc.c:npgettext_aux
Unexecuted instantiation: findkey.c:npgettext_aux
Unexecuted instantiation: fullio.c:npgettext_aux
Unexecuted instantiation: hash.c:npgettext_aux
Unexecuted instantiation: lock.c:npgettext_aux
Unexecuted instantiation: mmap.c:npgettext_aux
Unexecuted instantiation: recover.c:npgettext_aux
Unexecuted instantiation: update.c:npgettext_aux
Unexecuted instantiation: debug.c:npgettext_aux
172
173
/* The same thing extended for non-constant arguments.  Here MSGCTXT and MSGID
174
   can be arbitrary expressions.  But for string literals these macros are
175
   less efficient than those above.  */
176
177
#include <string.h>
178
179
#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
180
  (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
181
   /* || __STDC_VERSION__ >= 199901L */ )
182
183
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
184
#include <stdlib.h>
185
#endif
186
187
#define pgettext_expr(Msgctxt, Msgid) \
188
  dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
189
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
190
  dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
191
192
#ifdef __GNUC__
193
__inline
194
#else
195
#ifdef __cplusplus
196
inline
197
#endif
198
#endif
199
static const char *
200
dcpgettext_expr (const char *domain,
201
                 const char *msgctxt, const char *msgid,
202
                 int category)
203
0
{
204
0
  size_t msgctxt_len = strlen (msgctxt) + 1;
205
0
  size_t msgid_len = strlen (msgid) + 1;
206
0
  const char *translation;
207
0
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
208
0
  char msg_ctxt_id[msgctxt_len + msgid_len];
209
0
#else
210
0
  char buf[1024];
211
0
  char *msg_ctxt_id =
212
0
    (msgctxt_len + msgid_len <= sizeof (buf)
213
0
     ? buf
214
0
     : (char *) malloc (msgctxt_len + msgid_len));
215
0
  if (msg_ctxt_id != NULL)
216
0
#endif
217
0
    {
218
0
      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
219
0
      msg_ctxt_id[msgctxt_len - 1] = '\004';
220
0
      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
221
0
      translation = dcgettext (domain, msg_ctxt_id, category);
222
0
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
223
0
      if (msg_ctxt_id != buf)
224
0
        free (msg_ctxt_id);
225
0
#endif
226
0
      if (translation != msg_ctxt_id)
227
0
        return translation;
228
0
    }
229
0
  return msgid;
230
0
}
Unexecuted instantiation: gdbm_fuzzer.c:dcpgettext_expr
Unexecuted instantiation: mem.c:dcpgettext_expr
Unexecuted instantiation: progname.c:dcpgettext_expr
Unexecuted instantiation: gram.c:dcpgettext_expr
Unexecuted instantiation: lex.c:dcpgettext_expr
Unexecuted instantiation: gdbmshell.c:dcpgettext_expr
Unexecuted instantiation: var.c:dcpgettext_expr
Unexecuted instantiation: util.c:dcpgettext_expr
Unexecuted instantiation: wordwrap.c:dcpgettext_expr
Unexecuted instantiation: err.c:dcpgettext_expr
Unexecuted instantiation: pagerfile.c:dcpgettext_expr
Unexecuted instantiation: datconv.c:dcpgettext_expr
Unexecuted instantiation: input-file.c:dcpgettext_expr
Unexecuted instantiation: input-null.c:dcpgettext_expr
Unexecuted instantiation: gdbmclose.c:dcpgettext_expr
Unexecuted instantiation: gdbmcount.c:dcpgettext_expr
Unexecuted instantiation: gdbmdelete.c:dcpgettext_expr
Unexecuted instantiation: gdbmdump.c:dcpgettext_expr
Unexecuted instantiation: gdbmerrno.c:dcpgettext_expr
Unexecuted instantiation: gdbmexp.c:dcpgettext_expr
Unexecuted instantiation: gdbmfdesc.c:dcpgettext_expr
Unexecuted instantiation: gdbmfetch.c:dcpgettext_expr
Unexecuted instantiation: gdbmload.c:dcpgettext_expr
Unexecuted instantiation: gdbmopen.c:dcpgettext_expr
Unexecuted instantiation: gdbmimp.c:dcpgettext_expr
Unexecuted instantiation: gdbmreorg.c:dcpgettext_expr
Unexecuted instantiation: gdbmseq.c:dcpgettext_expr
Unexecuted instantiation: gdbmsetopt.c:dcpgettext_expr
Unexecuted instantiation: gdbmstore.c:dcpgettext_expr
Unexecuted instantiation: gdbmsync.c:dcpgettext_expr
Unexecuted instantiation: avail.c:dcpgettext_expr
Unexecuted instantiation: base64.c:dcpgettext_expr
Unexecuted instantiation: bucket.c:dcpgettext_expr
Unexecuted instantiation: falloc.c:dcpgettext_expr
Unexecuted instantiation: findkey.c:dcpgettext_expr
Unexecuted instantiation: fullio.c:dcpgettext_expr
Unexecuted instantiation: hash.c:dcpgettext_expr
Unexecuted instantiation: lock.c:dcpgettext_expr
Unexecuted instantiation: mmap.c:dcpgettext_expr
Unexecuted instantiation: recover.c:dcpgettext_expr
Unexecuted instantiation: update.c:dcpgettext_expr
Unexecuted instantiation: debug.c:dcpgettext_expr
231
232
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
233
  dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
234
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
235
  dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
236
237
#ifdef __GNUC__
238
__inline
239
#else
240
#ifdef __cplusplus
241
inline
242
#endif
243
#endif
244
static const char *
245
dcnpgettext_expr (const char *domain,
246
                  const char *msgctxt, const char *msgid,
247
                  const char *msgid_plural, unsigned long int n,
248
                  int category)
249
0
{
250
0
  size_t msgctxt_len = strlen (msgctxt) + 1;
251
0
  size_t msgid_len = strlen (msgid) + 1;
252
0
  const char *translation;
253
0
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
254
0
  char msg_ctxt_id[msgctxt_len + msgid_len];
255
0
#else
256
0
  char buf[1024];
257
0
  char *msg_ctxt_id =
258
0
    (msgctxt_len + msgid_len <= sizeof (buf)
259
0
     ? buf
260
0
     : (char *) malloc (msgctxt_len + msgid_len));
261
0
  if (msg_ctxt_id != NULL)
262
0
#endif
263
0
    {
264
0
      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
265
0
      msg_ctxt_id[msgctxt_len - 1] = '\004';
266
0
      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
267
0
      translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
268
0
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
269
0
      if (msg_ctxt_id != buf)
270
0
        free (msg_ctxt_id);
271
0
#endif
272
0
      if (!(translation == msg_ctxt_id || translation == msgid_plural))
273
0
        return translation;
274
0
    }
275
0
  return (n == 1 ? msgid : msgid_plural);
276
0
}
Unexecuted instantiation: gdbm_fuzzer.c:dcnpgettext_expr
Unexecuted instantiation: mem.c:dcnpgettext_expr
Unexecuted instantiation: progname.c:dcnpgettext_expr
Unexecuted instantiation: gram.c:dcnpgettext_expr
Unexecuted instantiation: lex.c:dcnpgettext_expr
Unexecuted instantiation: gdbmshell.c:dcnpgettext_expr
Unexecuted instantiation: var.c:dcnpgettext_expr
Unexecuted instantiation: util.c:dcnpgettext_expr
Unexecuted instantiation: wordwrap.c:dcnpgettext_expr
Unexecuted instantiation: err.c:dcnpgettext_expr
Unexecuted instantiation: pagerfile.c:dcnpgettext_expr
Unexecuted instantiation: datconv.c:dcnpgettext_expr
Unexecuted instantiation: input-file.c:dcnpgettext_expr
Unexecuted instantiation: input-null.c:dcnpgettext_expr
Unexecuted instantiation: gdbmclose.c:dcnpgettext_expr
Unexecuted instantiation: gdbmcount.c:dcnpgettext_expr
Unexecuted instantiation: gdbmdelete.c:dcnpgettext_expr
Unexecuted instantiation: gdbmdump.c:dcnpgettext_expr
Unexecuted instantiation: gdbmerrno.c:dcnpgettext_expr
Unexecuted instantiation: gdbmexp.c:dcnpgettext_expr
Unexecuted instantiation: gdbmfdesc.c:dcnpgettext_expr
Unexecuted instantiation: gdbmfetch.c:dcnpgettext_expr
Unexecuted instantiation: gdbmload.c:dcnpgettext_expr
Unexecuted instantiation: gdbmopen.c:dcnpgettext_expr
Unexecuted instantiation: gdbmimp.c:dcnpgettext_expr
Unexecuted instantiation: gdbmreorg.c:dcnpgettext_expr
Unexecuted instantiation: gdbmseq.c:dcnpgettext_expr
Unexecuted instantiation: gdbmsetopt.c:dcnpgettext_expr
Unexecuted instantiation: gdbmstore.c:dcnpgettext_expr
Unexecuted instantiation: gdbmsync.c:dcnpgettext_expr
Unexecuted instantiation: avail.c:dcnpgettext_expr
Unexecuted instantiation: base64.c:dcnpgettext_expr
Unexecuted instantiation: bucket.c:dcnpgettext_expr
Unexecuted instantiation: falloc.c:dcnpgettext_expr
Unexecuted instantiation: findkey.c:dcnpgettext_expr
Unexecuted instantiation: fullio.c:dcnpgettext_expr
Unexecuted instantiation: hash.c:dcnpgettext_expr
Unexecuted instantiation: lock.c:dcnpgettext_expr
Unexecuted instantiation: mmap.c:dcnpgettext_expr
Unexecuted instantiation: recover.c:dcnpgettext_expr
Unexecuted instantiation: update.c:dcnpgettext_expr
Unexecuted instantiation: debug.c:dcnpgettext_expr
277
278
#endif /* _LIBGETTEXT_H */