1 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
4 * This file is part of The Croco Library
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 Lesser General Public
8 * License as published by the Free Software Foundation.
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.
15 * You should have received a copy of the GNU Lesser 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
20 * Author: Dodji Seketeli
21 * See COPYRIGHTS file for copyright information.
26 #include "cr-om-parser.h"
31 *The definition of the CSS Object Model Parser.
32 *This parser uses (and sits) the SAC api of libcroco defined
33 *in cr-parser.h and cr-doc-handler.h
36 struct _CROMParserPriv {
40 #define PRIVATE(a_this) ((a_this)->priv)
43 *Forward declaration of a type defined later
46 struct _ParsingContext;
47 typedef struct _ParsingContext ParsingContext;
49 static ParsingContext *new_parsing_context (void);
51 static void destroy_context (ParsingContext * a_ctxt);
53 static void unrecoverable_error (CRDocHandler * a_this);
55 static void error (CRDocHandler * a_this);
57 static void property (CRDocHandler * a_this,
59 CRTerm * a_expression,
60 gboolean a_important);
62 static void end_selector (CRDocHandler * a_this,
63 CRSelector * a_selector_list);
65 static void start_selector (CRDocHandler * a_this,
66 CRSelector * a_selector_list);
68 static void start_font_face (CRDocHandler * a_this,
69 CRParsingLocation *a_location);
71 static void end_font_face (CRDocHandler * a_this);
73 static void end_document (CRDocHandler * a_this);
75 static void start_document (CRDocHandler * a_this);
77 static void charset (CRDocHandler * a_this,
79 CRParsingLocation *a_location);
81 static void start_page (CRDocHandler * a_this, CRString * a_page,
82 CRString * a_pseudo_page,
83 CRParsingLocation *a_location);
85 static void end_page (CRDocHandler * a_this, CRString * a_page,
86 CRString * a_pseudo_page);
88 static void start_media (CRDocHandler * a_this,
90 CRParsingLocation *a_location);
92 static void end_media (CRDocHandler * a_this,
93 GList * a_media_list);
95 static void import_style (CRDocHandler * a_this,
98 CRString * a_uri_default_ns,
99 CRParsingLocation *a_location);
101 struct _ParsingContext {
102 CRStyleSheet *stylesheet;
103 CRStatement *cur_stmt;
104 CRStatement *cur_media_stmt;
107 /********************************************
109 ********************************************/
111 static ParsingContext *
112 new_parsing_context (void)
114 ParsingContext *result = NULL;
116 result = g_try_malloc (sizeof (ParsingContext));
118 cr_utils_trace_info ("Out of Memory");
121 memset (result, 0, sizeof (ParsingContext));
126 destroy_context (ParsingContext * a_ctxt)
128 g_return_if_fail (a_ctxt);
130 if (a_ctxt->stylesheet) {
131 cr_stylesheet_destroy (a_ctxt->stylesheet);
132 a_ctxt->stylesheet = NULL;
134 if (a_ctxt->cur_stmt) {
135 cr_statement_destroy (a_ctxt->cur_stmt);
136 a_ctxt->cur_stmt = NULL;
142 cr_om_parser_init_default_sac_handler (CROMParser * a_this)
144 CRDocHandler *sac_handler = NULL;
145 gboolean free_hdlr_if_error = FALSE;
146 enum CRStatus status = CR_OK;
148 g_return_val_if_fail (a_this && PRIVATE (a_this)
149 && PRIVATE (a_this)->parser,
152 status = cr_parser_get_sac_handler (PRIVATE (a_this)->parser,
154 g_return_val_if_fail (status == CR_OK, status);
157 sac_handler = cr_doc_handler_new ();
158 free_hdlr_if_error = TRUE;
162 *initialyze here the sac handler.
164 sac_handler->start_document = start_document;
165 sac_handler->end_document = end_document;
166 sac_handler->start_selector = start_selector;
167 sac_handler->end_selector = end_selector;
168 sac_handler->property = property;
169 sac_handler->start_font_face = start_font_face;
170 sac_handler->end_font_face = end_font_face;
171 sac_handler->error = error;
172 sac_handler->unrecoverable_error = unrecoverable_error;
173 sac_handler->charset = charset;
174 sac_handler->start_page = start_page;
175 sac_handler->end_page = end_page;
176 sac_handler->start_media = start_media;
177 sac_handler->end_media = end_media;
178 sac_handler->import_style = import_style;
180 status = cr_parser_set_sac_handler (PRIVATE (a_this)->parser,
182 if (status == CR_OK) {
186 if (sac_handler && free_hdlr_if_error == TRUE) {
187 cr_doc_handler_destroy (sac_handler);
196 start_document (CRDocHandler * a_this)
198 ParsingContext *ctxt = NULL;
199 CRStyleSheet *stylesheet = NULL;
201 g_return_if_fail (a_this);
203 ctxt = new_parsing_context ();
204 g_return_if_fail (ctxt);
206 stylesheet = cr_stylesheet_new (NULL);
207 ctxt->stylesheet = stylesheet;
208 cr_doc_handler_set_ctxt (a_this, ctxt);
212 start_font_face (CRDocHandler * a_this,
213 CRParsingLocation *a_location)
215 enum CRStatus status = CR_OK;
216 ParsingContext *ctxt = NULL;
217 ParsingContext **ctxtptr = NULL;
219 g_return_if_fail (a_this);
221 g_return_if_fail (a_this);
223 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
224 g_return_if_fail (status == CR_OK && ctxt);
225 g_return_if_fail (ctxt->cur_stmt == NULL);
228 cr_statement_new_at_font_face_rule (ctxt->stylesheet, NULL);
230 g_return_if_fail (ctxt->cur_stmt);
234 end_font_face (CRDocHandler * a_this)
236 enum CRStatus status = CR_OK;
237 ParsingContext *ctxt = NULL;
238 ParsingContext **ctxtptr = NULL;
239 CRStatement *stmts = NULL;
241 g_return_if_fail (a_this);
243 g_return_if_fail (a_this);
245 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
246 g_return_if_fail (status == CR_OK && ctxt);
249 && ctxt->cur_stmt->type == AT_FONT_FACE_RULE_STMT
250 && ctxt->stylesheet);
252 stmts = cr_statement_append (ctxt->stylesheet->statements,
257 ctxt->stylesheet->statements = stmts;
259 ctxt->cur_stmt = NULL;
265 if (ctxt->cur_stmt) {
266 cr_statement_destroy (ctxt->cur_stmt);
267 ctxt->cur_stmt = NULL;
271 cr_statement_destroy (stmts);
277 end_document (CRDocHandler * a_this)
279 enum CRStatus status = CR_OK;
280 ParsingContext *ctxt = NULL;
281 ParsingContext **ctxtptr = NULL;
283 g_return_if_fail (a_this);
285 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
286 g_return_if_fail (status == CR_OK && ctxt);
288 if (!ctxt->stylesheet || ctxt->cur_stmt)
291 status = cr_doc_handler_set_result (a_this, ctxt->stylesheet);
292 g_return_if_fail (status == CR_OK);
294 ctxt->stylesheet = NULL;
295 destroy_context (ctxt);
296 cr_doc_handler_set_ctxt (a_this, NULL);
302 destroy_context (ctxt);
307 charset (CRDocHandler * a_this, CRString * a_charset,
308 CRParsingLocation *a_location)
310 enum CRStatus status = CR_OK;
311 CRStatement *stmt = NULL,
313 CRString *charset = NULL;
315 ParsingContext *ctxt = NULL;
316 ParsingContext **ctxtptr = NULL;
318 g_return_if_fail (a_this);
320 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
321 g_return_if_fail (status == CR_OK && ctxt);
322 g_return_if_fail (ctxt->stylesheet);
324 charset = cr_string_dup (a_charset) ;
325 stmt = cr_statement_new_at_charset_rule (ctxt->stylesheet, charset);
326 g_return_if_fail (stmt);
327 stmt2 = cr_statement_append (ctxt->stylesheet->statements, stmt);
330 cr_statement_destroy (stmt);
334 cr_string_destroy (charset);
338 ctxt->stylesheet->statements = stmt2;
343 start_page (CRDocHandler * a_this,
346 CRParsingLocation *a_location)
348 enum CRStatus status = CR_OK;
349 ParsingContext *ctxt = NULL;
350 ParsingContext **ctxtptr = NULL;
352 g_return_if_fail (a_this);
354 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
355 g_return_if_fail (status == CR_OK && ctxt);
356 g_return_if_fail (ctxt->cur_stmt == NULL);
358 ctxt->cur_stmt = cr_statement_new_at_page_rule
359 (ctxt->stylesheet, NULL, NULL, NULL);
361 ctxt->cur_stmt->kind.page_rule->name =
362 cr_string_dup (a_page) ;
364 if (!ctxt->cur_stmt->kind.page_rule->name) {
369 ctxt->cur_stmt->kind.page_rule->pseudo =
370 cr_string_dup (a_pseudo) ;
371 if (!ctxt->cur_stmt->kind.page_rule->pseudo) {
378 if (ctxt->cur_stmt) {
379 cr_statement_destroy (ctxt->cur_stmt);
380 ctxt->cur_stmt = NULL;
385 end_page (CRDocHandler * a_this,
387 CRString * a_pseudo_page)
389 enum CRStatus status = CR_OK;
390 ParsingContext *ctxt = NULL;
391 ParsingContext **ctxtptr = NULL;
392 CRStatement *stmt = NULL;
394 g_return_if_fail (a_this);
396 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
397 g_return_if_fail (status == CR_OK && ctxt);
398 g_return_if_fail (ctxt->cur_stmt
399 && ctxt->cur_stmt->type == AT_PAGE_RULE_STMT
400 && ctxt->stylesheet);
402 stmt = cr_statement_append (ctxt->stylesheet->statements,
406 ctxt->stylesheet->statements = stmt;
408 ctxt->cur_stmt = NULL;
411 if (ctxt->cur_stmt) {
412 cr_statement_destroy (ctxt->cur_stmt);
413 ctxt->cur_stmt = NULL;
415 a_page = NULL; /*keep compiler happy */
416 a_pseudo_page = NULL; /*keep compiler happy */
420 start_media (CRDocHandler * a_this,
421 GList * a_media_list,
422 CRParsingLocation *a_location)
424 enum CRStatus status = CR_OK;
425 ParsingContext *ctxt = NULL;
426 ParsingContext **ctxtptr = NULL;
427 GList *media_list = NULL;
429 g_return_if_fail (a_this);
431 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
432 g_return_if_fail (status == CR_OK && ctxt);
434 g_return_if_fail (ctxt
435 && ctxt->cur_stmt == NULL
436 && ctxt->cur_media_stmt == NULL
437 && ctxt->stylesheet);
439 /*duplicate the media_list */
440 media_list = cr_utils_dup_glist_of_cr_string
443 ctxt->cur_media_stmt =
444 cr_statement_new_at_media_rule
445 (ctxt->stylesheet, NULL, media_list);
450 end_media (CRDocHandler * a_this, GList * a_media_list)
452 enum CRStatus status = CR_OK;
453 ParsingContext *ctxt = NULL;
454 ParsingContext **ctxtptr = NULL;
455 CRStatement *stmts = NULL;
457 g_return_if_fail (a_this);
459 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
460 g_return_if_fail (status == CR_OK && ctxt);
461 g_return_if_fail (ctxt
462 && ctxt->cur_media_stmt
463 && ctxt->cur_media_stmt->type == AT_MEDIA_RULE_STMT
464 && ctxt->stylesheet);
466 stmts = cr_statement_append (ctxt->stylesheet->statements,
467 ctxt->cur_media_stmt);
469 cr_statement_destroy (ctxt->cur_media_stmt);
470 ctxt->cur_media_stmt = NULL;
473 ctxt->stylesheet->statements = stmts;
476 ctxt->cur_stmt = NULL ;
477 ctxt->cur_media_stmt = NULL ;
482 import_style (CRDocHandler * a_this,
483 GList * a_media_list,
485 CRString * a_uri_default_ns,
486 CRParsingLocation *a_location)
488 enum CRStatus status = CR_OK;
489 CRString *uri = NULL;
490 CRStatement *stmt = NULL,
492 ParsingContext *ctxt = NULL;
493 ParsingContext **ctxtptr = NULL;
494 GList *media_list = NULL ;
496 g_return_if_fail (a_this);
498 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
499 g_return_if_fail (status == CR_OK && ctxt);
500 g_return_if_fail (ctxt->stylesheet);
502 uri = cr_string_dup (a_uri) ;
504 media_list = cr_utils_dup_glist_of_cr_string (a_media_list) ;
505 stmt = cr_statement_new_at_import_rule
506 (ctxt->stylesheet, uri, media_list, NULL);
510 if (ctxt->cur_stmt) {
511 stmt2 = cr_statement_append (ctxt->cur_stmt, stmt);
514 ctxt->cur_stmt = stmt2;
518 stmt2 = cr_statement_append (ctxt->stylesheet->statements,
522 ctxt->stylesheet->statements = stmt2;
531 cr_string_destroy (uri);
535 cr_statement_destroy (stmt);
538 a_uri_default_ns = NULL; /*keep compiler happy */
542 start_selector (CRDocHandler * a_this, CRSelector * a_selector_list)
544 enum CRStatus status = CR_OK ;
545 ParsingContext *ctxt = NULL;
546 ParsingContext **ctxtptr = NULL;
548 g_return_if_fail (a_this);
550 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
551 g_return_if_fail (status == CR_OK && ctxt);
552 if (ctxt->cur_stmt) {
553 /*hmm, this should be NULL so free it */
554 cr_statement_destroy (ctxt->cur_stmt);
555 ctxt->cur_stmt = NULL;
558 ctxt->cur_stmt = cr_statement_new_ruleset
559 (ctxt->stylesheet, a_selector_list, NULL, NULL);
563 end_selector (CRDocHandler * a_this, CRSelector * a_selector_list)
565 enum CRStatus status = CR_OK;
566 ParsingContext *ctxt = NULL;
567 ParsingContext **ctxtptr = NULL;
569 g_return_if_fail (a_this);
571 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
572 g_return_if_fail (status == CR_OK && ctxt);
573 g_return_if_fail (ctxt->cur_stmt && ctxt->stylesheet);
575 if (ctxt->cur_stmt) {
576 CRStatement *stmts = NULL;
578 if (ctxt->cur_media_stmt) {
579 CRAtMediaRule *media_rule = NULL;
581 media_rule = ctxt->cur_media_stmt->kind.media_rule;
583 stmts = cr_statement_append
584 (media_rule->rulesets, ctxt->cur_stmt);
588 ("Could not append a new statement");
589 cr_statement_destroy (media_rule->rulesets);
590 ctxt->cur_media_stmt->
591 kind.media_rule->rulesets = NULL;
594 media_rule->rulesets = stmts;
595 ctxt->cur_stmt = NULL;
597 stmts = cr_statement_append
598 (ctxt->stylesheet->statements,
602 ("Could not append a new statement");
603 cr_statement_destroy (ctxt->cur_stmt);
604 ctxt->cur_stmt = NULL;
607 ctxt->stylesheet->statements = stmts;
608 ctxt->cur_stmt = NULL;
612 a_selector_list = NULL; /*keep compiler happy */
616 property (CRDocHandler * a_this,
618 CRTerm * a_expression,
619 gboolean a_important)
621 enum CRStatus status = CR_OK;
622 ParsingContext *ctxt = NULL;
623 ParsingContext **ctxtptr = NULL;
624 CRDeclaration *decl = NULL,
626 CRString *str = NULL;
628 g_return_if_fail (a_this);
630 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
631 g_return_if_fail (status == CR_OK && ctxt);
634 *make sure a current ruleset statement has been allocated
640 (ctxt->cur_stmt->type == RULESET_STMT
641 || ctxt->cur_stmt->type == AT_FONT_FACE_RULE_STMT
642 || ctxt->cur_stmt->type == AT_PAGE_RULE_STMT));
645 str = cr_string_dup (a_name);
646 g_return_if_fail (str);
649 /*instanciates a new declaration */
650 decl = cr_declaration_new (ctxt->cur_stmt, str, a_expression);
651 g_return_if_fail (decl);
653 decl->important = a_important;
655 *add the new declaration to the current statement
658 switch (ctxt->cur_stmt->type) {
660 decl2 = cr_declaration_append
661 (ctxt->cur_stmt->kind.ruleset->decl_list, decl);
663 cr_declaration_destroy (decl);
665 ("Could not append decl to ruleset");
668 ctxt->cur_stmt->kind.ruleset->decl_list = decl2;
673 case AT_FONT_FACE_RULE_STMT:
674 decl2 = cr_declaration_append
675 (ctxt->cur_stmt->kind.font_face_rule->decl_list,
678 cr_declaration_destroy (decl);
680 ("Could not append decl to ruleset");
683 ctxt->cur_stmt->kind.font_face_rule->decl_list = decl2;
687 case AT_PAGE_RULE_STMT:
688 decl2 = cr_declaration_append
689 (ctxt->cur_stmt->kind.page_rule->decl_list, decl);
691 cr_declaration_destroy (decl);
693 ("Could not append decl to ruleset");
696 ctxt->cur_stmt->kind.page_rule->decl_list = decl2;
715 cr_declaration_destroy (decl);
721 error (CRDocHandler * a_this)
723 enum CRStatus status = CR_OK;
724 ParsingContext *ctxt = NULL;
725 ParsingContext **ctxtptr = NULL;
727 g_return_if_fail (a_this);
729 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
730 g_return_if_fail (status == CR_OK && ctxt);
732 if (ctxt->cur_stmt) {
733 cr_statement_destroy (ctxt->cur_stmt);
734 ctxt->cur_stmt = NULL;
739 unrecoverable_error (CRDocHandler * a_this)
741 enum CRStatus status = CR_OK;
742 ParsingContext *ctxt = NULL;
743 ParsingContext **ctxtptr = NULL;
746 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
747 g_return_if_fail (status == CR_OK);
750 if (ctxt->stylesheet) {
751 status = cr_doc_handler_set_result
752 (a_this, ctxt->stylesheet);
753 g_return_if_fail (status == CR_OK);
756 cr_doc_handler_set_ctxt (a_this, NULL);
760 /********************************************
762 ********************************************/
766 *@a_input: the input stream.
768 *Constructor of the CROMParser.
769 *Returns the newly built instance of #CROMParser.
772 cr_om_parser_new (CRInput * a_input)
774 CROMParser *result = NULL;
775 enum CRStatus status = CR_OK;
777 result = g_try_malloc (sizeof (CROMParser));
780 cr_utils_trace_info ("Out of memory");
784 memset (result, 0, sizeof (CROMParser));
785 PRIVATE (result) = g_try_malloc (sizeof (CROMParserPriv));
787 if (!PRIVATE (result)) {
788 cr_utils_trace_info ("Out of memory");
792 memset (PRIVATE (result), 0, sizeof (CROMParserPriv));
794 PRIVATE (result)->parser = cr_parser_new_from_input (a_input);
796 if (!PRIVATE (result)->parser) {
797 cr_utils_trace_info ("parsing instanciation failed");
801 status = cr_om_parser_init_default_sac_handler (result);
803 if (status != CR_OK) {
812 cr_om_parser_destroy (result);
819 * cr_om_parser_parse_buf:
820 *@a_this: the current instance of #CROMParser.
821 *@a_buf: the in memory buffer to parse.
822 *@a_len: the length of the in memory buffer in number of bytes.
823 *@a_enc: the encoding of the in memory buffer.
824 *@a_result: out parameter the resulting style sheet
826 *Parses the content of an in memory buffer.
828 *Returns CR_OK upon successfull completion, an error code otherwise.
831 cr_om_parser_parse_buf (CROMParser * a_this,
832 const guchar * a_buf,
834 enum CREncoding a_enc, CRStyleSheet ** a_result)
837 enum CRStatus status = CR_OK;
839 g_return_val_if_fail (a_this && a_result, CR_BAD_PARAM_ERROR);
841 if (!PRIVATE (a_this)->parser) {
842 PRIVATE (a_this)->parser = cr_parser_new (NULL);
845 status = cr_parser_parse_buf (PRIVATE (a_this)->parser,
846 a_buf, a_len, a_enc);
848 if (status == CR_OK) {
849 CRStyleSheet *result = NULL;
850 CRStyleSheet **resultptr = NULL;
851 CRDocHandler *sac_handler = NULL;
853 cr_parser_get_sac_handler (PRIVATE (a_this)->parser,
855 g_return_val_if_fail (sac_handler, CR_ERROR);
857 status = cr_doc_handler_get_result (sac_handler,
858 (gpointer *) resultptr);
859 g_return_val_if_fail (status == CR_OK, status);
869 * cr_om_parser_simply_parse_buf:
870 *@a_buf: the css2 in memory buffer.
871 *@a_len: the length of the in memory buffer.
872 *@a_enc: the encoding of the in memory buffer.
873 *@a_result: out parameter. The resulting css2 style sheet.
875 *The simpler way to parse an in memory css2 buffer.
877 *Returns CR_OK upon successfull completion, an error code otherwise.
880 cr_om_parser_simply_parse_buf (const guchar * a_buf,
882 enum CREncoding a_enc,
883 CRStyleSheet ** a_result)
885 CROMParser *parser = NULL;
886 enum CRStatus status = CR_OK;
888 parser = cr_om_parser_new (NULL);
890 cr_utils_trace_info ("Could not create om parser");
891 cr_utils_trace_info ("System possibly out of memory");
895 status = cr_om_parser_parse_buf (parser, a_buf, a_len,
899 cr_om_parser_destroy (parser);
907 * cr_om_parser_parse_file:
908 *@a_this: the current instance of the cssom parser.
909 *@a_file_uri: the uri of the file.
910 *(only local file paths are suppported so far)
911 *@a_enc: the encoding of the file.
912 *@a_result: out parameter. A pointer
913 *the build css object model.
915 *Parses a css2 stylesheet contained
918 * Returns CR_OK upon succesful completion, an error code otherwise.
921 cr_om_parser_parse_file (CROMParser * a_this,
922 const guchar * a_file_uri,
923 enum CREncoding a_enc, CRStyleSheet ** a_result)
925 enum CRStatus status = CR_OK;
927 g_return_val_if_fail (a_this && a_file_uri && a_result,
930 if (!PRIVATE (a_this)->parser) {
931 PRIVATE (a_this)->parser = cr_parser_new_from_file
935 status = cr_parser_parse_file (PRIVATE (a_this)->parser,
938 if (status == CR_OK) {
939 CRStyleSheet *result = NULL;
940 CRStyleSheet **resultptr = NULL;
941 CRDocHandler *sac_handler = NULL;
943 cr_parser_get_sac_handler (PRIVATE (a_this)->parser,
945 g_return_val_if_fail (sac_handler, CR_ERROR);
947 status = cr_doc_handler_get_result
948 (sac_handler, (gpointer *) resultptr);
949 g_return_val_if_fail (status == CR_OK, status);
958 * cr_om_parser_simply_parse_file:
959 *@a_file_path: the css2 local file path.
960 *@a_enc: the file encoding.
961 *@a_result: out parameter. The returned css stylesheet.
962 *Must be freed by the caller using cr_stylesheet_destroy.
964 *The simpler method to parse a css2 file.
966 *Returns CR_OK upon successfull completion, an error code otherwise.
967 *Note that this method uses cr_om_parser_parse_file() so both methods
968 *have the same return values.
971 cr_om_parser_simply_parse_file (const guchar * a_file_path,
972 enum CREncoding a_enc,
973 CRStyleSheet ** a_result)
975 CROMParser *parser = NULL;
976 enum CRStatus status = CR_OK;
978 parser = cr_om_parser_new (NULL);
980 cr_utils_trace_info ("Could not allocate om parser");
981 cr_utils_trace_info ("System may be out of memory");
985 status = cr_om_parser_parse_file (parser, a_file_path,
988 cr_om_parser_destroy (parser);
996 * cr_om_parser_parse_paths_to_cascade:
997 *@a_this: the current instance of #CROMParser
998 *@a_author_path: the path to the author stylesheet
999 *@a_user_path: the path to the user stylesheet
1000 *@a_ua_path: the path to the User Agent stylesheet
1001 *@a_encoding: the encoding of the sheets.
1002 *@a_result: out parameter. The resulting cascade if the parsing
1005 *Parses three sheets located by their paths and build a cascade
1007 *Returns CR_OK upon successful completion, an error code otherwise
1010 cr_om_parser_parse_paths_to_cascade (CROMParser * a_this,
1011 const guchar * a_author_path,
1012 const guchar * a_user_path,
1013 const guchar * a_ua_path,
1014 enum CREncoding a_encoding,
1015 CRCascade ** a_result)
1017 enum CRStatus status = CR_OK;
1019 /*0->author sheet, 1->user sheet, 2->UA sheet */
1020 CRStyleSheet *sheets[3];
1022 CRCascade *result = NULL;
1025 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
1027 memset (sheets, 0, sizeof (CRStyleSheet*) * 3);
1028 paths[0] = (guchar *) a_author_path;
1029 paths[1] = (guchar *) a_user_path;
1030 paths[2] = (guchar *) a_ua_path;
1032 for (i = 0; i < 3; i++) {
1033 status = cr_om_parser_parse_file (a_this, paths[i],
1034 a_encoding, &sheets[i]);
1035 if (status != CR_OK) {
1037 cr_stylesheet_unref (sheets[i]);
1043 result = cr_cascade_new (sheets[0], sheets[1], sheets[2]);
1045 for (i = 0; i < 3; i++) {
1046 cr_stylesheet_unref (sheets[i]);
1056 * cr_om_parser_simply_parse_paths_to_cascade:
1057 *@a_author_path: the path to the author stylesheet
1058 *@a_user_path: the path to the user stylesheet
1059 *@a_ua_path: the path to the User Agent stylesheet
1060 *@a_encoding: the encoding of the sheets.
1061 *@a_result: out parameter. The resulting cascade if the parsing
1064 *Parses three sheets located by their paths and build a cascade
1066 *Returns CR_OK upon successful completion, an error code otherwise
1069 cr_om_parser_simply_parse_paths_to_cascade (const guchar * a_author_path,
1070 const guchar * a_user_path,
1071 const guchar * a_ua_path,
1072 enum CREncoding a_encoding,
1073 CRCascade ** a_result)
1075 enum CRStatus status = CR_OK;
1076 CROMParser *parser = NULL;
1078 parser = cr_om_parser_new (NULL);
1080 cr_utils_trace_info ("could not allocated om parser");
1081 cr_utils_trace_info ("System may be out of memory");
1084 status = cr_om_parser_parse_paths_to_cascade (parser,
1088 a_encoding, a_result);
1090 cr_om_parser_destroy (parser);
1097 * cr_om_parser_destroy:
1098 *@a_this: the current instance of #CROMParser.
1100 *Destructor of the #CROMParser.
1103 cr_om_parser_destroy (CROMParser * a_this)
1105 g_return_if_fail (a_this && PRIVATE (a_this));
1107 if (PRIVATE (a_this)->parser) {
1108 cr_parser_destroy (PRIVATE (a_this)->parser);
1109 PRIVATE (a_this)->parser = NULL;
1112 if (PRIVATE (a_this)) {
1113 g_free (PRIVATE (a_this));
1114 PRIVATE (a_this) = NULL;