• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/gettext-0.17/gettext-tools/src/
1/* Reading PO files, abstract class.
2   Copyright (C) 1995-1996, 1998, 2000-2003, 2005-2006 Free Software Foundation, Inc.
3
4   This file was written by Peter Miller <millerp@canb.auug.org.au>
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_ABSTRACT_H
20#define _READ_CATALOG_ABSTRACT_H
21
22#include "po-lex.h"
23#include "message.h"
24
25#include <stdbool.h>
26
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32
33/* Note: the _t suffix is reserved by ANSI C, so the _ty suffix is
34   used to indicate a type name.  */
35
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.  */
40
41/* Forward declaration.  */
42struct abstract_catalog_reader_ty;
43
44
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
48   required.  */
49
50typedef struct abstract_catalog_reader_class_ty
51        abstract_catalog_reader_class_ty;
52struct abstract_catalog_reader_class_ty
53{
54  /* how many bytes to malloc for an instance of this class */
55  size_t size;
56
57  /* what to do immediately after the instance is malloc()ed */
58  void (*constructor) (struct abstract_catalog_reader_ty *pop);
59
60  /* what to do immediately before the instance is free()ed */
61  void (*destructor) (struct abstract_catalog_reader_ty *pop);
62
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);
66
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*
70     functions.  */
71  void (*parse_debrief) (struct abstract_catalog_reader_ty *pop);
72
73  /* what to do with a domain directive */
74  void (*directive_domain) (struct abstract_catalog_reader_ty *pop, char *name);
75
76  /* what to do with a message directive */
77  void (*directive_message) (struct abstract_catalog_reader_ty *pop,
78			     char *msgctxt,
79			     char *msgid, lex_pos_ty *msgid_pos,
80			     char *msgid_plural,
81			     char *msgstr, size_t msgstr_len,
82			     lex_pos_ty *msgstr_pos,
83			     char *prev_msgctxt,
84			     char *prev_msgid, char *prev_msgid_plural,
85			     bool force_fuzzy, bool obsolete);
86
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);
91
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
95     ignored.  */
96  void (*comment_dot) (struct abstract_catalog_reader_ty *pop, const char *s);
97
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);
104
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,
109			   const char *s);
110};
111
112
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++).
116
117   When declaring derived classes, use the ABSTRACT_CATALOG_READER_TY define
118   at the start of the structure, to declare inherited instance variables,
119   etc.  */
120
121#define ABSTRACT_CATALOG_READER_TY \
122  abstract_catalog_reader_class_ty *methods;
123
124typedef struct abstract_catalog_reader_ty abstract_catalog_reader_ty;
125struct abstract_catalog_reader_ty
126{
127  ABSTRACT_CATALOG_READER_TY
128};
129
130
131/* This structure describes a textual catalog input format.  */
132struct catalog_input_format
133{
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);
137
138  /* Whether the parse function always produces messages encoded in UTF-8
139     encoding.  */
140  bool produces_utf8;
141};
142
143typedef const struct catalog_input_format * catalog_input_format_ty;
144
145
146/* Allocate a fresh abstract_catalog_reader_ty (or derived class) instance and
147   call its constructor.  */
148extern abstract_catalog_reader_ty *
149       catalog_reader_alloc (abstract_catalog_reader_class_ty *method_table);
150
151/* Read a PO file from a stream, and dispatch to the various
152   abstract_catalog_reader_class_ty methods.  */
153extern void
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);
158
159/* Call the destructor and deallocate a abstract_catalog_reader_ty (or derived
160   class) instance.  */
161extern void
162       catalog_reader_free (abstract_catalog_reader_ty *pop);
163
164
165/* Callbacks used by po-gram.y or po-lex.c, indirectly from
166   catalog_reader_parse.  */
167extern void po_callback_domain (char *name);
168extern void po_callback_message (char *msgctxt,
169				 char *msgid, lex_pos_ty *msgid_pos,
170				 char *msgid_plural,
171				 char *msgstr, size_t msgstr_len,
172				 lex_pos_ty *msgstr_pos,
173				 char *prev_msgctxt,
174				 char *prev_msgid, char *prev_msgid_plural,
175				 bool force_fuzzy, bool obsolete);
176extern void po_callback_comment (const char *s);
177extern void po_callback_comment_dot (const char *s);
178extern void po_callback_comment_filepos (const char *s, size_t line);
179extern void po_callback_comment_special (const char *s);
180extern void po_callback_comment_dispatcher (const char *s);
181
182/* Parse a special comment and put the result in *fuzzyp, formatp, *wrapp.  */
183extern void po_parse_comment_special (const char *s, bool *fuzzyp,
184				      enum is_format formatp[NFORMATS],
185				      enum is_wrap *wrapp);
186
187
188#ifdef __cplusplus
189}
190#endif
191
192
193#endif /* _READ_CATALOG_ABSTRACT_H */
194