2 Copyright (C) 1995-1998, 2000-2003, 2005-2006, 2008-2009, 2015 Free
3 Software Foundation, Inc.
4 This file was written by Bruno Haible <haible@clisp.cons.org>.
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/>. */
19 #ifndef _READ_CATALOG_H
20 #define _READ_CATALOG_H
23 #include "read-catalog-abstract.h"
29 /* For including this file in C++ mode. */
39 /* The following pair of structures cooperate to create a derived class from
40 class abstract_catalog_reader_ty. (See read-catalog-abstract.h for an
41 explanation.) It implements the default behaviour of reading a PO file
42 and converting it to an 'msgdomain_list_ty *'. */
44 /* Forward declaration. */
45 struct default_catalog_reader_ty;
48 typedef struct default_catalog_reader_class_ty default_catalog_reader_class_ty;
49 struct default_catalog_reader_class_ty
51 /* Methods inherited from superclass. */
52 struct abstract_catalog_reader_class_ty super;
54 /* How to change the current domain. */
55 void (*set_domain) (struct default_catalog_reader_ty *pop, char *name);
57 /* How to add a message to the list. */
58 void (*add_message) (struct default_catalog_reader_ty *pop,
60 char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural,
61 char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos,
64 char *prev_msgid_plural,
65 bool force_fuzzy, bool obsolete);
67 /* How to modify a new message before adding it to the list. */
68 void (*frob_new_message) (struct default_catalog_reader_ty *pop,
70 const lex_pos_ty *msgid_pos,
71 const lex_pos_ty *msgstr_pos);
75 #define DEFAULT_CATALOG_READER_TY \
76 ABSTRACT_CATALOG_READER_TY \
78 /* If true, pay attention to comments and filepos comments. */ \
79 bool handle_comments; \
81 /* If false, domain directives lead to an error messsage. */ \
82 bool allow_domain_directives; \
84 /* If false, duplicate msgids in the same domain and file generate an \
85 error. If true, such msgids are allowed; the caller should treat \
86 them appropriately. */ \
87 bool allow_duplicates; \
89 /* If true, allow duplicates if they have the same translation. */ \
90 bool allow_duplicates_if_same_msgstr; \
92 /* File name used in error messages. */ \
93 const char *file_name; \
95 /* List of messages already appeared in the current file. */ \
96 msgdomain_list_ty *mdlp; \
98 /* Name of domain we are currently examining. */ \
101 /* List of messages belonging to the current domain. */ \
102 message_list_ty *mlp; \
104 /* Accumulate comments for next message directive. */ \
105 string_list_ty *comment; \
106 string_list_ty *comment_dot; \
108 /* Accumulate filepos comments for the next message directive. */ \
109 size_t filepos_count; \
110 lex_pos_ty *filepos; \
112 /* Flags transported in special comments. */ \
114 enum is_format is_format[NFORMATS]; \
115 struct argument_range range; \
116 enum is_wrap do_wrap; \
117 enum is_syntax_check do_syntax_check[NSYNTAXCHECKS]; \
119 typedef struct default_catalog_reader_ty default_catalog_reader_ty;
120 struct default_catalog_reader_ty
122 DEFAULT_CATALOG_READER_TY
125 extern void default_constructor (abstract_catalog_reader_ty *that);
126 extern void default_destructor (abstract_catalog_reader_ty *that);
127 extern void default_parse_brief (abstract_catalog_reader_ty *that);
128 extern void default_parse_debrief (abstract_catalog_reader_ty *that);
129 extern void default_directive_domain (abstract_catalog_reader_ty *that,
131 extern void default_directive_message (abstract_catalog_reader_ty *that,
134 lex_pos_ty *msgid_pos,
136 char *msgstr, size_t msgstr_len,
137 lex_pos_ty *msgstr_pos,
140 char *prev_msgid_plural,
141 bool force_fuzzy, bool obsolete);
142 extern void default_comment (abstract_catalog_reader_ty *that, const char *s);
143 extern void default_comment_dot (abstract_catalog_reader_ty *that,
145 extern void default_comment_filepos (abstract_catalog_reader_ty *that,
146 const char *name, size_t line);
147 extern void default_comment_special (abstract_catalog_reader_ty *that,
149 extern void default_set_domain (default_catalog_reader_ty *this, char *name);
150 extern void default_add_message (default_catalog_reader_ty *this,
153 lex_pos_ty *msgid_pos,
155 char *msgstr, size_t msgstr_len,
156 lex_pos_ty *msgstr_pos,
159 char *prev_msgid_plural,
160 bool force_fuzzy, bool obsolete);
162 /* Allocate a fresh default_catalog_reader_ty (or derived class) instance and
163 call its constructor. */
164 extern default_catalog_reader_ty *
165 default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table);
168 /* If false, duplicate msgids in the same domain and file generate an error.
169 If true, such msgids are allowed; the caller should treat them
170 appropriately. Defaults to false. */
171 extern DLL_VARIABLE bool allow_duplicates;
173 /* Read the input file from a stream. Returns a list of messages. */
174 extern msgdomain_list_ty *
175 read_catalog_stream (FILE *fp,
176 const char *real_filename,
177 const char *logical_filename,
178 catalog_input_format_ty input_syntax);
180 /* Read the input file with the name INPUT_NAME. The ending .po is added
181 if necessary. If INPUT_NAME is not an absolute file name and the file is
182 not found, the list of directories in "dir-list.h" is searched. Returns
183 a list of messages. */
184 extern msgdomain_list_ty *
185 read_catalog_file (const char *input_name,
186 catalog_input_format_ty input_syntax);
194 #endif /* _READ_CATALOG_H */