1/* Reading PO files, abstract class.
2   Copyright (C) 1995-1996, 1998, 2000-2003, 2005 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 2, or (at your option)
9   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, write to the Free Software Foundation,
18   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20#ifndef _READ_PO_ABSTRACT_H
21#define _READ_PO_ABSTRACT_H
22
23#include "po-lex.h"
24#include "message.h"
25
26#include <stdbool.h>
27
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33
34/* Note: the _t suffix is reserved by ANSI C, so the _ty suffix is
35   used to indicate a type name.  */
36
37/* The following pair of structures cooperate to create an "Object" in
38   the OO sense.  We are simply doing it manually, rather than with the
39   help of an OO compiler.  This implementation allows polymorphism
40   and inheritance - more than enough for the immediate needs.  */
41
42/* Forward declaration.  */
43struct abstract_po_reader_ty;
44
45
46/* This first structure, playing the role of the "Class" in OO sense,
47   contains pointers to functions.  Each function is a method for the
48   class (base or derived).  Use a NULL pointer where no action is
49   required.  */
50
51typedef struct abstract_po_reader_class_ty abstract_po_reader_class_ty;
52struct abstract_po_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_po_reader_ty *pop);
59
60  /* what to do immediately before the instance is free()ed */
61  void (*destructor) (struct abstract_po_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_po_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_po_reader_ty *pop);
72
73  /* what to do with a domain directive */
74  void (*directive_domain) (struct abstract_po_reader_ty *pop, char *name);
75
76  /* what to do with a message directive */
77  void (*directive_message) (struct abstract_po_reader_ty *pop,
78			     char *msgid, lex_pos_ty *msgid_pos,
79			     char *msgid_plural,
80			     char *msgstr, size_t msgstr_len,
81			     lex_pos_ty *msgstr_pos,
82			     bool force_fuzzy, bool obsolete);
83
84  /* What to do with a plain-vanilla comment - the expectation is that
85     they will be accumulated, and added to the next message
86     definition seen.  Or completely ignored.  */
87  void (*comment) (struct abstract_po_reader_ty *pop, const char *s);
88
89  /* What to do with a comment that starts with a dot (i.e.  extracted
90     by xgettext) - the expectation is that they will be accumulated,
91     and added to the next message definition seen.  Or completely
92     ignored.  */
93  void (*comment_dot) (struct abstract_po_reader_ty *pop, const char *s);
94
95  /* What to do with a file position seen in a comment (i.e. a message
96     location comment extracted by xgettext) - the expectation is that
97     they will be accumulated, and added to the next message
98     definition seen.  Or completely ignored.  */
99  void (*comment_filepos) (struct abstract_po_reader_ty *pop,
100			   const char *s, size_t line);
101
102  /* What to do with a comment that starts with a ',' or '!' - this is a
103     special comment.  One of the possible uses is to indicate a
104     inexact translation.  */
105  void (*comment_special) (struct abstract_po_reader_ty *pop, const char *s);
106};
107
108
109/* This next structure defines the base class passed to the methods.
110   Derived methods will often need to cast their first argument before
111   using it (this corresponds to the implicit ``this'' argument in C++).
112
113   When declaring derived classes, use the ABSTRACT_PO_READER_TY define
114   at the start of the structure, to declare inherited instance variables,
115   etc.  */
116
117#define ABSTRACT_PO_READER_TY \
118  abstract_po_reader_class_ty *methods;
119
120typedef struct abstract_po_reader_ty abstract_po_reader_ty;
121struct abstract_po_reader_ty
122{
123  ABSTRACT_PO_READER_TY
124};
125
126
127/* Allocate a fresh abstract_po_reader_ty (or derived class) instance and
128   call its constructor.  */
129extern abstract_po_reader_ty *
130       po_reader_alloc (abstract_po_reader_class_ty *method_table);
131
132/* Kinds of PO file input syntaxes.  */
133enum input_syntax_ty
134{
135  syntax_po,
136  syntax_properties,
137  syntax_stringtable
138};
139typedef enum input_syntax_ty input_syntax_ty;
140
141/* Read a PO file from a stream, and dispatch to the various
142   abstract_po_reader_class_ty methods.  */
143extern void
144       po_scan (abstract_po_reader_ty *pop, FILE *fp,
145		const char *real_filename, const char *logical_filename,
146		input_syntax_ty syntax);
147
148/* Call the destructor and deallocate a abstract_po_reader_ty (or derived
149   class) instance.  */
150extern void
151       po_reader_free (abstract_po_reader_ty *pop);
152
153
154/* Callbacks used by po-gram.y or po-lex.c, indirectly from po_scan.  */
155extern void po_callback_domain (char *name);
156extern void po_callback_message (char *msgid, lex_pos_ty *msgid_pos,
157				 char *msgid_plural,
158				 char *msgstr, size_t msgstr_len,
159				 lex_pos_ty *msgstr_pos,
160				 bool force_fuzzy, bool obsolete);
161extern void po_callback_comment (const char *s);
162extern void po_callback_comment_dot (const char *s);
163extern void po_callback_comment_filepos (const char *s, size_t line);
164extern void po_callback_comment_special (const char *s);
165extern void po_callback_comment_dispatcher (const char *s);
166
167/* Parse a special comment and put the result in *fuzzyp, formatp, *wrapp.  */
168extern void po_parse_comment_special (const char *s, bool *fuzzyp,
169				      enum is_format formatp[NFORMATS],
170				      enum is_wrap *wrapp);
171
172
173#ifdef __cplusplus
174}
175#endif
176
177
178#endif /* _READ_PO_ABSTRACT_H */
179