summaryrefslogtreecommitdiff
path: root/gettext-tools/src/read-catalog.h
blob: f50bcb0806efb2c1579c957d15e9eb5220ae4e16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* Reading PO files.
   Copyright (C) 1995-1998, 2000-2003, 2005-2006, 2008-2009, 2015 Free
   Software Foundation, Inc.
   This file was written by Bruno Haible <haible@clisp.cons.org>.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#ifndef _READ_CATALOG_H
#define _READ_CATALOG_H

#include "message.h"
#include "read-catalog-abstract.h"

#include <stdbool.h>
#include <stdio.h>


/* For including this file in C++ mode.  */
#ifdef __cplusplus
# define this thiss
#endif

#ifdef __cplusplus
extern "C" {
#endif


/* The following pair of structures cooperate to create a derived class from
   class abstract_catalog_reader_ty.  (See read-catalog-abstract.h for an
   explanation.)  It implements the default behaviour of reading a PO file
   and converting it to an 'msgdomain_list_ty *'.  */

/* Forward declaration.  */
struct default_catalog_reader_ty;


typedef struct default_catalog_reader_class_ty default_catalog_reader_class_ty;
struct default_catalog_reader_class_ty
{
  /* Methods inherited from superclass.  */
  struct abstract_catalog_reader_class_ty super;

  /* How to change the current domain.  */
  void (*set_domain) (struct default_catalog_reader_ty *pop, char *name);

  /* How to add a message to the list.  */
  void (*add_message) (struct default_catalog_reader_ty *pop,
                       char *msgctxt,
                       char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural,
                       char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos,
                       char *prev_msgctxt,
                       char *prev_msgid,
                       char *prev_msgid_plural,
                       bool force_fuzzy, bool obsolete);

  /* How to modify a new message before adding it to the list.  */
  void (*frob_new_message) (struct default_catalog_reader_ty *pop,
                            message_ty *mp,
                            const lex_pos_ty *msgid_pos,
                            const lex_pos_ty *msgstr_pos);
};


#define DEFAULT_CATALOG_READER_TY \
  ABSTRACT_CATALOG_READER_TY                                            \
                                                                        \
  /* If true, pay attention to comments and filepos comments.  */       \
  bool handle_comments;                                                 \
                                                                        \
  /* If false, domain directives lead to an error messsage.  */         \
  bool allow_domain_directives;                                         \
                                                                        \
  /* If false, duplicate msgids in the same domain and file generate an \
     error.  If true, such msgids are allowed; the caller should treat  \
     them appropriately.  */                                            \
  bool allow_duplicates;                                                \
                                                                        \
  /* If true, allow duplicates if they have the same translation.  */   \
  bool allow_duplicates_if_same_msgstr;                                 \
                                                                        \
  /* File name used in error messages.  */                              \
  const char *file_name;                                                \
                                                                        \
  /* List of messages already appeared in the current file.  */         \
  msgdomain_list_ty *mdlp;                                              \
                                                                        \
  /* Name of domain we are currently examining.  */                     \
  const char *domain;                                                   \
                                                                        \
  /* List of messages belonging to the current domain.  */              \
  message_list_ty *mlp;                                                 \
                                                                        \
  /* Accumulate comments for next message directive.  */                \
  string_list_ty *comment;                                              \
  string_list_ty *comment_dot;                                          \
                                                                        \
  /* Accumulate filepos comments for the next message directive.  */    \
  size_t filepos_count;                                                 \
  lex_pos_ty *filepos;                                                  \
                                                                        \
  /* Flags transported in special comments.  */                         \
  bool is_fuzzy;                                                        \
  enum is_format is_format[NFORMATS];                                   \
  struct argument_range range;                                          \
  enum is_wrap do_wrap;                                                 \
  enum is_syntax_check do_syntax_check[NSYNTAXCHECKS];                  \

typedef struct default_catalog_reader_ty default_catalog_reader_ty;
struct default_catalog_reader_ty
{
  DEFAULT_CATALOG_READER_TY
};

extern void default_constructor (abstract_catalog_reader_ty *that);
extern void default_destructor (abstract_catalog_reader_ty *that);
extern void default_parse_brief (abstract_catalog_reader_ty *that);
extern void default_parse_debrief (abstract_catalog_reader_ty *that);
extern void default_directive_domain (abstract_catalog_reader_ty *that,
                                      char *name);
extern void default_directive_message (abstract_catalog_reader_ty *that,
                                       char *msgctxt,
                                       char *msgid,
                                       lex_pos_ty *msgid_pos,
                                       char *msgid_plural,
                                       char *msgstr, size_t msgstr_len,
                                       lex_pos_ty *msgstr_pos,
                                       char *prev_msgctxt,
                                       char *prev_msgid,
                                       char *prev_msgid_plural,
                                       bool force_fuzzy, bool obsolete);
extern void default_comment (abstract_catalog_reader_ty *that, const char *s);
extern void default_comment_dot (abstract_catalog_reader_ty *that,
                                 const char *s);
extern void default_comment_filepos (abstract_catalog_reader_ty *that,
                                     const char *name, size_t line);
extern void default_comment_special (abstract_catalog_reader_ty *that,
                                     const char *s);
extern void default_set_domain (default_catalog_reader_ty *this, char *name);
extern void default_add_message (default_catalog_reader_ty *this,
                                 char *msgctxt,
                                 char *msgid,
                                 lex_pos_ty *msgid_pos,
                                 char *msgid_plural,
                                 char *msgstr, size_t msgstr_len,
                                 lex_pos_ty *msgstr_pos,
                                 char *prev_msgctxt,
                                 char *prev_msgid,
                                 char *prev_msgid_plural,
                                 bool force_fuzzy, bool obsolete);

/* Allocate a fresh default_catalog_reader_ty (or derived class) instance and
   call its constructor.  */
extern default_catalog_reader_ty *
       default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table);


/* If false, duplicate msgids in the same domain and file generate an error.
   If true, such msgids are allowed; the caller should treat them
   appropriately.  Defaults to false.  */
extern DLL_VARIABLE bool allow_duplicates;

/* Read the input file from a stream.  Returns a list of messages.  */
extern msgdomain_list_ty *
       read_catalog_stream (FILE *fp,
                            const char *real_filename,
                            const char *logical_filename,
                            catalog_input_format_ty input_syntax);

/* Read the input file with the name INPUT_NAME.  The ending .po is added
   if necessary.  If INPUT_NAME is not an absolute file name and the file is
   not found, the list of directories in "dir-list.h" is searched.  Returns
   a list of messages.  */
extern msgdomain_list_ty *
       read_catalog_file (const char *input_name,
                          catalog_input_format_ty input_syntax);


#ifdef __cplusplus
}
#endif


#endif /* _READ_CATALOG_H */