Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:35:13

0001 /* Public API for GNU gettext PO files - contained in libgettextpo.
0002    Copyright (C) 2003-2026 Free Software Foundation, Inc.
0003 
0004    This program is free software: you can redistribute it and/or modify
0005    it under the terms of the GNU General Public License as published by
0006    the Free Software Foundation; either version 3 of the License, or
0007    (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012    GNU General Public License for more details.
0013 
0014    You should have received a copy of the GNU General Public License
0015    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
0016 
0017 /* Written by Bruno Haible.  */
0018 
0019 #ifndef _GETTEXT_PO_H
0020 #define _GETTEXT_PO_H 1
0021 
0022 #include <stdlib.h>
0023 
0024 #ifdef __cplusplus
0025 extern "C" {
0026 #endif
0027 
0028 
0029 /* =========================== Meta Information ============================ */
0030 
0031 /* Version number: (major<<16) + (minor<<8) + subminor */
0032 #define LIBGETTEXTPO_VERSION 0x010000
0033 extern int libgettextpo_version;
0034 
0035 /* ================================= Types ================================= */
0036 
0037 /* A po_file_t represents the contents of a PO file.  */
0038 typedef struct po_file *po_file_t;
0039 
0040 /* A po_message_iterator_t represents an iterator through a domain of a
0041    PO file.  */
0042 typedef struct po_message_iterator *po_message_iterator_t;
0043 
0044 /* A po_message_t represents a message in a PO file.  */
0045 typedef struct po_message *po_message_t;
0046 
0047 /* A po_filepos_t represents a string's position within a source file.  */
0048 typedef struct po_filepos *po_filepos_t;
0049 
0050 /* A po_flag_iterator_t represents an iterator through the workflow flags or
0051    the sticky flags of a message.  */
0052 typedef struct po_flag_iterator *po_flag_iterator_t;
0053 
0054 /* A po_error_handler handles error situations.  No longer used.  */
0055 struct po_error_handler
0056 {
0057   /* Signal an error.  The error message is built from FORMAT and the following
0058      arguments.  ERRNUM, if nonzero, is an errno value.
0059      Must increment the error_message_count variable declared in error.h.
0060      Must not return if STATUS is nonzero.  */
0061   void (*error) (int status, int errnum,
0062                  const char *format, ...)
0063 #if (((__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3) || defined __clang__) && !__STRICT_ANSI__
0064   __attribute__ ((__format__ (__printf__, 3, 4)))
0065 #endif
0066   ;
0067 
0068   /* Signal an error.  The error message is built from FORMAT and the following
0069      arguments.  The error location is at FILENAME line LINENO. ERRNUM, if
0070      nonzero, is an errno value.
0071      Must increment the error_message_count variable declared in error.h.
0072      Must not return if STATUS is nonzero.  */
0073   void (*error_at_line) (int status, int errnum,
0074                          const char *filename, unsigned int lineno,
0075                          const char *format, ...)
0076 #if (((__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3) || defined __clang__) && !__STRICT_ANSI__
0077   __attribute__ ((__format__ (__printf__, 5, 6)))
0078 #endif
0079   ;
0080 
0081   /* Signal a multiline warning.  The PREFIX applies to all lines of the
0082      MESSAGE.  Free the PREFIX and MESSAGE when done.  */
0083   void (*multiline_warning) (char *prefix, char *message);
0084 
0085   /* Signal a multiline error.  The PREFIX applies to all lines of the
0086      MESSAGE.  Free the PREFIX and MESSAGE when done.
0087      Must increment the error_message_count variable declared in error.h if
0088      PREFIX is non-NULL.  */
0089   void (*multiline_error) (char *prefix, char *message);
0090 };
0091 typedef const struct po_error_handler *po_error_handler_t;
0092 
0093 /* A po_xerror_handler handles warnings, error and fatal error situations.  */
0094 #define PO_SEVERITY_WARNING     0 /* just a warning, tell the user */
0095 #define PO_SEVERITY_ERROR       1 /* an error, the operation cannot complete */
0096 #define PO_SEVERITY_FATAL_ERROR 2 /* an error, the operation must be aborted */
0097 struct po_xerror_handler
0098 {
0099   /* Signal a problem of the given severity.
0100      MESSAGE and/or FILENAME + LINENO indicate where the problem occurred.
0101      If FILENAME is NULL, FILENAME and LINENO and COLUMN should be ignored.
0102      If LINENO is (size_t)(-1), LINENO and COLUMN should be ignored.
0103      If COLUMN is (size_t)(-1), it should be ignored.
0104      MESSAGE_TEXT is the problem description (if MULTILINE_P is true,
0105      multiple lines of text, each terminated with a newline, otherwise
0106      usually a single line).
0107      Must not return if SEVERITY is PO_SEVERITY_FATAL_ERROR.  */
0108   void (*xerror) (int severity,
0109                   po_message_t message,
0110                   const char *filename, size_t lineno, size_t column,
0111                   int multiline_p, const char *message_text);
0112   /* Signal a problem that refers to two messages.
0113      Similar to two calls to xerror.
0114      If possible, a "..." can be appended to MESSAGE_TEXT1 and prepended to
0115      MESSAGE_TEXT2.  */
0116   void (*xerror2) (int severity,
0117                    po_message_t message1,
0118                    const char *filename1, size_t lineno1, size_t column1,
0119                    int multiline_p1, const char *message_text1,
0120                    po_message_t message2,
0121                    const char *filename2, size_t lineno2, size_t column2,
0122                    int multiline_p2, const char *message_text2);
0123 };
0124 typedef const struct po_xerror_handler *po_xerror_handler_t;
0125 
0126 /* Memory allocation:
0127    The memory allocations performed by these functions use xmalloc(),
0128    therefore will cause a program exit if memory is exhausted.
0129    The memory allocated by po_file_read, and implicitly returned through
0130    the po_message_* functions, lasts until freed with po_file_free.  */
0131 
0132 
0133 /* ============================= po_file_t API ============================= */
0134 
0135 /* Create an empty PO file representation in memory.  */
0136 extern po_file_t po_file_create (void);
0137 
0138 /* Read a PO file into memory.
0139    Return its contents.  Upon failure, call function from handler.  */
0140 #define po_file_read po_file_read_v3
0141 extern po_file_t po_file_read (const char *filename,
0142                                po_xerror_handler_t handler);
0143 
0144 /* Write an in-memory PO file to a file.
0145    Upon failure, call function from handler.  */
0146 #define po_file_write po_file_write_v2
0147 extern po_file_t po_file_write (po_file_t file, const char *filename,
0148                                 po_xerror_handler_t handler);
0149 
0150 /* Free a PO file from memory.  */
0151 extern void po_file_free (po_file_t file);
0152 
0153 /* Return the names of the domains covered by a PO file in memory.  */
0154 extern const char * const * po_file_domains (po_file_t file);
0155 
0156 
0157 /* =========================== Header entry API ============================ */
0158 
0159 /* Return the header entry of a domain of a PO file in memory.
0160    The domain NULL denotes the default domain.
0161    Return NULL if there is no header entry.  */
0162 extern const char * po_file_domain_header (po_file_t file, const char *domain);
0163 
0164 /* Return the value of a field in a header entry.
0165    The return value is either a freshly allocated string, to be freed by the
0166    caller, or NULL.  */
0167 extern char * po_header_field (const char *header, const char *field);
0168 
0169 /* Return the header entry with a given field set to a given value.  The field
0170    is added if necessary.
0171    The return value is a freshly allocated string.  */
0172 extern char * po_header_set_field (const char *header, const char *field, const char *value);
0173 
0174 
0175 /* ======================= po_message_iterator_t API ======================= */
0176 
0177 /* Create an iterator for traversing a domain of a PO file in memory.
0178    The domain NULL denotes the default domain.  */
0179 extern po_message_iterator_t po_message_iterator (po_file_t file, const char *domain);
0180 
0181 /* Free an iterator.  */
0182 extern void po_message_iterator_free (po_message_iterator_t iterator);
0183 
0184 /* Return the next message, and advance the iterator.
0185    Return NULL at the end of the message list.  */
0186 extern po_message_t po_next_message (po_message_iterator_t iterator);
0187 
0188 /* Insert a message in a PO file in memory, in the domain and at the position
0189    indicated by the iterator.  The iterator thereby advances past the freshly
0190    inserted message.  */
0191 extern void po_message_insert (po_message_iterator_t iterator, po_message_t message);
0192 
0193 
0194 /* =========================== po_message_t API ============================ */
0195 
0196 /* Return a freshly constructed message.
0197    To finish initializing the message, you must set the msgid and msgstr.  */
0198 extern po_message_t po_message_create (void);
0199 
0200 
0201 /* Return the context of a message, or NULL for a message not restricted to a
0202    context.  */
0203 extern const char * po_message_msgctxt (po_message_t message);
0204 
0205 /* Change the context of a message. NULL means a message not restricted to a
0206    context.  */
0207 extern void po_message_set_msgctxt (po_message_t message, const char *msgctxt);
0208 
0209 
0210 /* Return the msgid (untranslated English string) of a message.  */
0211 extern const char * po_message_msgid (po_message_t message);
0212 
0213 /* Change the msgid (untranslated English string) of a message.  */
0214 extern void po_message_set_msgid (po_message_t message, const char *msgid);
0215 
0216 /* Return the msgid_plural (untranslated English plural string) of a message,
0217    or NULL for a message without plural.  */
0218 extern const char * po_message_msgid_plural (po_message_t message);
0219 
0220 /* Change the msgid_plural (untranslated English plural string) of a message.
0221    NULL means a message without plural.  */
0222 extern void po_message_set_msgid_plural (po_message_t message, const char *msgid_plural);
0223 
0224 
0225 /* Return the msgstr (translation) of a message.
0226    Return the empty string for an untranslated message.  */
0227 extern const char * po_message_msgstr (po_message_t message);
0228 
0229 /* Change the msgstr (translation) of a message.
0230    Use an empty string to denote an untranslated message.  */
0231 extern void po_message_set_msgstr (po_message_t message, const char *msgstr);
0232 
0233 /* Return the msgstr[index] for a message with plural handling, or
0234    NULL when the index is out of range or for a message without plural.  */
0235 extern const char * po_message_msgstr_plural (po_message_t message, int index);
0236 
0237 /* Change the msgstr[index] for a message with plural handling.
0238    Use a NULL value at the end to reduce the number of plural forms.  */
0239 extern void po_message_set_msgstr_plural (po_message_t message, int index, const char *msgstr);
0240 
0241 
0242 /* Return the comments for a message.  */
0243 extern const char * po_message_comments (po_message_t message);
0244 
0245 /* Change the comments for a message.
0246    comments should be a multiline string, ending in a newline, or empty.  */
0247 extern void po_message_set_comments (po_message_t message, const char *comments);
0248 
0249 
0250 /* Return the extracted comments for a message.  */
0251 extern const char * po_message_extracted_comments (po_message_t message);
0252 
0253 /* Change the extracted comments for a message.
0254    comments should be a multiline string, ending in a newline, or empty.  */
0255 extern void po_message_set_extracted_comments (po_message_t message, const char *comments);
0256 
0257 
0258 /* Return the i-th file position for a message, or NULL if i is out of
0259    range.  */
0260 extern po_filepos_t po_message_filepos (po_message_t message, int i);
0261 
0262 /* Remove the i-th file position from a message.
0263    The indices of all following file positions for the message are decremented
0264    by one.  */
0265 extern void po_message_remove_filepos (po_message_t message, int i);
0266 
0267 /* Add a file position to a message, if it is not already present for the
0268    message.
0269    file is the file name.
0270    start_line is the line number where the string starts, or (size_t)(-1) if no
0271    line number is available.  */
0272 extern void po_message_add_filepos (po_message_t message, const char *file, size_t start_line);
0273 
0274 
0275 /* Return the previous context of a message, or NULL for none.  */
0276 extern const char * po_message_prev_msgctxt (po_message_t message);
0277 
0278 /* Change the previous context of a message.  NULL is allowed.  */
0279 extern void po_message_set_prev_msgctxt (po_message_t message, const char *prev_msgctxt);
0280 
0281 /* Return the previous msgid (untranslated English string) of a message, or
0282    NULL for none.  */
0283 extern const char * po_message_prev_msgid (po_message_t message);
0284 
0285 /* Change the previous msgid (untranslated English string) of a message.
0286    NULL is allowed.  */
0287 extern void po_message_set_prev_msgid (po_message_t message, const char *prev_msgid);
0288 
0289 /* Return the previous msgid_plural (untranslated English plural string) of a
0290    message, or NULL for none.  */
0291 extern const char * po_message_prev_msgid_plural (po_message_t message);
0292 
0293 /* Change the previous msgid_plural (untranslated English plural string) of a
0294    message.  NULL is allowed.  */
0295 extern void po_message_set_prev_msgid_plural (po_message_t message, const char *prev_msgid_plural);
0296 
0297 
0298 /* Return true if the message is marked obsolete.  */
0299 extern int po_message_is_obsolete (po_message_t message);
0300 
0301 /* Change the obsolete mark of a message.  */
0302 extern void po_message_set_obsolete (po_message_t message, int obsolete);
0303 
0304 
0305 /* Return true if the message is marked fuzzy.  */
0306 extern int po_message_is_fuzzy (po_message_t message);
0307 
0308 /* Change the fuzzy mark of a message.  */
0309 extern void po_message_set_fuzzy (po_message_t message, int fuzzy);
0310 
0311 /* Return true if the message has a given workflow flag.
0312    This function is a generalization of po_message_is_fuzzy.  */
0313 extern int po_message_has_workflow_flag (po_message_t message, const char *workflow_flag);
0314 
0315 /* Set or unset a given workflow flag on a message.
0316    This function is a generalization of po_message_set_fuzzy.    */
0317 extern void po_message_set_workflow_flag (po_message_t message, const char *workflow_flag, int value);
0318 
0319 /* Create an iterator for traversing the list of workflow flags of a message.
0320    This includes the "fuzzy" flag.  */
0321 extern po_flag_iterator_t po_message_workflow_flags_iterator (po_message_t message);
0322 
0323 
0324 /* Return true if the message is marked as being a format string of the given
0325    type (e.g. "c-format").  */
0326 extern int po_message_is_format (po_message_t message, const char *format_type);
0327 
0328 /* Return the format string mark for a given type (e.g. "c-format") of a
0329    message.
0330    Returns 1 if the the mark is set,
0331    0 if the opposite mark ("no-*") is set,
0332    -1 if neither the mark nor the opposite mark is set.  */
0333 extern int po_message_get_format (po_message_t message, const char *format_type);
0334 
0335 /* Change the format string mark for a given type of a message.
0336    Pass value = 1 to assert the format string mark (e.g. "c-format"),
0337    value = 0 to assert the opposite (leading to e.g. "no-c-format"),
0338    or value = -1 to remove the format string mark and its opposite.  */
0339 extern void po_message_set_format (po_message_t message, const char *format_type, int value);
0340 
0341 /* Return true if the message has a given sticky flag.
0342    This function is a generalization of po_message_is_format and
0343    po_message_get_format.  */
0344 extern int po_message_has_sticky_flag (po_message_t message, const char *sticky_flag);
0345 
0346 /* Set or unset a given sticky flag on a message.
0347    This function is a generalization of po_message_set_format.  */
0348 extern void po_message_set_sticky_flag (po_message_t message, const char *sticky_flag, int value);
0349 
0350 /* Create an iterator for traversing the list of sticky flags of a message.
0351    This includes the "*-format" and "no-*-format" flags, as well as the
0352    "no-wrap" flag.
0353    It does *not* include the "range", because that is not a flag.  */
0354 extern po_flag_iterator_t po_message_sticky_flags_iterator (po_message_t message);
0355 
0356 
0357 /* If a numeric range of a message is set, return true and store the minimum
0358    and maximum value in *MINP and *MAXP.  */
0359 extern int po_message_is_range (po_message_t message, int *minp, int *maxp);
0360 
0361 /* Change the numeric range of a message.  MIN and MAX must be non-negative,
0362    with MIN < MAX.  Use MIN = MAX = -1 to remove the numeric range of a
0363    message.  */
0364 extern void po_message_set_range (po_message_t message, int min, int max);
0365 
0366 
0367 /* =========================== po_filepos_t API ============================ */
0368 
0369 /* Return the file name.  */
0370 extern const char * po_filepos_file (po_filepos_t filepos);
0371 
0372 /* Return the line number where the string starts, or (size_t)(-1) if no line
0373    number is available.  */
0374 extern size_t po_filepos_start_line (po_filepos_t filepos);
0375 
0376 
0377 /* ============================ Format type API ============================= */
0378 
0379 /* Return a NULL terminated array of the supported format types.  */
0380 extern const char * const * po_format_list (void);
0381 
0382 /* Return the pretty name associated with a format type.
0383    For example, for "csharp-format", return "C#".
0384    Return NULL if the argument is not a supported format type.  */
0385 extern const char * po_format_pretty_name (const char *format_type);
0386 
0387 
0388 /* ========================= po_flag_iterator_t API ========================= */
0389 
0390 /* Free an iterator.  */
0391 extern void po_flag_iterator_free (po_flag_iterator_t iterator);
0392 
0393 /* Return the next flag, and advance the iterator.
0394    Return NULL at the end of the list of flags.  */
0395 extern const char * po_flag_next (po_flag_iterator_t iterator);
0396 
0397 
0398 /* ============================= Checking API ============================== */
0399 
0400 /* Test whether an entire file PO file is valid, like msgfmt does it.
0401    If it is invalid, pass the reasons to the handler.  */
0402 extern void po_file_check_all (po_file_t file, po_xerror_handler_t handler);
0403 
0404 /* Test a single message, to be inserted in a PO file in memory, like msgfmt
0405    does it.  If it is invalid, pass the reasons to the handler.  The iterator
0406    is not modified by this call; it only specifies the file and the domain.  */
0407 extern void po_message_check_all (po_message_t message, po_message_iterator_t iterator, po_xerror_handler_t handler);
0408 
0409 /* Test whether the message translation is a valid format string if the message
0410    is marked as being a format string.  If it is invalid, pass the reasons to
0411    the handler.  */
0412 #define po_message_check_format po_message_check_format_v2
0413 extern void po_message_check_format (po_message_t message, po_xerror_handler_t handler);
0414 
0415 
0416 #ifdef __cplusplus
0417 }
0418 #endif
0419 
0420 #endif /* _GETTEXT_PO_H */