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.
27 #include "cr-om-parser.h"
32 *The definition of the CSS Object Model Parser.
33 *This parser uses (and sits) the SAC api of libcroco defined
34 *in cr-parser.h and cr-doc-handler.h
37 struct _CROMParserPriv {
41 #define PRIVATE(a_this) ((a_this)->priv)
44 *Forward declaration of a type defined later
47 struct _ParsingContext;
48 typedef struct _ParsingContext ParsingContext;
50 static ParsingContext *new_parsing_context (void);
52 static void destroy_context (ParsingContext * a_ctxt);
54 static void unrecoverable_error (CRDocHandler * a_this);
56 static void error (CRDocHandler * a_this);
58 static void property (CRDocHandler * a_this,
60 CRTerm * a_expression,
61 gboolean a_important);
63 static void end_selector (CRDocHandler * a_this,
64 CRSelector * a_selector_list);
66 static void start_selector (CRDocHandler * a_this,
67 CRSelector * a_selector_list);
69 static void start_font_face (CRDocHandler * a_this,
70 CRParsingLocation *a_location);
72 static void end_font_face (CRDocHandler * a_this);
74 static void end_document (CRDocHandler * a_this);
76 static void start_document (CRDocHandler * a_this);
78 static void charset (CRDocHandler * a_this,
80 CRParsingLocation *a_location);
82 static void start_page (CRDocHandler * a_this, CRString * a_page,
83 CRString * a_pseudo_page,
84 CRParsingLocation *a_location);
86 static void end_page (CRDocHandler * a_this, CRString * a_page,
87 CRString * a_pseudo_page);
89 static void start_media (CRDocHandler * a_this,
91 CRParsingLocation *a_location);
93 static void end_media (CRDocHandler * a_this,
94 GList * a_media_list);
96 static void import_style (CRDocHandler * a_this,
99 CRString * a_uri_default_ns,
100 CRParsingLocation *a_location);
102 struct _ParsingContext {
103 CRStyleSheet *stylesheet;
104 CRStatement *cur_stmt;
105 CRStatement *cur_media_stmt;
108 /********************************************
110 ********************************************/
112 static ParsingContext *
113 new_parsing_context (void)
115 ParsingContext *result = NULL;
117 result = g_try_malloc (sizeof (ParsingContext));
119 cr_utils_trace_info ("Out of Memory");
122 memset (result, 0, sizeof (ParsingContext));
127 destroy_context (ParsingContext * a_ctxt)
129 g_return_if_fail (a_ctxt);
131 if (a_ctxt->stylesheet) {
132 cr_stylesheet_destroy (a_ctxt->stylesheet);
133 a_ctxt->stylesheet = NULL;
135 if (a_ctxt->cur_stmt) {
136 cr_statement_destroy (a_ctxt->cur_stmt);
137 a_ctxt->cur_stmt = NULL;
143 cr_om_parser_init_default_sac_handler (CROMParser * a_this)
145 CRDocHandler *sac_handler = NULL;
146 gboolean free_hdlr_if_error = FALSE;
147 enum CRStatus status = CR_OK;
149 g_return_val_if_fail (a_this && PRIVATE (a_this)
150 && PRIVATE (a_this)->parser,
153 status = cr_parser_get_sac_handler (PRIVATE (a_this)->parser,
155 g_return_val_if_fail (status == CR_OK, status);
158 sac_handler = cr_doc_handler_new ();
159 free_hdlr_if_error = TRUE;
163 *initialyze here the sac handler.
165 sac_handler->start_document = start_document;
166 sac_handler->end_document = end_document;
167 sac_handler->start_selector = start_selector;
168 sac_handler->end_selector = end_selector;
169 sac_handler->property = property;
170 sac_handler->start_font_face = start_font_face;
171 sac_handler->end_font_face = end_font_face;
172 sac_handler->error = error;
173 sac_handler->unrecoverable_error = unrecoverable_error;
174 sac_handler->charset = charset;
175 sac_handler->start_page = start_page;
176 sac_handler->end_page = end_page;
177 sac_handler->start_media = start_media;
178 sac_handler->end_media = end_media;
179 sac_handler->import_style = import_style;
181 status = cr_parser_set_sac_handler (PRIVATE (a_this)->parser,
183 if (status == CR_OK) {
187 if (sac_handler && free_hdlr_if_error == TRUE) {
188 cr_doc_handler_destroy (sac_handler);
197 start_document (CRDocHandler * a_this)
199 ParsingContext *ctxt = NULL;
200 CRStyleSheet *stylesheet = NULL;
202 g_return_if_fail (a_this);
204 ctxt = new_parsing_context ();
205 g_return_if_fail (ctxt);
207 stylesheet = cr_stylesheet_new (NULL);
208 ctxt->stylesheet = stylesheet;
209 cr_doc_handler_set_ctxt (a_this, ctxt);
213 start_font_face (CRDocHandler * a_this,
214 CRParsingLocation *a_location)
216 enum CRStatus status = CR_OK;
217 ParsingContext *ctxt = NULL;
218 ParsingContext **ctxtptr = NULL;
220 g_return_if_fail (a_this);
222 g_return_if_fail (a_this);
224 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
225 g_return_if_fail (status == CR_OK && ctxt);
226 g_return_if_fail (ctxt->cur_stmt == NULL);
229 cr_statement_new_at_font_face_rule (ctxt->stylesheet, NULL);
231 g_return_if_fail (ctxt->cur_stmt);
235 end_font_face (CRDocHandler * a_this)
237 enum CRStatus status = CR_OK;
238 ParsingContext *ctxt = NULL;
239 ParsingContext **ctxtptr = NULL;
240 CRStatement *stmts = NULL;
242 g_return_if_fail (a_this);
244 g_return_if_fail (a_this);
246 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
247 g_return_if_fail (status == CR_OK && ctxt);
250 && ctxt->cur_stmt->type == AT_FONT_FACE_RULE_STMT
251 && ctxt->stylesheet);
253 stmts = cr_statement_append (ctxt->stylesheet->statements,
258 ctxt->stylesheet->statements = stmts;
260 ctxt->cur_stmt = NULL;
266 if (ctxt->cur_stmt) {
267 cr_statement_destroy (ctxt->cur_stmt);
268 ctxt->cur_stmt = NULL;
272 cr_statement_destroy (stmts);
278 end_document (CRDocHandler * a_this)
280 enum CRStatus status = CR_OK;
281 ParsingContext *ctxt = NULL;
282 ParsingContext **ctxtptr = NULL;
284 g_return_if_fail (a_this);
286 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
287 g_return_if_fail (status == CR_OK && ctxt);
289 if (!ctxt->stylesheet || ctxt->cur_stmt)
292 status = cr_doc_handler_set_result (a_this, ctxt->stylesheet);
293 g_return_if_fail (status == CR_OK);
295 ctxt->stylesheet = NULL;
296 destroy_context (ctxt);
297 cr_doc_handler_set_ctxt (a_this, NULL);
303 destroy_context (ctxt);
308 charset (CRDocHandler * a_this, CRString * a_charset,
309 CRParsingLocation *a_location)
311 enum CRStatus status = CR_OK;
312 CRStatement *stmt = NULL,
314 CRString *charset = NULL;
316 ParsingContext *ctxt = NULL;
317 ParsingContext **ctxtptr = NULL;
319 g_return_if_fail (a_this);
321 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
322 g_return_if_fail (status == CR_OK && ctxt);
323 g_return_if_fail (ctxt->stylesheet);
325 charset = cr_string_dup (a_charset) ;
326 stmt = cr_statement_new_at_charset_rule (ctxt->stylesheet, charset);
327 g_return_if_fail (stmt);
328 stmt2 = cr_statement_append (ctxt->stylesheet->statements, stmt);
331 cr_statement_destroy (stmt);
335 cr_string_destroy (charset);
339 ctxt->stylesheet->statements = stmt2;
344 start_page (CRDocHandler * a_this,
347 CRParsingLocation *a_location)
349 enum CRStatus status = CR_OK;
350 ParsingContext *ctxt = NULL;
351 ParsingContext **ctxtptr = NULL;
353 g_return_if_fail (a_this);
355 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
356 g_return_if_fail (status == CR_OK && ctxt);
357 g_return_if_fail (ctxt->cur_stmt == NULL);
359 ctxt->cur_stmt = cr_statement_new_at_page_rule
360 (ctxt->stylesheet, NULL, NULL, NULL);
362 ctxt->cur_stmt->kind.page_rule->name =
363 cr_string_dup (a_page) ;
365 if (!ctxt->cur_stmt->kind.page_rule->name) {
370 ctxt->cur_stmt->kind.page_rule->pseudo =
371 cr_string_dup (a_pseudo) ;
372 if (!ctxt->cur_stmt->kind.page_rule->pseudo) {
379 if (ctxt->cur_stmt) {
380 cr_statement_destroy (ctxt->cur_stmt);
381 ctxt->cur_stmt = NULL;
386 end_page (CRDocHandler * a_this,
388 CRString * a_pseudo_page)
390 enum CRStatus status = CR_OK;
391 ParsingContext *ctxt = NULL;
392 ParsingContext **ctxtptr = NULL;
393 CRStatement *stmt = NULL;
395 g_return_if_fail (a_this);
397 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
398 g_return_if_fail (status == CR_OK && ctxt);
399 g_return_if_fail (ctxt->cur_stmt
400 && ctxt->cur_stmt->type == AT_PAGE_RULE_STMT
401 && ctxt->stylesheet);
403 stmt = cr_statement_append (ctxt->stylesheet->statements,
407 ctxt->stylesheet->statements = stmt;
409 ctxt->cur_stmt = NULL;
412 if (ctxt->cur_stmt) {
413 cr_statement_destroy (ctxt->cur_stmt);
414 ctxt->cur_stmt = NULL;
416 a_page = NULL; /*keep compiler happy */
417 a_pseudo_page = NULL; /*keep compiler happy */
421 start_media (CRDocHandler * a_this,
422 GList * a_media_list,
423 CRParsingLocation *a_location)
425 enum CRStatus status = CR_OK;
426 ParsingContext *ctxt = NULL;
427 ParsingContext **ctxtptr = NULL;
428 GList *media_list = NULL;
430 g_return_if_fail (a_this);
432 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
433 g_return_if_fail (status == CR_OK && ctxt);
435 g_return_if_fail (ctxt
436 && ctxt->cur_stmt == NULL
437 && ctxt->cur_media_stmt == NULL
438 && ctxt->stylesheet);
440 /*duplicate the media_list */
441 media_list = cr_utils_dup_glist_of_cr_string
444 ctxt->cur_media_stmt =
445 cr_statement_new_at_media_rule
446 (ctxt->stylesheet, NULL, media_list);
451 end_media (CRDocHandler * a_this, GList * a_media_list)
453 enum CRStatus status = CR_OK;
454 ParsingContext *ctxt = NULL;
455 ParsingContext **ctxtptr = NULL;
456 CRStatement *stmts = NULL;
458 g_return_if_fail (a_this);
460 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
461 g_return_if_fail (status == CR_OK && ctxt);
462 g_return_if_fail (ctxt
463 && ctxt->cur_media_stmt
464 && ctxt->cur_media_stmt->type == AT_MEDIA_RULE_STMT
465 && ctxt->stylesheet);
467 stmts = cr_statement_append (ctxt->stylesheet->statements,
468 ctxt->cur_media_stmt);
470 cr_statement_destroy (ctxt->cur_media_stmt);
471 ctxt->cur_media_stmt = NULL;
474 ctxt->stylesheet->statements = stmts;
477 ctxt->cur_stmt = NULL ;
478 ctxt->cur_media_stmt = NULL ;
483 import_style (CRDocHandler * a_this,
484 GList * a_media_list,
486 CRString * a_uri_default_ns,
487 CRParsingLocation *a_location)
489 enum CRStatus status = CR_OK;
490 CRString *uri = NULL;
491 CRStatement *stmt = NULL,
493 ParsingContext *ctxt = NULL;
494 ParsingContext **ctxtptr = NULL;
495 GList *media_list = NULL ;
497 g_return_if_fail (a_this);
499 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
500 g_return_if_fail (status == CR_OK && ctxt);
501 g_return_if_fail (ctxt->stylesheet);
503 uri = cr_string_dup (a_uri) ;
505 media_list = cr_utils_dup_glist_of_cr_string (a_media_list) ;
506 stmt = cr_statement_new_at_import_rule
507 (ctxt->stylesheet, uri, media_list, NULL);
511 if (ctxt->cur_stmt) {
512 stmt2 = cr_statement_append (ctxt->cur_stmt, stmt);
515 ctxt->cur_stmt = stmt2;
519 stmt2 = cr_statement_append (ctxt->stylesheet->statements,
523 ctxt->stylesheet->statements = stmt2;
532 cr_string_destroy (uri);
536 cr_statement_destroy (stmt);
539 a_uri_default_ns = NULL; /*keep compiler happy */
543 start_selector (CRDocHandler * a_this, CRSelector * a_selector_list)
545 enum CRStatus status = CR_OK ;
546 ParsingContext *ctxt = NULL;
547 ParsingContext **ctxtptr = NULL;
549 g_return_if_fail (a_this);
551 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
552 g_return_if_fail (status == CR_OK && ctxt);
553 if (ctxt->cur_stmt) {
554 /*hmm, this should be NULL so free it */
555 cr_statement_destroy (ctxt->cur_stmt);
556 ctxt->cur_stmt = NULL;
559 ctxt->cur_stmt = cr_statement_new_ruleset
560 (ctxt->stylesheet, a_selector_list, NULL, NULL);
564 end_selector (CRDocHandler * a_this, CRSelector * a_selector_list)
566 enum CRStatus status = CR_OK;
567 ParsingContext *ctxt = NULL;
568 ParsingContext **ctxtptr = NULL;
570 g_return_if_fail (a_this);
572 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
573 g_return_if_fail (status == CR_OK && ctxt);
574 g_return_if_fail (ctxt->cur_stmt && ctxt->stylesheet);
576 if (ctxt->cur_stmt) {
577 CRStatement *stmts = NULL;
579 if (ctxt->cur_media_stmt) {
580 CRAtMediaRule *media_rule = NULL;
582 media_rule = ctxt->cur_media_stmt->kind.media_rule;
584 stmts = cr_statement_append
585 (media_rule->rulesets, ctxt->cur_stmt);
589 ("Could not append a new statement");
590 cr_statement_destroy (media_rule->rulesets);
591 ctxt->cur_media_stmt->
592 kind.media_rule->rulesets = NULL;
595 media_rule->rulesets = stmts;
596 ctxt->cur_stmt = NULL;
598 stmts = cr_statement_append
599 (ctxt->stylesheet->statements,
603 ("Could not append a new statement");
604 cr_statement_destroy (ctxt->cur_stmt);
605 ctxt->cur_stmt = NULL;
608 ctxt->stylesheet->statements = stmts;
609 ctxt->cur_stmt = NULL;
613 a_selector_list = NULL; /*keep compiler happy */
617 property (CRDocHandler * a_this,
619 CRTerm * a_expression,
620 gboolean a_important)
622 enum CRStatus status = CR_OK;
623 ParsingContext *ctxt = NULL;
624 ParsingContext **ctxtptr = NULL;
625 CRDeclaration *decl = NULL,
627 CRString *str = NULL;
629 g_return_if_fail (a_this);
631 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
632 g_return_if_fail (status == CR_OK && ctxt);
635 *make sure a current ruleset statement has been allocated
641 (ctxt->cur_stmt->type == RULESET_STMT
642 || ctxt->cur_stmt->type == AT_FONT_FACE_RULE_STMT
643 || ctxt->cur_stmt->type == AT_PAGE_RULE_STMT));
646 str = cr_string_dup (a_name);
647 g_return_if_fail (str);
650 /*instanciates a new declaration */
651 decl = cr_declaration_new (ctxt->cur_stmt, str, a_expression);
652 g_return_if_fail (decl);
654 decl->important = a_important;
656 *add the new declaration to the current statement
659 switch (ctxt->cur_stmt->type) {
661 decl2 = cr_declaration_append
662 (ctxt->cur_stmt->kind.ruleset->decl_list, decl);
664 cr_declaration_destroy (decl);
666 ("Could not append decl to ruleset");
669 ctxt->cur_stmt->kind.ruleset->decl_list = decl2;
674 case AT_FONT_FACE_RULE_STMT:
675 decl2 = cr_declaration_append
676 (ctxt->cur_stmt->kind.font_face_rule->decl_list,
679 cr_declaration_destroy (decl);
681 ("Could not append decl to ruleset");
684 ctxt->cur_stmt->kind.font_face_rule->decl_list = decl2;
688 case AT_PAGE_RULE_STMT:
689 decl2 = cr_declaration_append
690 (ctxt->cur_stmt->kind.page_rule->decl_list, decl);
692 cr_declaration_destroy (decl);
694 ("Could not append decl to ruleset");
697 ctxt->cur_stmt->kind.page_rule->decl_list = decl2;
716 cr_declaration_destroy (decl);
722 error (CRDocHandler * a_this)
724 enum CRStatus status = CR_OK;
725 ParsingContext *ctxt = NULL;
726 ParsingContext **ctxtptr = NULL;
728 g_return_if_fail (a_this);
730 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
731 g_return_if_fail (status == CR_OK && ctxt);
733 if (ctxt->cur_stmt) {
734 cr_statement_destroy (ctxt->cur_stmt);
735 ctxt->cur_stmt = NULL;
740 unrecoverable_error (CRDocHandler * a_this)
742 enum CRStatus status = CR_OK;
743 ParsingContext *ctxt = NULL;
744 ParsingContext **ctxtptr = NULL;
747 status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr);
748 g_return_if_fail (status == CR_OK);
751 if (ctxt->stylesheet) {
752 status = cr_doc_handler_set_result
753 (a_this, ctxt->stylesheet);
754 g_return_if_fail (status == CR_OK);
757 cr_doc_handler_set_ctxt (a_this, NULL);
761 /********************************************
763 ********************************************/
767 *@a_input: the input stream.
769 *Constructor of the CROMParser.
770 *Returns the newly built instance of #CROMParser.
773 cr_om_parser_new (CRInput * a_input)
775 CROMParser *result = NULL;
776 enum CRStatus status = CR_OK;
778 result = g_try_malloc (sizeof (CROMParser));
781 cr_utils_trace_info ("Out of memory");
785 memset (result, 0, sizeof (CROMParser));
786 PRIVATE (result) = g_try_malloc (sizeof (CROMParserPriv));
788 if (!PRIVATE (result)) {
789 cr_utils_trace_info ("Out of memory");
793 memset (PRIVATE (result), 0, sizeof (CROMParserPriv));
795 PRIVATE (result)->parser = cr_parser_new_from_input (a_input);
797 if (!PRIVATE (result)->parser) {
798 cr_utils_trace_info ("parsing instanciation failed");
802 status = cr_om_parser_init_default_sac_handler (result);
804 if (status != CR_OK) {
813 cr_om_parser_destroy (result);
820 * cr_om_parser_parse_buf:
821 *@a_this: the current instance of #CROMParser.
822 *@a_buf: the in memory buffer to parse.
823 *@a_len: the length of the in memory buffer in number of bytes.
824 *@a_enc: the encoding of the in memory buffer.
825 *@a_result: out parameter the resulting style sheet
827 *Parses the content of an in memory buffer.
829 *Returns CR_OK upon successfull completion, an error code otherwise.
832 cr_om_parser_parse_buf (CROMParser * a_this,
833 const guchar * a_buf,
835 enum CREncoding a_enc, CRStyleSheet ** a_result)
838 enum CRStatus status = CR_OK;
840 g_return_val_if_fail (a_this && a_result, CR_BAD_PARAM_ERROR);
842 if (!PRIVATE (a_this)->parser) {
843 PRIVATE (a_this)->parser = cr_parser_new (NULL);
846 status = cr_parser_parse_buf (PRIVATE (a_this)->parser,
847 a_buf, a_len, a_enc);
849 if (status == CR_OK) {
850 CRStyleSheet *result = NULL;
851 CRStyleSheet **resultptr = NULL;
852 CRDocHandler *sac_handler = NULL;
854 cr_parser_get_sac_handler (PRIVATE (a_this)->parser,
856 g_return_val_if_fail (sac_handler, CR_ERROR);
858 status = cr_doc_handler_get_result (sac_handler,
859 (gpointer *) resultptr);
860 g_return_val_if_fail (status == CR_OK, status);
870 * cr_om_parser_simply_parse_buf:
871 *@a_buf: the css2 in memory buffer.
872 *@a_len: the length of the in memory buffer.
873 *@a_enc: the encoding of the in memory buffer.
874 *@a_result: out parameter. The resulting css2 style sheet.
876 *The simpler way to parse an in memory css2 buffer.
878 *Returns CR_OK upon successfull completion, an error code otherwise.
881 cr_om_parser_simply_parse_buf (const guchar * a_buf,
883 enum CREncoding a_enc,
884 CRStyleSheet ** a_result)
886 CROMParser *parser = NULL;
887 enum CRStatus status = CR_OK;
889 parser = cr_om_parser_new (NULL);
891 cr_utils_trace_info ("Could not create om parser");
892 cr_utils_trace_info ("System possibly out of memory");
896 status = cr_om_parser_parse_buf (parser, a_buf, a_len,
900 cr_om_parser_destroy (parser);
908 * cr_om_parser_parse_file:
909 *@a_this: the current instance of the cssom parser.
910 *@a_file_uri: the uri of the file.
911 *(only local file paths are suppported so far)
912 *@a_enc: the encoding of the file.
913 *@a_result: out parameter. A pointer
914 *the build css object model.
916 *Parses a css2 stylesheet contained
919 * Returns CR_OK upon succesful completion, an error code otherwise.
922 cr_om_parser_parse_file (CROMParser * a_this,
923 const guchar * a_file_uri,
924 enum CREncoding a_enc, CRStyleSheet ** a_result)
926 enum CRStatus status = CR_OK;
928 g_return_val_if_fail (a_this && a_file_uri && a_result,
931 if (!PRIVATE (a_this)->parser) {
932 PRIVATE (a_this)->parser = cr_parser_new_from_file
936 status = cr_parser_parse_file (PRIVATE (a_this)->parser,
939 if (status == CR_OK) {
940 CRStyleSheet *result = NULL;
941 CRStyleSheet **resultptr = NULL;
942 CRDocHandler *sac_handler = NULL;
944 cr_parser_get_sac_handler (PRIVATE (a_this)->parser,
946 g_return_val_if_fail (sac_handler, CR_ERROR);
948 status = cr_doc_handler_get_result
949 (sac_handler, (gpointer *) resultptr);
950 g_return_val_if_fail (status == CR_OK, status);
959 * cr_om_parser_simply_parse_file:
960 *@a_file_path: the css2 local file path.
961 *@a_enc: the file encoding.
962 *@a_result: out parameter. The returned css stylesheet.
963 *Must be freed by the caller using cr_stylesheet_destroy.
965 *The simpler method to parse a css2 file.
967 *Returns CR_OK upon successfull completion, an error code otherwise.
968 *Note that this method uses cr_om_parser_parse_file() so both methods
969 *have the same return values.
972 cr_om_parser_simply_parse_file (const guchar * a_file_path,
973 enum CREncoding a_enc,
974 CRStyleSheet ** a_result)
976 CROMParser *parser = NULL;
977 enum CRStatus status = CR_OK;
979 parser = cr_om_parser_new (NULL);
981 cr_utils_trace_info ("Could not allocate om parser");
982 cr_utils_trace_info ("System may be out of memory");
986 status = cr_om_parser_parse_file (parser, a_file_path,
989 cr_om_parser_destroy (parser);
997 * cr_om_parser_parse_paths_to_cascade:
998 *@a_this: the current instance of #CROMParser
999 *@a_author_path: the path to the author stylesheet
1000 *@a_user_path: the path to the user stylesheet
1001 *@a_ua_path: the path to the User Agent stylesheet
1002 *@a_encoding: the encoding of the sheets.
1003 *@a_result: out parameter. The resulting cascade if the parsing
1006 *Parses three sheets located by their paths and build a cascade
1008 *Returns CR_OK upon successful completion, an error code otherwise
1011 cr_om_parser_parse_paths_to_cascade (CROMParser * a_this,
1012 const guchar * a_author_path,
1013 const guchar * a_user_path,
1014 const guchar * a_ua_path,
1015 enum CREncoding a_encoding,
1016 CRCascade ** a_result)
1018 enum CRStatus status = CR_OK;
1020 /*0->author sheet, 1->user sheet, 2->UA sheet */
1021 CRStyleSheet *sheets[3];
1023 CRCascade *result = NULL;
1026 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
1028 memset (sheets, 0, sizeof (CRStyleSheet*) * 3);
1029 paths[0] = (guchar *) a_author_path;
1030 paths[1] = (guchar *) a_user_path;
1031 paths[2] = (guchar *) a_ua_path;
1033 for (i = 0; i < 3; i++) {
1034 status = cr_om_parser_parse_file (a_this, paths[i],
1035 a_encoding, &sheets[i]);
1036 if (status != CR_OK) {
1038 cr_stylesheet_unref (sheets[i]);
1044 result = cr_cascade_new (sheets[0], sheets[1], sheets[2]);
1046 for (i = 0; i < 3; i++) {
1047 cr_stylesheet_unref (sheets[i]);
1057 * cr_om_parser_simply_parse_paths_to_cascade:
1058 *@a_author_path: the path to the author stylesheet
1059 *@a_user_path: the path to the user stylesheet
1060 *@a_ua_path: the path to the User Agent stylesheet
1061 *@a_encoding: the encoding of the sheets.
1062 *@a_result: out parameter. The resulting cascade if the parsing
1065 *Parses three sheets located by their paths and build a cascade
1067 *Returns CR_OK upon successful completion, an error code otherwise
1070 cr_om_parser_simply_parse_paths_to_cascade (const guchar * a_author_path,
1071 const guchar * a_user_path,
1072 const guchar * a_ua_path,
1073 enum CREncoding a_encoding,
1074 CRCascade ** a_result)
1076 enum CRStatus status = CR_OK;
1077 CROMParser *parser = NULL;
1079 parser = cr_om_parser_new (NULL);
1081 cr_utils_trace_info ("could not allocated om parser");
1082 cr_utils_trace_info ("System may be out of memory");
1085 status = cr_om_parser_parse_paths_to_cascade (parser,
1089 a_encoding, a_result);
1091 cr_om_parser_destroy (parser);
1098 * cr_om_parser_destroy:
1099 *@a_this: the current instance of #CROMParser.
1101 *Destructor of the #CROMParser.
1104 cr_om_parser_destroy (CROMParser * a_this)
1106 g_return_if_fail (a_this && PRIVATE (a_this));
1108 if (PRIVATE (a_this)->parser) {
1109 cr_parser_destroy (PRIVATE (a_this)->parser);
1110 PRIVATE (a_this)->parser = NULL;
1113 if (PRIVATE (a_this)) {
1114 g_free (PRIVATE (a_this));
1115 PRIVATE (a_this) = NULL;