static void end_media (CRDocHandler * a_this, GList * a_media_list) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; CRStatement *stmts = NULL; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); g_return_if_fail (ctxt && ctxt->cur_media_stmt && ctxt->cur_media_stmt->type == AT_MEDIA_RULE_STMT && ctxt->stylesheet); stmts = cr_statement_append (ctxt->stylesheet->statements, ctxt->cur_media_stmt); if (!stmts) { cr_statement_destroy (ctxt->cur_media_stmt); ctxt->cur_media_stmt = NULL; } ctxt->stylesheet->statements = stmts; stmts = NULL; ctxt->cur_stmt = NULL ; ctxt->cur_media_stmt = NULL ; a_media_list = NULL; }
static void start_media (CRDocHandler * a_this, GList * a_media_list, CRParsingLocation *a_location) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; GList *media_list = NULL; (void) a_location; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); g_return_if_fail (ctxt && ctxt->cur_stmt == NULL && ctxt->cur_media_stmt == NULL && ctxt->stylesheet); if (a_media_list) { /*duplicate the media_list */ media_list = cr_utils_dup_glist_of_cr_string (a_media_list); } ctxt->cur_media_stmt = cr_statement_new_at_media_rule (ctxt->stylesheet, NULL, media_list); }
static void end_document (CRDocHandler * a_this) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); if (!ctxt->stylesheet || ctxt->cur_stmt) goto error; status = cr_doc_handler_set_result (a_this, ctxt->stylesheet); g_return_if_fail (status == CR_OK); ctxt->stylesheet = NULL; destroy_context (ctxt); cr_doc_handler_set_ctxt (a_this, NULL); return; error: if (ctxt) { destroy_context (ctxt); } }
static void end_page (CRDocHandler * a_this, CRString * a_page, CRString * a_pseudo_page) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; CRStatement *stmt = NULL; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); g_return_if_fail (ctxt->cur_stmt && ctxt->cur_stmt->type == AT_PAGE_RULE_STMT && ctxt->stylesheet); stmt = cr_statement_append (ctxt->stylesheet->statements, ctxt->cur_stmt); if (stmt) { ctxt->stylesheet->statements = stmt; stmt = NULL; ctxt->cur_stmt = NULL; } if (ctxt->cur_stmt) { cr_statement_destroy (ctxt->cur_stmt); ctxt->cur_stmt = NULL; } a_page = NULL; /*keep compiler happy */ a_pseudo_page = NULL; /*keep compiler happy */ }
static void charset (CRDocHandler * a_this, CRString * a_charset, CRParsingLocation *a_location) { enum CRStatus status = CR_OK; CRStatement *stmt = NULL, *stmt2 = NULL; CRString *charset = NULL; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); g_return_if_fail (ctxt->stylesheet); charset = cr_string_dup (a_charset) ; stmt = cr_statement_new_at_charset_rule (ctxt->stylesheet, charset); g_return_if_fail (stmt); stmt2 = cr_statement_append (ctxt->stylesheet->statements, stmt); if (!stmt2) { if (stmt) { cr_statement_destroy (stmt); stmt = NULL; } if (charset) { cr_string_destroy (charset); } return; } ctxt->stylesheet->statements = stmt2; stmt2 = NULL; }
static void import_style (CRDocHandler * a_this, GList * a_media_list, CRString * a_uri, CRString * a_uri_default_ns, CRParsingLocation *a_location) { enum CRStatus status = CR_OK; CRString *uri = NULL; CRStatement *stmt = NULL, *stmt2 = NULL; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; GList *media_list = NULL ; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); g_return_if_fail (ctxt->stylesheet); uri = cr_string_dup (a_uri) ; if (a_media_list) media_list = cr_utils_dup_glist_of_cr_string (a_media_list) ; stmt = cr_statement_new_at_import_rule (ctxt->stylesheet, uri, media_list, NULL); if (!stmt) goto error; if (ctxt->cur_stmt) { stmt2 = cr_statement_append (ctxt->cur_stmt, stmt); if (!stmt2) goto error; ctxt->cur_stmt = stmt2; stmt2 = NULL; stmt = NULL; } else { stmt2 = cr_statement_append (ctxt->stylesheet->statements, stmt); if (!stmt2) goto error; ctxt->stylesheet->statements = stmt2; stmt2 = NULL; stmt = NULL; } return; error: if (uri) { cr_string_destroy (uri); } if (stmt) { cr_statement_destroy (stmt); stmt = NULL; } a_uri_default_ns = NULL; /*keep compiler happy */ }
static void end_selector (CRDocHandler * a_this, CRSelector * a_selector_list) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; (void) a_selector_list; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); g_return_if_fail (ctxt->cur_stmt && ctxt->stylesheet); if (ctxt->cur_stmt) { CRStatement *stmts = NULL; if (ctxt->cur_media_stmt) { CRAtMediaRule *media_rule = NULL; media_rule = ctxt->cur_media_stmt->kind.media_rule; stmts = cr_statement_append (media_rule->rulesets, ctxt->cur_stmt); if (!stmts) { cr_utils_trace_info ("Could not append a new statement"); cr_statement_destroy (media_rule->rulesets); ctxt->cur_media_stmt-> kind.media_rule->rulesets = NULL; return; } media_rule->rulesets = stmts; ctxt->cur_stmt = NULL; } else { stmts = cr_statement_append (ctxt->stylesheet->statements, ctxt->cur_stmt); if (!stmts) { cr_utils_trace_info ("Could not append a new statement"); cr_statement_destroy (ctxt->cur_stmt); ctxt->cur_stmt = NULL; return; } ctxt->stylesheet->statements = stmts; ctxt->cur_stmt = NULL; } } a_selector_list = NULL; /*keep compiler happy */ }
static void error (CRDocHandler * a_this) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); if (ctxt->cur_stmt) { cr_statement_destroy (ctxt->cur_stmt); ctxt->cur_stmt = NULL; } }
static void start_page (CRDocHandler * a_this, CRString * a_page, CRString * a_pseudo, CRParsingLocation *a_location) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; (void) a_location; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); g_return_if_fail (ctxt->cur_stmt == NULL); ctxt->cur_stmt = cr_statement_new_at_page_rule (ctxt->stylesheet, NULL, NULL, NULL); if (a_page) { ctxt->cur_stmt->kind.page_rule->name = cr_string_dup (a_page) ; if (!ctxt->cur_stmt->kind.page_rule->name) { goto error; } } if (a_pseudo) { ctxt->cur_stmt->kind.page_rule->pseudo = cr_string_dup (a_pseudo) ; if (!ctxt->cur_stmt->kind.page_rule->pseudo) { goto error; } } return; error: if (ctxt->cur_stmt) { cr_statement_destroy (ctxt->cur_stmt); ctxt->cur_stmt = NULL; } }
static void end_font_face (CRDocHandler * a_this) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; CRStatement *stmts = NULL; g_return_if_fail (a_this); g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); g_return_if_fail (ctxt->cur_stmt && ctxt->cur_stmt->type == AT_FONT_FACE_RULE_STMT && ctxt->stylesheet); stmts = cr_statement_append (ctxt->stylesheet->statements, ctxt->cur_stmt); if (!stmts) goto error; ctxt->stylesheet->statements = stmts; stmts = NULL; ctxt->cur_stmt = NULL; return; error: if (ctxt->cur_stmt) { cr_statement_destroy (ctxt->cur_stmt); ctxt->cur_stmt = NULL; } if (!stmts) { cr_statement_destroy (stmts); stmts = NULL; } }
static void start_selector (CRDocHandler * a_this, CRSelector * a_selector_list) { enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); if (ctxt->cur_stmt) { /*hmm, this should be NULL so free it */ cr_statement_destroy (ctxt->cur_stmt); ctxt->cur_stmt = NULL; } ctxt->cur_stmt = cr_statement_new_ruleset (ctxt->stylesheet, a_selector_list, NULL, NULL); }
static void unrecoverable_error (CRDocHandler * a_this) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK); if (ctxt) { if (ctxt->stylesheet) { status = cr_doc_handler_set_result (a_this, ctxt->stylesheet); g_return_if_fail (status == CR_OK); } g_free (ctxt); cr_doc_handler_set_ctxt (a_this, NULL); } }
static void start_font_face (CRDocHandler * a_this, CRParsingLocation *a_location) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; g_return_if_fail (a_this); g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); g_return_if_fail (ctxt->cur_stmt == NULL); ctxt->cur_stmt = cr_statement_new_at_font_face_rule (ctxt->stylesheet, NULL); g_return_if_fail (ctxt->cur_stmt); }
static void property (CRDocHandler * a_this, CRString * a_name, CRTerm * a_expression, gboolean a_important) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; CRDeclaration *decl = NULL, *decl2 = NULL; CRString *str = NULL; g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); /* *make sure a current ruleset statement has been allocated *already. */ g_return_if_fail (ctxt->cur_stmt && (ctxt->cur_stmt->type == RULESET_STMT || ctxt->cur_stmt->type == AT_FONT_FACE_RULE_STMT || ctxt->cur_stmt->type == AT_PAGE_RULE_STMT)); if (a_name) { str = cr_string_dup (a_name); g_return_if_fail (str); } /*instanciates a new declaration */ decl = cr_declaration_new (ctxt->cur_stmt, str, a_expression); g_return_if_fail (decl); str = NULL; decl->important = a_important; /* *add the new declaration to the current statement *being build. */ switch (ctxt->cur_stmt->type) { case RULESET_STMT: decl2 = cr_declaration_append (ctxt->cur_stmt->kind.ruleset->decl_list, decl); if (!decl2) { cr_declaration_destroy (decl); cr_utils_trace_info ("Could not append decl to ruleset"); goto error; } ctxt->cur_stmt->kind.ruleset->decl_list = decl2; decl = NULL; decl2 = NULL; break; case AT_FONT_FACE_RULE_STMT: decl2 = cr_declaration_append (ctxt->cur_stmt->kind.font_face_rule->decl_list, decl); if (!decl2) { cr_declaration_destroy (decl); cr_utils_trace_info ("Could not append decl to ruleset"); goto error; } ctxt->cur_stmt->kind.font_face_rule->decl_list = decl2; decl = NULL; decl2 = NULL; break; case AT_PAGE_RULE_STMT: decl2 = cr_declaration_append (ctxt->cur_stmt->kind.page_rule->decl_list, decl); if (!decl2) { cr_declaration_destroy (decl); cr_utils_trace_info ("Could not append decl to ruleset"); goto error; } ctxt->cur_stmt->kind.page_rule->decl_list = decl2; decl = NULL; decl2 = NULL; break; default: goto error; break; } return; error: if (str) { g_free (str); str = NULL; } if (decl) { cr_declaration_destroy (decl); decl = NULL; } }