1 /* GNU gettext - internationalization aids
2 Copyright (C) 1995-1998, 2000-2009, 2015 Free Software Foundation,
5 This file was written by Peter Miller <millerp@canb.auug.org.au>
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 /* According to Sun's Uniforum proposal the default message domain is
37 #define MESSAGE_DOMAIN_DEFAULT "messages"
40 /* Separator between msgctxt and msgid in .mo files. */
41 #define MSGCTXT_SEPARATOR '\004' /* EOT */
44 /* Kinds of format strings. */
76 #define NFORMATS 28 /* Number of format_type enum values. */
77 extern DLL_VARIABLE const char *const format_language[NFORMATS];
78 extern DLL_VARIABLE const char *const format_language_pretty[NFORMATS];
80 /* Is current msgid a format string? */
86 yes_according_to_context,
92 possible_format_p (enum is_format);
95 /* Range of an unsigned integer argument. */
102 /* Tests whether a range is present. */
103 #define has_range_p(range) ((range).min >= 0 && (range).max >= 0)
106 /* Is current msgid wrappable? */
114 #else /* HACK - C's enum concept is so stupid */
115 #define is_wrap is_format
119 /* Kinds of syntax checks which apply to strings. */
120 enum syntax_check_type
126 #define NSYNTAXCHECKS 3
127 extern DLL_VARIABLE const char *const syntax_check_name[NSYNTAXCHECKS];
129 /* Is current msgid subject to a syntax check? */
137 #else /* HACK - C's enum concept is so stupid */
138 #define is_syntax_check is_format
146 const char *msgstr_end;
147 string_list_ty *comment;
148 string_list_ty *comment_dot;
153 typedef struct message_ty message_ty;
156 /* The msgctxt string, if present. */
159 /* The msgid string. */
162 /* The msgid's plural, if present. */
163 const char *msgid_plural;
165 /* The msgstr strings. */
167 /* The number of bytes in msgstr, including the terminating NUL. */
170 /* Position in the source PO file. */
173 /* Plain comments (#) appearing before the message. */
174 string_list_ty *comment;
176 /* Extracted comments (#.) appearing before the message. */
177 string_list_ty *comment_dot;
179 /* File position comments (#:) appearing before the message, one for
180 each unique file position instance, sorted by file name and then
182 size_t filepos_count;
185 /* Informations from special comments (#,).
186 Some of them come from extracted comments. They are manipulated by
187 the tools, e.g. msgmerge. */
189 /* Fuzzy means "needs translator review". */
192 /* Designation of format string syntax requirements for specific
193 programming languages. */
194 enum is_format is_format[NFORMATS];
196 /* Lower and upper bound for the argument whose format directive can be
197 omitted in specific cases of singular or plural. */
198 struct argument_range range;
200 /* Do we want the string to be wrapped in the emitted PO file? */
201 enum is_wrap do_wrap;
203 /* Do we want to apply extra syntax checks on the string? */
204 enum is_syntax_check do_syntax_check[NSYNTAXCHECKS];
206 /* The prev_msgctxt, prev_msgid and prev_msgid_plural strings appearing
207 before the message, if present. Generated by msgmerge. */
208 const char *prev_msgctxt;
209 const char *prev_msgid;
210 const char *prev_msgid_plural;
212 /* If set the message is obsolete and while writing out it should be
216 /* Used for checking that messages have been used, in the msgcmp,
217 msgmerge, msgcomm and msgcat programs. */
220 /* Used for looking up the target message, in the msgcat program. */
223 /* Used for combining alternative translations, in the msgcat program. */
224 int alternative_count;
225 struct altstr *alternative;
229 message_alloc (const char *msgctxt,
230 const char *msgid, const char *msgid_plural,
231 const char *msgstr, size_t msgstr_len,
232 const lex_pos_ty *pp);
233 #define is_header(mp) ((mp)->msgctxt == NULL && (mp)->msgid[0] == '\0')
235 message_free (message_ty *mp);
237 message_comment_append (message_ty *mp, const char *comment);
239 message_comment_dot_append (message_ty *mp, const char *comment);
241 message_comment_filepos (message_ty *mp, const char *name, size_t line);
243 message_copy (message_ty *mp);
246 typedef struct message_list_ty message_list_ty;
247 struct message_list_ty
253 hash_table htable; /* Table mapping msgid to 'message_ty *'. */
256 /* Create a fresh message list.
257 If USE_HASHTABLE is true, a hash table will be used to speed up
258 message_list_search(). USE_HASHTABLE can only be set to true if it is
259 known that the message list will not contain duplicate msgids. */
260 extern message_list_ty *
261 message_list_alloc (bool use_hashtable);
262 /* Free a message list.
263 If keep_messages = 0, also free the messages. If keep_messages = 1, don't
264 free the messages. */
266 message_list_free (message_list_ty *mlp, int keep_messages);
268 message_list_append (message_list_ty *mlp, message_ty *mp);
270 message_list_prepend (message_list_ty *mlp, message_ty *mp);
272 message_list_insert_at (message_list_ty *mlp, size_t n, message_ty *mp);
274 message_list_delete_nth (message_list_ty *mlp, size_t n);
275 typedef bool message_predicate_ty (const message_ty *mp);
277 message_list_remove_if_not (message_list_ty *mlp,
278 message_predicate_ty *predicate);
279 /* Recompute the hash table of a message list after the msgids or msgctxts
282 message_list_msgids_changed (message_list_ty *mlp);
283 /* Copy a message list.
284 If copy_level = 0, also copy the messages. If copy_level = 1, share the
286 extern message_list_ty *
287 message_list_copy (message_list_ty *mlp, int copy_level);
289 message_list_search (message_list_ty *mlp,
290 const char *msgctxt, const char *msgid);
291 /* Return the message in MLP which maximizes the fuzzy_search_goal_function.
292 Only messages with a fuzzy_search_goal_function > FUZZY_THRESHOLD are
293 considered. In case of several messages with the same goal function value,
294 the one with the smaller index is returned. */
296 message_list_search_fuzzy (message_list_ty *mlp,
297 const char *msgctxt, const char *msgid);
300 typedef struct message_list_list_ty message_list_list_ty;
301 struct message_list_list_ty
303 message_list_ty **item;
308 extern message_list_list_ty *
309 message_list_list_alloc (void);
310 /* Free a list of message lists.
311 If keep_level = 0, also free the messages. If keep_level = 1, don't free
312 the messages but free the lists. If keep_level = 2, don't free the
313 the messages and the lists. */
315 message_list_list_free (message_list_list_ty *mllp, int keep_level);
317 message_list_list_append (message_list_list_ty *mllp,
318 message_list_ty *mlp);
320 message_list_list_append_list (message_list_list_ty *mllp,
321 message_list_list_ty *mllp2);
323 message_list_list_search (message_list_list_ty *mllp,
324 const char *msgctxt, const char *msgid);
326 message_list_list_search_fuzzy (message_list_list_ty *mllp,
327 const char *msgctxt, const char *msgid);
330 typedef struct msgdomain_ty msgdomain_ty;
334 message_list_ty *messages;
337 extern msgdomain_ty *
338 msgdomain_alloc (const char *domain, bool use_hashtable);
340 msgdomain_free (msgdomain_ty *mdp);
343 typedef struct msgdomain_list_ty msgdomain_list_ty;
344 struct msgdomain_list_ty
350 const char *encoding; /* canonicalized encoding or NULL if unknown */
353 extern msgdomain_list_ty *
354 msgdomain_list_alloc (bool use_hashtable);
356 msgdomain_list_free (msgdomain_list_ty *mdlp);
358 msgdomain_list_append (msgdomain_list_ty *mdlp, msgdomain_ty *mdp);
360 msgdomain_list_append_list (msgdomain_list_ty *mdlp,
361 msgdomain_list_ty *mdlp2);
362 extern message_list_ty *
363 msgdomain_list_sublist (msgdomain_list_ty *mdlp, const char *domain,
365 /* Copy a message domain list.
366 If copy_level = 0, also copy the messages. If copy_level = 1, share the
367 messages but copy the domains. If copy_level = 2, share the domains. */
368 extern msgdomain_list_ty *
369 msgdomain_list_copy (msgdomain_list_ty *mdlp, int copy_level);
371 msgdomain_list_search (msgdomain_list_ty *mdlp,
372 const char *msgctxt, const char *msgid);
374 msgdomain_list_search_fuzzy (msgdomain_list_ty *mdlp,
375 const char *msgctxt, const char *msgid);
378 /* The goal function used in fuzzy search.
379 Higher values indicate a closer match.
380 If the result is < LOWER_BOUND, an arbitrary other value < LOWER_BOUND can
383 fuzzy_search_goal_function (const message_ty *mp,
384 const char *msgctxt, const char *msgid,
387 /* The threshold for fuzzy-searching.
388 A message is considered only if
389 fuzzy_search_goal_function (mp, given, 0.0) > FUZZY_THRESHOLD. */
390 #define FUZZY_THRESHOLD 0.6
398 #endif /* message.h */