1 /* GNU gettext - internationalization aids
2 Copyright (C) 1995-1998, 2000-2009 Free Software Foundation, Inc.
4 This file was written by Peter Miller <millerp@canb.auug.org.au>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 /* According to Sun's Uniforum proposal the default message domain is
36 #define MESSAGE_DOMAIN_DEFAULT "messages"
39 /* Separator between msgctxt and msgid in .mo files. */
40 #define MSGCTXT_SEPARATOR '\004' /* EOT */
43 /* Kinds of format strings. */
71 #define NFORMATS 24 /* Number of format_type enum values. */
72 extern DLL_VARIABLE const char *const format_language[NFORMATS];
73 extern DLL_VARIABLE const char *const format_language_pretty[NFORMATS];
75 /* Is current msgid a format string? */
81 yes_according_to_context,
87 possible_format_p (enum is_format);
90 /* Range of an unsigned integer argument. */
97 /* Tests whether a range is present. */
98 #define has_range_p(range) ((range).min >= 0 && (range).max >= 0)
101 /* Is current msgid wrappable? */
109 #else /* HACK - C's enum concept is so stupid */
110 #define is_wrap is_format
118 const char *msgstr_end;
119 string_list_ty *comment;
120 string_list_ty *comment_dot;
125 typedef struct message_ty message_ty;
128 /* The msgctxt string, if present. */
131 /* The msgid string. */
134 /* The msgid's plural, if present. */
135 const char *msgid_plural;
137 /* The msgstr strings. */
139 /* The number of bytes in msgstr, including the terminating NUL. */
142 /* Position in the source PO file. */
145 /* Plain comments (#) appearing before the message. */
146 string_list_ty *comment;
148 /* Extracted comments (#.) appearing before the message. */
149 string_list_ty *comment_dot;
151 /* File position comments (#:) appearing before the message, one for
152 each unique file position instance, sorted by file name and then
154 size_t filepos_count;
157 /* Informations from special comments (#,).
158 Some of them come from extracted comments. They are manipulated by
159 the tools, e.g. msgmerge. */
161 /* Fuzzy means "needs translator review". */
164 /* Designation of format string syntax requirements for specific
165 programming languages. */
166 enum is_format is_format[NFORMATS];
168 /* Lower and upper bound for the argument whose format directive can be
169 omitted in specific cases of singular or plural. */
170 struct argument_range range;
172 /* Do we want the string to be wrapped in the emitted PO file? */
173 enum is_wrap do_wrap;
175 /* The prev_msgctxt, prev_msgid and prev_msgid_plural strings appearing
176 before the message, if present. Generated by msgmerge. */
177 const char *prev_msgctxt;
178 const char *prev_msgid;
179 const char *prev_msgid_plural;
181 /* If set the message is obsolete and while writing out it should be
185 /* Used for checking that messages have been used, in the msgcmp,
186 msgmerge, msgcomm and msgcat programs. */
189 /* Used for looking up the target message, in the msgcat program. */
192 /* Used for combining alternative translations, in the msgcat program. */
193 int alternative_count;
194 struct altstr *alternative;
198 message_alloc (const char *msgctxt,
199 const char *msgid, const char *msgid_plural,
200 const char *msgstr, size_t msgstr_len,
201 const lex_pos_ty *pp);
202 #define is_header(mp) ((mp)->msgctxt == NULL && (mp)->msgid[0] == '\0')
204 message_free (message_ty *mp);
206 message_comment_append (message_ty *mp, const char *comment);
208 message_comment_dot_append (message_ty *mp, const char *comment);
210 message_comment_filepos (message_ty *mp, const char *name, size_t line);
212 message_copy (message_ty *mp);
215 typedef struct message_list_ty message_list_ty;
216 struct message_list_ty
222 hash_table htable; /* Table mapping msgid to 'message_ty *'. */
225 /* Create a fresh message list.
226 If USE_HASHTABLE is true, a hash table will be used to speed up
227 message_list_search(). USE_HASHTABLE can only be set to true if it is
228 known that the message list will not contain duplicate msgids. */
229 extern message_list_ty *
230 message_list_alloc (bool use_hashtable);
231 /* Free a message list.
232 If keep_messages = 0, also free the messages. If keep_messages = 1, don't
233 free the messages. */
235 message_list_free (message_list_ty *mlp, int keep_messages);
237 message_list_append (message_list_ty *mlp, message_ty *mp);
239 message_list_prepend (message_list_ty *mlp, message_ty *mp);
241 message_list_insert_at (message_list_ty *mlp, size_t n, message_ty *mp);
243 message_list_delete_nth (message_list_ty *mlp, size_t n);
244 typedef bool message_predicate_ty (const message_ty *mp);
246 message_list_remove_if_not (message_list_ty *mlp,
247 message_predicate_ty *predicate);
248 /* Recompute the hash table of a message list after the msgids or msgctxts
251 message_list_msgids_changed (message_list_ty *mlp);
252 /* Copy a message list.
253 If copy_level = 0, also copy the messages. If copy_level = 1, share the
255 extern message_list_ty *
256 message_list_copy (message_list_ty *mlp, int copy_level);
258 message_list_search (message_list_ty *mlp,
259 const char *msgctxt, const char *msgid);
260 /* Return the message in MLP which maximizes the fuzzy_search_goal_function.
261 Only messages with a fuzzy_search_goal_function > FUZZY_THRESHOLD are
262 considered. In case of several messages with the same goal function value,
263 the one with the smaller index is returned. */
265 message_list_search_fuzzy (message_list_ty *mlp,
266 const char *msgctxt, const char *msgid);
269 typedef struct message_list_list_ty message_list_list_ty;
270 struct message_list_list_ty
272 message_list_ty **item;
277 extern message_list_list_ty *
278 message_list_list_alloc (void);
279 /* Free a list of message lists.
280 If keep_level = 0, also free the messages. If keep_level = 1, don't free
281 the messages but free the lists. If keep_level = 2, don't free the
282 the messages and the lists. */
284 message_list_list_free (message_list_list_ty *mllp, int keep_level);
286 message_list_list_append (message_list_list_ty *mllp,
287 message_list_ty *mlp);
289 message_list_list_append_list (message_list_list_ty *mllp,
290 message_list_list_ty *mllp2);
292 message_list_list_search (message_list_list_ty *mllp,
293 const char *msgctxt, const char *msgid);
295 message_list_list_search_fuzzy (message_list_list_ty *mllp,
296 const char *msgctxt, const char *msgid);
299 typedef struct msgdomain_ty msgdomain_ty;
303 message_list_ty *messages;
306 extern msgdomain_ty *
307 msgdomain_alloc (const char *domain, bool use_hashtable);
309 msgdomain_free (msgdomain_ty *mdp);
312 typedef struct msgdomain_list_ty msgdomain_list_ty;
313 struct msgdomain_list_ty
319 const char *encoding; /* canonicalized encoding or NULL if unknown */
322 extern msgdomain_list_ty *
323 msgdomain_list_alloc (bool use_hashtable);
325 msgdomain_list_free (msgdomain_list_ty *mdlp);
327 msgdomain_list_append (msgdomain_list_ty *mdlp, msgdomain_ty *mdp);
329 msgdomain_list_append_list (msgdomain_list_ty *mdlp,
330 msgdomain_list_ty *mdlp2);
331 extern message_list_ty *
332 msgdomain_list_sublist (msgdomain_list_ty *mdlp, const char *domain,
334 /* Copy a message domain list.
335 If copy_level = 0, also copy the messages. If copy_level = 1, share the
336 messages but copy the domains. If copy_level = 2, share the domains. */
337 extern msgdomain_list_ty *
338 msgdomain_list_copy (msgdomain_list_ty *mdlp, int copy_level);
340 msgdomain_list_search (msgdomain_list_ty *mdlp,
341 const char *msgctxt, const char *msgid);
343 msgdomain_list_search_fuzzy (msgdomain_list_ty *mdlp,
344 const char *msgctxt, const char *msgid);
347 /* The goal function used in fuzzy search.
348 Higher values indicate a closer match.
349 If the result is < LOWER_BOUND, an arbitrary other value < LOWER_BOUND can
352 fuzzy_search_goal_function (const message_ty *mp,
353 const char *msgctxt, const char *msgid,
356 /* The threshold for fuzzy-searching.
357 A message is considered only if
358 fuzzy_search_goal_function (mp, given, 0.0) > FUZZY_THRESHOLD. */
359 #define FUZZY_THRESHOLD 0.6
367 #endif /* message.h */