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. */
74 #define NFORMATS 27 /* Number of format_type enum values. */
75 extern DLL_VARIABLE const char *const format_language[NFORMATS];
76 extern DLL_VARIABLE const char *const format_language_pretty[NFORMATS];
78 /* Is current msgid a format string? */
84 yes_according_to_context,
90 possible_format_p (enum is_format);
93 /* Range of an unsigned integer argument. */
100 /* Tests whether a range is present. */
101 #define has_range_p(range) ((range).min >= 0 && (range).max >= 0)
104 /* Is current msgid wrappable? */
112 #else /* HACK - C's enum concept is so stupid */
113 #define is_wrap is_format
121 const char *msgstr_end;
122 string_list_ty *comment;
123 string_list_ty *comment_dot;
128 typedef struct message_ty message_ty;
131 /* The msgctxt string, if present. */
134 /* The msgid string. */
137 /* The msgid's plural, if present. */
138 const char *msgid_plural;
140 /* The msgstr strings. */
142 /* The number of bytes in msgstr, including the terminating NUL. */
145 /* Position in the source PO file. */
148 /* Plain comments (#) appearing before the message. */
149 string_list_ty *comment;
151 /* Extracted comments (#.) appearing before the message. */
152 string_list_ty *comment_dot;
154 /* File position comments (#:) appearing before the message, one for
155 each unique file position instance, sorted by file name and then
157 size_t filepos_count;
160 /* Informations from special comments (#,).
161 Some of them come from extracted comments. They are manipulated by
162 the tools, e.g. msgmerge. */
164 /* Fuzzy means "needs translator review". */
167 /* Designation of format string syntax requirements for specific
168 programming languages. */
169 enum is_format is_format[NFORMATS];
171 /* Lower and upper bound for the argument whose format directive can be
172 omitted in specific cases of singular or plural. */
173 struct argument_range range;
175 /* Do we want the string to be wrapped in the emitted PO file? */
176 enum is_wrap do_wrap;
178 /* The prev_msgctxt, prev_msgid and prev_msgid_plural strings appearing
179 before the message, if present. Generated by msgmerge. */
180 const char *prev_msgctxt;
181 const char *prev_msgid;
182 const char *prev_msgid_plural;
184 /* If set the message is obsolete and while writing out it should be
188 /* Used for checking that messages have been used, in the msgcmp,
189 msgmerge, msgcomm and msgcat programs. */
192 /* Used for looking up the target message, in the msgcat program. */
195 /* Used for combining alternative translations, in the msgcat program. */
196 int alternative_count;
197 struct altstr *alternative;
201 message_alloc (const char *msgctxt,
202 const char *msgid, const char *msgid_plural,
203 const char *msgstr, size_t msgstr_len,
204 const lex_pos_ty *pp);
205 #define is_header(mp) ((mp)->msgctxt == NULL && (mp)->msgid[0] == '\0')
207 message_free (message_ty *mp);
209 message_comment_append (message_ty *mp, const char *comment);
211 message_comment_dot_append (message_ty *mp, const char *comment);
213 message_comment_filepos (message_ty *mp, const char *name, size_t line);
215 message_copy (message_ty *mp);
218 typedef struct message_list_ty message_list_ty;
219 struct message_list_ty
225 hash_table htable; /* Table mapping msgid to 'message_ty *'. */
228 /* Create a fresh message list.
229 If USE_HASHTABLE is true, a hash table will be used to speed up
230 message_list_search(). USE_HASHTABLE can only be set to true if it is
231 known that the message list will not contain duplicate msgids. */
232 extern message_list_ty *
233 message_list_alloc (bool use_hashtable);
234 /* Free a message list.
235 If keep_messages = 0, also free the messages. If keep_messages = 1, don't
236 free the messages. */
238 message_list_free (message_list_ty *mlp, int keep_messages);
240 message_list_append (message_list_ty *mlp, message_ty *mp);
242 message_list_prepend (message_list_ty *mlp, message_ty *mp);
244 message_list_insert_at (message_list_ty *mlp, size_t n, message_ty *mp);
246 message_list_delete_nth (message_list_ty *mlp, size_t n);
247 typedef bool message_predicate_ty (const message_ty *mp);
249 message_list_remove_if_not (message_list_ty *mlp,
250 message_predicate_ty *predicate);
251 /* Recompute the hash table of a message list after the msgids or msgctxts
254 message_list_msgids_changed (message_list_ty *mlp);
255 /* Copy a message list.
256 If copy_level = 0, also copy the messages. If copy_level = 1, share the
258 extern message_list_ty *
259 message_list_copy (message_list_ty *mlp, int copy_level);
261 message_list_search (message_list_ty *mlp,
262 const char *msgctxt, const char *msgid);
263 /* Return the message in MLP which maximizes the fuzzy_search_goal_function.
264 Only messages with a fuzzy_search_goal_function > FUZZY_THRESHOLD are
265 considered. In case of several messages with the same goal function value,
266 the one with the smaller index is returned. */
268 message_list_search_fuzzy (message_list_ty *mlp,
269 const char *msgctxt, const char *msgid);
272 typedef struct message_list_list_ty message_list_list_ty;
273 struct message_list_list_ty
275 message_list_ty **item;
280 extern message_list_list_ty *
281 message_list_list_alloc (void);
282 /* Free a list of message lists.
283 If keep_level = 0, also free the messages. If keep_level = 1, don't free
284 the messages but free the lists. If keep_level = 2, don't free the
285 the messages and the lists. */
287 message_list_list_free (message_list_list_ty *mllp, int keep_level);
289 message_list_list_append (message_list_list_ty *mllp,
290 message_list_ty *mlp);
292 message_list_list_append_list (message_list_list_ty *mllp,
293 message_list_list_ty *mllp2);
295 message_list_list_search (message_list_list_ty *mllp,
296 const char *msgctxt, const char *msgid);
298 message_list_list_search_fuzzy (message_list_list_ty *mllp,
299 const char *msgctxt, const char *msgid);
302 typedef struct msgdomain_ty msgdomain_ty;
306 message_list_ty *messages;
309 extern msgdomain_ty *
310 msgdomain_alloc (const char *domain, bool use_hashtable);
312 msgdomain_free (msgdomain_ty *mdp);
315 typedef struct msgdomain_list_ty msgdomain_list_ty;
316 struct msgdomain_list_ty
322 const char *encoding; /* canonicalized encoding or NULL if unknown */
325 extern msgdomain_list_ty *
326 msgdomain_list_alloc (bool use_hashtable);
328 msgdomain_list_free (msgdomain_list_ty *mdlp);
330 msgdomain_list_append (msgdomain_list_ty *mdlp, msgdomain_ty *mdp);
332 msgdomain_list_append_list (msgdomain_list_ty *mdlp,
333 msgdomain_list_ty *mdlp2);
334 extern message_list_ty *
335 msgdomain_list_sublist (msgdomain_list_ty *mdlp, const char *domain,
337 /* Copy a message domain list.
338 If copy_level = 0, also copy the messages. If copy_level = 1, share the
339 messages but copy the domains. If copy_level = 2, share the domains. */
340 extern msgdomain_list_ty *
341 msgdomain_list_copy (msgdomain_list_ty *mdlp, int copy_level);
343 msgdomain_list_search (msgdomain_list_ty *mdlp,
344 const char *msgctxt, const char *msgid);
346 msgdomain_list_search_fuzzy (msgdomain_list_ty *mdlp,
347 const char *msgctxt, const char *msgid);
350 /* The goal function used in fuzzy search.
351 Higher values indicate a closer match.
352 If the result is < LOWER_BOUND, an arbitrary other value < LOWER_BOUND can
355 fuzzy_search_goal_function (const message_ty *mp,
356 const char *msgctxt, const char *msgid,
359 /* The threshold for fuzzy-searching.
360 A message is considered only if
361 fuzzy_search_goal_function (mp, given, 0.0) > FUZZY_THRESHOLD. */
362 #define FUZZY_THRESHOLD 0.6
370 #endif /* message.h */