• 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/gnulib-lib/libcroco/
1/* -*- Mode: C; indent-tabs-mode: ni; c-basic-offset: 8 -*- */
2
3/*
4 * This file is part of The Croco Library
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2.1 of the GNU General Public
8 * License as published by the Free Software Foundation.
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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 *
20 * See COPRYRIGHTS file for copyright information.
21 */
22
23#include <config.h>
24#include <string.h>
25#include "cr-doc-handler.h"
26#include "cr-parser.h"
27
28/**
29 *@CRDocHandler:
30 *
31 *The definition of the CRDocHandler class.
32 *Contains methods to instantiate, destroy,
33 *and initialyze instances of #CRDocHandler
34 *to custom values.
35 */
36
37#define PRIVATE(obj) (obj)->priv
38
39struct _CRDocHandlerPriv {
40	/**
41	 *This pointer is to hold an application parsing context.
42	 *For example, it used by the Object Model parser to
43	 *store it parsing context. #CRParser does not touch it, but
44	 *#CROMParser does. #CROMParser allocates this pointer at
45	 *the beginning of the css document, and frees it at the end
46	 *of the document.
47	 */
48        gpointer context;
49
50	/**
51	 *The place where #CROMParser puts the result of its parsing, if
52	 *any.
53	 */
54        gpointer result;
55	/**
56	 *a pointer to the parser used to parse
57	 *the current document.
58	 */
59	CRParser *parser ;
60};
61
62/**
63 * cr_doc_handler_new:
64 *Constructor of #CRDocHandler.
65 *
66 *Returns the newly built instance of
67 *#CRDocHandler
68 *
69 */
70CRDocHandler *
71cr_doc_handler_new (void)
72{
73        CRDocHandler *result = NULL;
74
75        result = g_try_malloc (sizeof (CRDocHandler));
76
77        g_return_val_if_fail (result, NULL);
78
79        memset (result, 0, sizeof (CRDocHandler));
80
81        result->priv = g_try_malloc (sizeof (CRDocHandlerPriv));
82        if (!result->priv) {
83                cr_utils_trace_info ("Out of memory exception");
84                g_free (result);
85                return NULL;
86        }
87
88        cr_doc_handler_set_default_sac_handler (result);
89
90        return result;
91}
92
93/**
94 * cr_doc_handler_get_ctxt:
95 *@a_this: the current instance of #CRDocHandler.
96 *@a_ctxt: out parameter. The new parsing context.
97 *
98 *Gets the private parsing context associated to the document handler
99 *The private parsing context is used by libcroco only.
100 *
101 *Returns CR_OK upon successfull completion, an error code otherwise.
102 */
103enum CRStatus
104cr_doc_handler_get_ctxt (CRDocHandler * a_this, gpointer * a_ctxt)
105{
106        g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
107
108        *a_ctxt = a_this->priv->context;
109
110        return CR_OK;
111}
112
113/**
114 * cr_doc_handler_set_ctxt:
115 *@a_this: the current instance of #CRDocHandler
116 *@a_ctxt: a pointer to the parsing context.
117 *
118 *Sets the private parsing context.
119 *This is used by libcroco only.
120 *Returns CR_OK upon successfull completion, an error code otherwise.
121 */
122enum CRStatus
123cr_doc_handler_set_ctxt (CRDocHandler * a_this, gpointer a_ctxt)
124{
125        g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
126        a_this->priv->context = a_ctxt;
127        return CR_OK;
128}
129
130/**
131 * cr_doc_handler_get_result:
132 *@a_this: the current instance of #CRDocHandler
133 *@a_result: out parameter. The returned result.
134 *
135 *Gets the private parsing result.
136 *The private parsing result is used by libcroco only.
137 *
138 *Returns CR_OK upon successfull completion, an error code otherwise.
139 */
140enum CRStatus
141cr_doc_handler_get_result (CRDocHandler * a_this, gpointer * a_result)
142{
143        g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
144
145        *a_result = a_this->priv->result;
146
147        return CR_OK;
148}
149
150/**
151 * cr_doc_handler_set_result:
152 *@a_this: the current instance of #CRDocHandler
153 *@a_result: the new result.
154 *
155 *Sets the private parsing context.
156 *This is used by libcroco only.
157 *
158 *Returns CR_OK upon successfull completion, an error code otherwise.
159 */
160enum CRStatus
161cr_doc_handler_set_result (CRDocHandler * a_this, gpointer a_result)
162{
163        g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
164        a_this->priv->result = a_result;
165        return CR_OK;
166}
167
168/**
169 *cr_doc_handler_set_default_sac_handler:
170 *@a_this: a pointer to the current instance of #CRDocHandler.
171 *
172 *Sets the sac handlers contained in the current
173 *instance of DocHandler to the default handlers.
174 *For the time being the default handlers are
175 *test handlers. This is expected to change in a
176 *near future, when the libcroco gets a bit debugged.
177 *
178 *Returns CR_OK upon successfull completion, an error code otherwise.
179 */
180enum CRStatus
181cr_doc_handler_set_default_sac_handler (CRDocHandler * a_this)
182{
183        g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
184
185        a_this->start_document = NULL;
186        a_this->end_document = NULL;
187        a_this->import_style = NULL;
188        a_this->namespace_declaration = NULL;
189        a_this->comment = NULL;
190        a_this->start_selector = NULL;
191        a_this->end_selector = NULL;
192        a_this->property = NULL;
193        a_this->start_font_face = NULL;
194        a_this->end_font_face = NULL;
195        a_this->start_media = NULL;
196        a_this->end_media = NULL;
197        a_this->start_page = NULL;
198        a_this->end_page = NULL;
199        a_this->ignorable_at_rule = NULL;
200        a_this->error = NULL;
201        a_this->unrecoverable_error = NULL;
202        return CR_OK;
203}
204
205/**
206 * cr_doc_handler_ref:
207 *@a_this: the current instance of #CRDocHandler.
208 */
209void
210cr_doc_handler_ref (CRDocHandler * a_this)
211{
212        g_return_if_fail (a_this);
213
214        a_this->ref_count++;
215}
216
217/**
218 * cr_doc_handler_unref:
219 *@a_this: the currrent instance of #CRDocHandler.
220 *
221 *Decreases the ref count of the current instance of #CRDocHandler.
222 *If the ref count reaches '0' then, destroys the instance.
223 *
224 *Returns TRUE if the instance as been destroyed, FALSE otherwise.
225 */
226gboolean
227cr_doc_handler_unref (CRDocHandler * a_this)
228{
229        g_return_val_if_fail (a_this, FALSE);
230
231        if (a_this->ref_count > 0) {
232                a_this->ref_count--;
233        }
234
235        if (a_this->ref_count == 0) {
236                cr_doc_handler_destroy (a_this);
237                return TRUE;
238        }
239        return FALSE ;
240}
241
242/**
243 * cr_doc_handler_destroy:
244 *@a_this: the instance of #CRDocHandler to
245 *destroy.
246 *
247 *The destructor of the #CRDocHandler class.
248 */
249void
250cr_doc_handler_destroy (CRDocHandler * a_this)
251{
252        g_return_if_fail (a_this);
253
254        if (a_this->priv) {
255                g_free (a_this->priv);
256                a_this->priv = NULL;
257        }
258        g_free (a_this);
259}
260
261/**
262 * cr_doc_handler_associate_a_parser:
263 *Associates a parser to the current document handler
264 *@a_this: the current instance of document handler.
265 *@a_parser: the parser to associate.
266 */
267void
268cr_doc_handler_associate_a_parser (CRDocHandler *a_this,
269				   gpointer a_parser)
270{
271	g_return_if_fail (a_this && PRIVATE (a_this)
272			  && a_parser) ;
273
274	PRIVATE (a_this)->parser = a_parser ;
275}
276