2 Copyright (C) 1995-1998, 2000-2003, 2005-2006, 2008-2009 Free Software Foundation, Inc.
3 This file was written by Bruno Haible <haible@clisp.cons.org>.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #ifndef _READ_CATALOG_H
19 #define _READ_CATALOG_H
22 #include "read-catalog-abstract.h"
28 /* For including this file in C++ mode. */
38 /* The following pair of structures cooperate to create a derived class from
39 class abstract_catalog_reader_ty. (See read-catalog-abstract.h for an
40 explanation.) It implements the default behaviour of reading a PO file
41 and converting it to an 'msgdomain_list_ty *'. */
43 /* Forward declaration. */
44 struct default_catalog_reader_ty;
47 typedef struct default_catalog_reader_class_ty default_catalog_reader_class_ty;
48 struct default_catalog_reader_class_ty
50 /* Methods inherited from superclass. */
51 struct abstract_catalog_reader_class_ty super;
53 /* How to change the current domain. */
54 void (*set_domain) (struct default_catalog_reader_ty *pop, char *name);
56 /* How to add a message to the list. */
57 void (*add_message) (struct default_catalog_reader_ty *pop,
59 char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural,
60 char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos,
63 char *prev_msgid_plural,
64 bool force_fuzzy, bool obsolete);
66 /* How to modify a new message before adding it to the list. */
67 void (*frob_new_message) (struct default_catalog_reader_ty *pop,
69 const lex_pos_ty *msgid_pos,
70 const lex_pos_ty *msgstr_pos);
74 #define DEFAULT_CATALOG_READER_TY \
75 ABSTRACT_CATALOG_READER_TY \
77 /* If true, pay attention to comments and filepos comments. */ \
78 bool handle_comments; \
80 /* If true, remember comments for file name and line number for each \
81 msgid, if present in the reference input. */ \
82 bool handle_filepos_comments; \
84 /* If false, domain directives lead to an error messsage. */ \
85 bool allow_domain_directives; \
87 /* If false, duplicate msgids in the same domain and file generate an \
88 error. If true, such msgids are allowed; the caller should treat \
89 them appropriately. */ \
90 bool allow_duplicates; \
92 /* If true, allow duplicates if they have the same translation. */ \
93 bool allow_duplicates_if_same_msgstr; \
95 /* File name used in error messages. */ \
96 const char *file_name; \
98 /* List of messages already appeared in the current file. */ \
99 msgdomain_list_ty *mdlp; \
101 /* Name of domain we are currently examining. */ \
102 const char *domain; \
104 /* List of messages belonging to the current domain. */ \
105 message_list_ty *mlp; \
107 /* Accumulate comments for next message directive. */ \
108 string_list_ty *comment; \
109 string_list_ty *comment_dot; \
111 /* Accumulate filepos comments for the next message directive. */ \
112 size_t filepos_count; \
113 lex_pos_ty *filepos; \
115 /* Flags transported in special comments. */ \
117 enum is_format is_format[NFORMATS]; \
118 struct argument_range range; \
119 enum is_wrap do_wrap; \
121 typedef struct default_catalog_reader_ty default_catalog_reader_ty;
122 struct default_catalog_reader_ty
124 DEFAULT_CATALOG_READER_TY
127 extern void default_constructor (abstract_catalog_reader_ty *that);
128 extern void default_destructor (abstract_catalog_reader_ty *that);
129 extern void default_parse_brief (abstract_catalog_reader_ty *that);
130 extern void default_parse_debrief (abstract_catalog_reader_ty *that);
131 extern void default_directive_domain (abstract_catalog_reader_ty *that,
133 extern void default_directive_message (abstract_catalog_reader_ty *that,
136 lex_pos_ty *msgid_pos,
138 char *msgstr, size_t msgstr_len,
139 lex_pos_ty *msgstr_pos,
142 char *prev_msgid_plural,
143 bool force_fuzzy, bool obsolete);
144 extern void default_comment (abstract_catalog_reader_ty *that, const char *s);
145 extern void default_comment_dot (abstract_catalog_reader_ty *that,
147 extern void default_comment_filepos (abstract_catalog_reader_ty *that,
148 const char *name, size_t line);
149 extern void default_comment_special (abstract_catalog_reader_ty *that,
151 extern void default_set_domain (default_catalog_reader_ty *this, char *name);
152 extern void default_add_message (default_catalog_reader_ty *this,
155 lex_pos_ty *msgid_pos,
157 char *msgstr, size_t msgstr_len,
158 lex_pos_ty *msgstr_pos,
161 char *prev_msgid_plural,
162 bool force_fuzzy, bool obsolete);
164 /* Allocate a fresh default_catalog_reader_ty (or derived class) instance and
165 call its constructor. */
166 extern default_catalog_reader_ty *
167 default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table);
170 /* If nonzero, remember comments for file name and line number for each
171 msgid, if present in the reference input. Defaults to true. */
172 extern DLL_VARIABLE int line_comment;
174 /* If false, duplicate msgids in the same domain and file generate an error.
175 If true, such msgids are allowed; the caller should treat them
176 appropriately. Defaults to false. */
177 extern DLL_VARIABLE bool allow_duplicates;
179 /* Read the input file from a stream. Returns a list of messages. */
180 extern msgdomain_list_ty *
181 read_catalog_stream (FILE *fp,
182 const char *real_filename,
183 const char *logical_filename,
184 catalog_input_format_ty input_syntax);
186 /* Read the input file with the name INPUT_NAME. The ending .po is added
187 if necessary. If INPUT_NAME is not an absolute file name and the file is
188 not found, the list of directories in "dir-list.h" is searched. Returns
189 a list of messages. */
190 extern msgdomain_list_ty *
191 read_catalog_file (const char *input_name,
192 catalog_input_format_ty input_syntax);
200 #endif /* _READ_CATALOG_H */