Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / src / read-catalog.h
1 /* Reading PO files.
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>.
5
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.
10
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.
15
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/>.  */
18
19 #ifndef _READ_CATALOG_H
20 #define _READ_CATALOG_H
21
22 #include "message.h"
23 #include "read-catalog-abstract.h"
24
25 #include <stdbool.h>
26 #include <stdio.h>
27
28
29 /* For including this file in C++ mode.  */
30 #ifdef __cplusplus
31 # define this thiss
32 #endif
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38
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 *'.  */
43
44 /* Forward declaration.  */
45 struct default_catalog_reader_ty;
46
47
48 typedef struct default_catalog_reader_class_ty default_catalog_reader_class_ty;
49 struct default_catalog_reader_class_ty
50 {
51   /* Methods inherited from superclass.  */
52   struct abstract_catalog_reader_class_ty super;
53
54   /* How to change the current domain.  */
55   void (*set_domain) (struct default_catalog_reader_ty *pop, char *name);
56
57   /* How to add a message to the list.  */
58   void (*add_message) (struct default_catalog_reader_ty *pop,
59                        char *msgctxt,
60                        char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural,
61                        char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos,
62                        char *prev_msgctxt,
63                        char *prev_msgid,
64                        char *prev_msgid_plural,
65                        bool force_fuzzy, bool obsolete);
66
67   /* How to modify a new message before adding it to the list.  */
68   void (*frob_new_message) (struct default_catalog_reader_ty *pop,
69                             message_ty *mp,
70                             const lex_pos_ty *msgid_pos,
71                             const lex_pos_ty *msgstr_pos);
72 };
73
74
75 #define DEFAULT_CATALOG_READER_TY \
76   ABSTRACT_CATALOG_READER_TY                                            \
77                                                                         \
78   /* If true, pay attention to comments and filepos comments.  */       \
79   bool handle_comments;                                                 \
80                                                                         \
81   /* If false, domain directives lead to an error messsage.  */         \
82   bool allow_domain_directives;                                         \
83                                                                         \
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;                                                \
88                                                                         \
89   /* If true, allow duplicates if they have the same translation.  */   \
90   bool allow_duplicates_if_same_msgstr;                                 \
91                                                                         \
92   /* File name used in error messages.  */                              \
93   const char *file_name;                                                \
94                                                                         \
95   /* List of messages already appeared in the current file.  */         \
96   msgdomain_list_ty *mdlp;                                              \
97                                                                         \
98   /* Name of domain we are currently examining.  */                     \
99   const char *domain;                                                   \
100                                                                         \
101   /* List of messages belonging to the current domain.  */              \
102   message_list_ty *mlp;                                                 \
103                                                                         \
104   /* Accumulate comments for next message directive.  */                \
105   string_list_ty *comment;                                              \
106   string_list_ty *comment_dot;                                          \
107                                                                         \
108   /* Accumulate filepos comments for the next message directive.  */    \
109   size_t filepos_count;                                                 \
110   lex_pos_ty *filepos;                                                  \
111                                                                         \
112   /* Flags transported in special comments.  */                         \
113   bool is_fuzzy;                                                        \
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];                  \
118
119 typedef struct default_catalog_reader_ty default_catalog_reader_ty;
120 struct default_catalog_reader_ty
121 {
122   DEFAULT_CATALOG_READER_TY
123 };
124
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,
130                                       char *name);
131 extern void default_directive_message (abstract_catalog_reader_ty *that,
132                                        char *msgctxt,
133                                        char *msgid,
134                                        lex_pos_ty *msgid_pos,
135                                        char *msgid_plural,
136                                        char *msgstr, size_t msgstr_len,
137                                        lex_pos_ty *msgstr_pos,
138                                        char *prev_msgctxt,
139                                        char *prev_msgid,
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,
144                                  const char *s);
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,
148                                      const char *s);
149 extern void default_set_domain (default_catalog_reader_ty *this, char *name);
150 extern void default_add_message (default_catalog_reader_ty *this,
151                                  char *msgctxt,
152                                  char *msgid,
153                                  lex_pos_ty *msgid_pos,
154                                  char *msgid_plural,
155                                  char *msgstr, size_t msgstr_len,
156                                  lex_pos_ty *msgstr_pos,
157                                  char *prev_msgctxt,
158                                  char *prev_msgid,
159                                  char *prev_msgid_plural,
160                                  bool force_fuzzy, bool obsolete);
161
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);
166
167
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;
172
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);
179
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);
187
188
189 #ifdef __cplusplus
190 }
191 #endif
192
193
194 #endif /* _READ_CATALOG_H */