Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:29:57

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