Imported Upstream version 0.18.3.2
[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 Free Software Foundation, Inc.
3    This file was written by Bruno Haible <haible@clisp.cons.org>.
4
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.
9
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.
14
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/>.  */
17
18 #ifndef _READ_CATALOG_H
19 #define _READ_CATALOG_H
20
21 #include "message.h"
22 #include "read-catalog-abstract.h"
23
24 #include <stdbool.h>
25 #include <stdio.h>
26
27
28 /* For including this file in C++ mode.  */
29 #ifdef __cplusplus
30 # define this thiss
31 #endif
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37
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 *'.  */
42
43 /* Forward declaration.  */
44 struct default_catalog_reader_ty;
45
46
47 typedef struct default_catalog_reader_class_ty default_catalog_reader_class_ty;
48 struct default_catalog_reader_class_ty
49 {
50   /* Methods inherited from superclass.  */
51   struct abstract_catalog_reader_class_ty super;
52
53   /* How to change the current domain.  */
54   void (*set_domain) (struct default_catalog_reader_ty *pop, char *name);
55
56   /* How to add a message to the list.  */
57   void (*add_message) (struct default_catalog_reader_ty *pop,
58                        char *msgctxt,
59                        char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural,
60                        char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos,
61                        char *prev_msgctxt,
62                        char *prev_msgid,
63                        char *prev_msgid_plural,
64                        bool force_fuzzy, bool obsolete);
65
66   /* How to modify a new message before adding it to the list.  */
67   void (*frob_new_message) (struct default_catalog_reader_ty *pop,
68                             message_ty *mp,
69                             const lex_pos_ty *msgid_pos,
70                             const lex_pos_ty *msgstr_pos);
71 };
72
73
74 #define DEFAULT_CATALOG_READER_TY \
75   ABSTRACT_CATALOG_READER_TY                                            \
76                                                                         \
77   /* If true, pay attention to comments and filepos comments.  */       \
78   bool handle_comments;                                                 \
79                                                                         \
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;                                         \
83                                                                         \
84   /* If false, domain directives lead to an error messsage.  */         \
85   bool allow_domain_directives;                                         \
86                                                                         \
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;                                                \
91                                                                         \
92   /* If true, allow duplicates if they have the same translation.  */   \
93   bool allow_duplicates_if_same_msgstr;                                 \
94                                                                         \
95   /* File name used in error messages.  */                              \
96   const char *file_name;                                                \
97                                                                         \
98   /* List of messages already appeared in the current file.  */         \
99   msgdomain_list_ty *mdlp;                                              \
100                                                                         \
101   /* Name of domain we are currently examining.  */                     \
102   const char *domain;                                                   \
103                                                                         \
104   /* List of messages belonging to the current domain.  */              \
105   message_list_ty *mlp;                                                 \
106                                                                         \
107   /* Accumulate comments for next message directive.  */                \
108   string_list_ty *comment;                                              \
109   string_list_ty *comment_dot;                                          \
110                                                                         \
111   /* Accumulate filepos comments for the next message directive.  */    \
112   size_t filepos_count;                                                 \
113   lex_pos_ty *filepos;                                                  \
114                                                                         \
115   /* Flags transported in special comments.  */                         \
116   bool is_fuzzy;                                                        \
117   enum is_format is_format[NFORMATS];                                   \
118   struct argument_range range;                                          \
119   enum is_wrap do_wrap;                                                 \
120
121 typedef struct default_catalog_reader_ty default_catalog_reader_ty;
122 struct default_catalog_reader_ty
123 {
124   DEFAULT_CATALOG_READER_TY
125 };
126
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,
132                                       char *name);
133 extern void default_directive_message (abstract_catalog_reader_ty *that,
134                                        char *msgctxt,
135                                        char *msgid,
136                                        lex_pos_ty *msgid_pos,
137                                        char *msgid_plural,
138                                        char *msgstr, size_t msgstr_len,
139                                        lex_pos_ty *msgstr_pos,
140                                        char *prev_msgctxt,
141                                        char *prev_msgid,
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,
146                                  const char *s);
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,
150                                      const char *s);
151 extern void default_set_domain (default_catalog_reader_ty *this, char *name);
152 extern void default_add_message (default_catalog_reader_ty *this,
153                                  char *msgctxt,
154                                  char *msgid,
155                                  lex_pos_ty *msgid_pos,
156                                  char *msgid_plural,
157                                  char *msgstr, size_t msgstr_len,
158                                  lex_pos_ty *msgstr_pos,
159                                  char *prev_msgctxt,
160                                  char *prev_msgid,
161                                  char *prev_msgid_plural,
162                                  bool force_fuzzy, bool obsolete);
163
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);
168
169
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;
173
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;
178
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);
185
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);
193
194
195 #ifdef __cplusplus
196 }
197 #endif
198
199
200 #endif /* _READ_CATALOG_H */