1 /* Reading PO files, abstract class.
2 Copyright (C) 1995-1996, 1998, 2000-2003, 2005-2006, 2008-2009, 2012 Free Software Foundation, Inc.
4 This file was written by Peter Miller <millerp@canb.auug.org.au>
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_ABSTRACT_H
20 #define _READ_CATALOG_ABSTRACT_H
33 /* Note: the _t suffix is reserved by ANSI C, so the _ty suffix is
34 used to indicate a type name. */
36 /* The following pair of structures cooperate to create an "Object" in
37 the OO sense. We are simply doing it manually, rather than with the
38 help of an OO compiler. This implementation allows polymorphism
39 and inheritance - more than enough for the immediate needs. */
41 /* Forward declaration. */
42 struct abstract_catalog_reader_ty;
45 /* This first structure, playing the role of the "Class" in OO sense,
46 contains pointers to functions. Each function is a method for the
47 class (base or derived). Use a NULL pointer where no action is
50 typedef struct abstract_catalog_reader_class_ty
51 abstract_catalog_reader_class_ty;
52 struct abstract_catalog_reader_class_ty
54 /* how many bytes to malloc for an instance of this class */
57 /* what to do immediately after the instance is malloc()ed */
58 void (*constructor) (struct abstract_catalog_reader_ty *pop);
60 /* what to do immediately before the instance is free()ed */
61 void (*destructor) (struct abstract_catalog_reader_ty *pop);
63 /* This method is invoked before the parse, but after the file is
64 opened by the lexer. */
65 void (*parse_brief) (struct abstract_catalog_reader_ty *pop);
67 /* This method is invoked after the parse, but before the file is
68 closed by the lexer. The intention is to make consistency checks
69 against the file here, and emit the errors through the lex_error*
71 void (*parse_debrief) (struct abstract_catalog_reader_ty *pop);
73 /* what to do with a domain directive */
74 void (*directive_domain) (struct abstract_catalog_reader_ty *pop, char *name);
76 /* what to do with a message directive */
77 void (*directive_message) (struct abstract_catalog_reader_ty *pop,
79 char *msgid, lex_pos_ty *msgid_pos,
81 char *msgstr, size_t msgstr_len,
82 lex_pos_ty *msgstr_pos,
84 char *prev_msgid, char *prev_msgid_plural,
85 bool force_fuzzy, bool obsolete);
87 /* What to do with a plain-vanilla comment - the expectation is that
88 they will be accumulated, and added to the next message
89 definition seen. Or completely ignored. */
90 void (*comment) (struct abstract_catalog_reader_ty *pop, const char *s);
92 /* What to do with a comment that starts with a dot (i.e. extracted
93 by xgettext) - the expectation is that they will be accumulated,
94 and added to the next message definition seen. Or completely
96 void (*comment_dot) (struct abstract_catalog_reader_ty *pop, const char *s);
98 /* What to do with a file position seen in a comment (i.e. a message
99 location comment extracted by xgettext) - the expectation is that
100 they will be accumulated, and added to the next message
101 definition seen. Or completely ignored. */
102 void (*comment_filepos) (struct abstract_catalog_reader_ty *pop,
103 const char *s, size_t line);
105 /* What to do with a comment that starts with a ',' or '!' - this is a
106 special comment. One of the possible uses is to indicate a
107 inexact translation. */
108 void (*comment_special) (struct abstract_catalog_reader_ty *pop,
113 /* This next structure defines the base class passed to the methods.
114 Derived methods will often need to cast their first argument before
115 using it (this corresponds to the implicit 'this' argument in C++).
117 When declaring derived classes, use the ABSTRACT_CATALOG_READER_TY define
118 at the start of the structure, to declare inherited instance variables,
121 #define ABSTRACT_CATALOG_READER_TY \
122 abstract_catalog_reader_class_ty *methods;
124 typedef struct abstract_catalog_reader_ty abstract_catalog_reader_ty;
125 struct abstract_catalog_reader_ty
127 ABSTRACT_CATALOG_READER_TY
131 /* This structure describes a textual catalog input format. */
132 struct catalog_input_format
134 /* Parses the contents of FP, invoking the appropriate callbacks. */
135 void (*parse) (abstract_catalog_reader_ty *pop, FILE *fp,
136 const char *real_filename, const char *logical_filename);
138 /* Whether the parse function always produces messages encoded in UTF-8
143 typedef const struct catalog_input_format * catalog_input_format_ty;
146 /* Allocate a fresh abstract_catalog_reader_ty (or derived class) instance and
147 call its constructor. */
148 extern abstract_catalog_reader_ty *
149 catalog_reader_alloc (abstract_catalog_reader_class_ty *method_table);
151 /* Read a PO file from a stream, and dispatch to the various
152 abstract_catalog_reader_class_ty methods. */
154 catalog_reader_parse (abstract_catalog_reader_ty *pop, FILE *fp,
155 const char *real_filename,
156 const char *logical_filename,
157 catalog_input_format_ty input_syntax);
159 /* Call the destructor and deallocate a abstract_catalog_reader_ty (or derived
162 catalog_reader_free (abstract_catalog_reader_ty *pop);
165 /* Callbacks used by po-gram.y or po-lex.c, indirectly from
166 catalog_reader_parse. */
167 extern void po_callback_domain (char *name);
168 extern void po_callback_message (char *msgctxt,
169 char *msgid, lex_pos_ty *msgid_pos,
171 char *msgstr, size_t msgstr_len,
172 lex_pos_ty *msgstr_pos,
174 char *prev_msgid, char *prev_msgid_plural,
175 bool force_fuzzy, bool obsolete);
176 extern void po_callback_comment (const char *s);
177 extern void po_callback_comment_dot (const char *s);
178 extern void po_callback_comment_filepos (const char *s, size_t line);
179 extern void po_callback_comment_special (const char *s);
180 extern void po_callback_comment_dispatcher (const char *s);
182 /* Parse a special comment and put the result in *fuzzyp, formatp, *rangep,
184 extern void po_parse_comment_special (const char *s, bool *fuzzyp,
185 enum is_format formatp[NFORMATS],
186 struct argument_range *rangep,
187 enum is_wrap *wrapp);
195 #endif /* _READ_CATALOG_ABSTRACT_H */