diff --git a/src/cr-attr-sel.c b/src/cr-attr-sel.c index c057bbb..31d9da5 100644 --- a/src/cr-attr-sel.c +++ b/src/cr-attr-sel.c @@ -227,9 +227,6 @@ cr_attr_sel_destroy (CRAttrSel * a_this) a_this->next = NULL; } - if (a_this) { - g_free (a_this); - a_this = NULL; - } + g_free (a_this); } diff --git a/src/cr-cascade.c b/src/cr-cascade.c index b8f8277..9f8dbdf 100644 --- a/src/cr-cascade.c +++ b/src/cr-cascade.c @@ -104,7 +104,7 @@ cr_cascade_new (CRStyleSheet * a_author_sheet, *Gets a sheet, part of the cascade. *Note that the returned stylesheet *is refcounted so if the caller wants - *to manage it's lifecycle, it must use + *to manage its lifecycle, it must use *cr_stylesheet_ref()/cr_stylesheet_unref() instead *of the cr_stylesheet_destroy() method. *Returns the style sheet, or NULL if it does not @@ -114,8 +114,7 @@ CRStyleSheet * cr_cascade_get_sheet (CRCascade * a_this, enum CRStyleOrigin a_origin) { g_return_val_if_fail (a_this - && a_origin >= ORIGIN_UA - && a_origin < NB_ORIGINS, NULL); + && (unsigned)a_origin < NB_ORIGINS, NULL); return PRIVATE (a_this)->sheets[a_origin]; } @@ -137,8 +136,7 @@ cr_cascade_set_sheet (CRCascade * a_this, { g_return_val_if_fail (a_this && a_sheet - && a_origin >= ORIGIN_UA - && a_origin < NB_ORIGINS, CR_BAD_PARAM_ERROR); + && (unsigned)a_origin < NB_ORIGINS, CR_BAD_PARAM_ERROR); if (PRIVATE (a_this)->sheets[a_origin]) cr_stylesheet_unref (PRIVATE (a_this)->sheets[a_origin]); diff --git a/src/cr-declaration.c b/src/cr-declaration.c index 2a13c82..69c24b3 100644 --- a/src/cr-declaration.c +++ b/src/cr-declaration.c @@ -233,7 +233,8 @@ cr_declaration_parse_list_from_buf (const guchar * a_str, if (c == ';') { status = cr_tknzr_read_char (tokenizer, &c); } else { - break; + cr_tknzr_read_char (tokenizer, &c); + continue; // try to keep reading until we reach the end or a ; } important = FALSE; cr_parser_try_to_skip_spaces_and_comments (parser); @@ -241,9 +242,11 @@ cr_declaration_parse_list_from_buf (const guchar * a_str, &value, &important); if (status != CR_OK || !property) { if (status == CR_END_OF_INPUT_ERROR) { - status = CR_OK; + status = CR_OK; // simply the end of input, do not delete what we got so far, just finish + break; + } else { + continue; // even if one declaration is broken, it's no reason to discard others (see http://www.w3.org/TR/CSS21/syndata.html#declaration) } - break; } cur_decl = cr_declaration_new (NULL, property, value); if (cur_decl) { diff --git a/src/cr-fonts.c b/src/cr-fonts.c index 669aa2b..78e2611 100644 --- a/src/cr-fonts.c +++ b/src/cr-fonts.c @@ -420,8 +420,7 @@ cr_font_size_set_predefined_absolute_font_size (CRFontSize *a_this, enum CRPredefinedAbsoluteFontSize a_predefined) { g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - g_return_val_if_fail (a_predefined >= FONT_SIZE_XX_SMALL - && a_predefined < NB_PREDEFINED_ABSOLUTE_FONT_SIZES, + g_return_val_if_fail ((unsigned)a_predefined < NB_PREDEFINED_ABSOLUTE_FONT_SIZES, CR_BAD_PARAM_ERROR) ; a_this->type = PREDEFINED_ABSOLUTE_FONT_SIZE ; @@ -442,8 +441,7 @@ cr_font_size_set_relative_font_size (CRFontSize *a_this, enum CRRelativeFontSize a_relative) { g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - g_return_val_if_fail (a_relative >= FONT_SIZE_LARGER - && a_relative < NB_RELATIVE_FONT_SIZE, + g_return_val_if_fail ((unsigned)a_relative < NB_RELATIVE_FONT_SIZE, CR_BAD_PARAM_ERROR) ; a_this->type = RELATIVE_FONT_SIZE ; @@ -465,8 +463,7 @@ cr_font_size_set_absolute_font_size (CRFontSize *a_this, gdouble a_value) { g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - g_return_val_if_fail (a_num_type >= NUM_AUTO - && a_num_type < NB_NUM_TYPE, + g_return_val_if_fail ((unsigned)a_num_type < NB_NUM_TYPE, CR_BAD_PARAM_ERROR) ; a_this->type = ABSOLUTE_FONT_SIZE ; @@ -557,8 +554,7 @@ cr_font_size_get_smaller_predefined_font_size enum CRPredefinedAbsoluteFontSize result = FONT_SIZE_MEDIUM ; g_return_if_fail (a_smaller_size) ; - g_return_if_fail (a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES - && a_font_size >= FONT_SIZE_XX_SMALL) ; + g_return_if_fail ((unsigned)a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) ; switch (a_font_size) { case FONT_SIZE_XX_SMALL: @@ -610,8 +606,7 @@ cr_font_size_get_larger_predefined_font_size enum CRPredefinedAbsoluteFontSize result = FONT_SIZE_MEDIUM ; g_return_if_fail (a_larger_size) ; - g_return_if_fail (a_font_size >= FONT_SIZE_XX_SMALL - && a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) ; + g_return_if_fail ((unsigned)a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) ; switch (a_font_size) { case FONT_SIZE_XX_SMALL: @@ -658,8 +653,7 @@ gboolean cr_font_size_is_predefined_absolute_font_size (enum CRPredefinedAbsoluteFontSize a_font_size) { - if (a_font_size >= FONT_SIZE_XX_SMALL - && a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) { + if ((unsigned)a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) { return TRUE ; } else { return FALSE ; diff --git a/src/cr-num.c b/src/cr-num.c index d5dbd5f..6cc5150 100644 --- a/src/cr-num.c +++ b/src/cr-num.c @@ -107,9 +107,11 @@ cr_num_to_string (CRNum const * a_this) if (!test_val) { tmp_char1 = (guchar *) g_strdup_printf ("%ld", (glong) a_this->val); } else { - tmp_char1 = (guchar *) g_new0 (char, G_ASCII_DTOSTR_BUF_SIZE + 1); - if (tmp_char1 != NULL) - g_ascii_dtostr ((gchar *) tmp_char1, G_ASCII_DTOSTR_BUF_SIZE, a_this->val); + /* We can't use g_ascii_dtostr, because that sometimes uses + e notation (which wouldn't be a valid number in CSS). */ + size_t const buflen = 35; /* fairly arbitrary. */ + tmp_char1 = (guchar *)g_malloc (buflen); + g_ascii_formatd ((gchar *)tmp_char1, buflen, "%.17f", a_this->val); } g_return_val_if_fail (tmp_char1, NULL); diff --git a/src/cr-om-parser.c b/src/cr-om-parser.c index 36a6697..596cd6e 100644 --- a/src/cr-om-parser.c +++ b/src/cr-om-parser.c @@ -211,6 +211,8 @@ start_font_face (CRDocHandler * a_this, ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; + (void) a_location; + g_return_if_fail (a_this); g_return_if_fail (a_this); @@ -310,6 +312,8 @@ charset (CRDocHandler * a_this, CRString * a_charset, 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); @@ -344,6 +348,8 @@ start_page (CRDocHandler * a_this, 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); @@ -427,6 +433,8 @@ start_media (CRDocHandler * a_this, 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); @@ -501,6 +509,7 @@ import_style (CRDocHandler * a_this, GList *media_list = NULL ; (void) a_uri_default_ns; + (void) a_location; g_return_if_fail (a_this); diff --git a/src/cr-parser.c b/src/cr-parser.c index a17f161..544b35a 100644 --- a/src/cr-parser.c +++ b/src/cr-parser.c @@ -511,7 +511,7 @@ cr_parser_error_destroy (CRParserError * a_this) *@param a_this the current instance of #CRParser. *@param a_msg the error message. *@param a_status the error status. - *@return CR_OK upon successfull completion, an error code otherwise. + *@return CR_OK upon successful completion, an error code otherwise. */ static enum CRStatus cr_parser_push_error (CRParser * a_this, @@ -553,7 +553,7 @@ cr_parser_push_error (CRParser * a_this, } /** - *Dumps the error stack on stdout. + *Dumps the error stack using g_printerr. *@param a_this the current instance of #CRParser. *@param a_clear_errs whether to clear the error stack *after the dump or not. @@ -1329,7 +1329,7 @@ cr_parser_parse_attribute_selector (CRParser * a_this, CRInputPos init_pos; CRToken *token = NULL; CRAttrSel *result = NULL; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; g_return_val_if_fail (a_this && a_sel, CR_BAD_PARAM_ERROR); @@ -1512,7 +1512,7 @@ cr_parser_parse_term (CRParser * a_this, CRTerm ** a_term) CRTerm *param = NULL; CRToken *token = NULL; CRString *func_name = NULL; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; g_return_val_if_fail (a_this && a_term, CR_BAD_PARAM_ERROR); @@ -1686,12 +1686,14 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel) if (token && token->type == DELIM_TK && token->u.unichar == '*') { - sel->type_mask |= UNIVERSAL_SELECTOR; + int comb = (int)sel->type_mask | (int) UNIVERSAL_SELECTOR; + sel->type_mask = (enum SimpleSelectorType)comb; sel->name = cr_string_new_from_string ("*"); found_sel = TRUE; } else if (token && token->type == IDENT_TK) { sel->name = token->u.str; - sel->type_mask |= TYPE_SELECTOR; + int comb = (int)sel->type_mask | (int) TYPE_SELECTOR; + sel->type_mask = (enum SimpleSelectorType)comb; token->u.str = NULL; found_sel = TRUE; } else { @@ -1948,7 +1950,7 @@ cr_parser_parse_simple_sels (CRParser * a_this, for (;;) { guint32 next_char = 0; - enum Combinator comb = 0; + int comb = 0; sel = NULL; @@ -1971,7 +1973,7 @@ cr_parser_parse_simple_sels (CRParser * a_this, break; if (comb && sel) { - sel->combinator = comb; + sel->combinator = (enum Combinator)comb; comb = 0; } if (sel) { @@ -2329,7 +2331,7 @@ cr_parser_parse_stylesheet (CRParser * a_this) CHECK_PARSING_STATUS (status, TRUE); if (token && token->type == CHARSET_SYM_TK) { - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token); CHECK_PARSING_STATUS (status, TRUE); @@ -2405,7 +2407,7 @@ cr_parser_parse_stylesheet (CRParser * a_this) if (token && token->type == IMPORT_SYM_TK) { GList *media_list = NULL; CRString *import_string = NULL; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token); @@ -2426,14 +2428,14 @@ cr_parser_parse_stylesheet (CRParser * a_this) import_string, NULL, &location) ; - if ((PRIVATE (a_this)->sac_handler->resolve_import == TRUE)) { + if (PRIVATE (a_this)->sac_handler->resolve_import == TRUE) { /* *TODO: resolve the *import rule. */ } - if ((PRIVATE (a_this)->sac_handler->import_style_result)) { + if (PRIVATE (a_this)->sac_handler->import_style_result) { PRIVATE (a_this)->sac_handler->import_style_result (PRIVATE (a_this)->sac_handler, media_list, import_string, @@ -2789,7 +2791,7 @@ cr_parser_new_from_buf (guchar * a_buf, CRParser *result = NULL; CRInput *input = NULL; - g_return_val_if_fail (a_buf && a_len, NULL); + g_return_val_if_fail (a_buf, NULL); input = cr_input_new_from_buf (a_buf, a_len, a_enc, a_free_buf); g_return_val_if_fail (input, NULL); @@ -3027,7 +3029,7 @@ cr_parser_parse_expr (CRParser * a_this, CRTerm ** a_expr) CHECK_PARSING_STATUS (status, FALSE); for (;;) { - guchar operator = 0; + guchar operatr = 0; status = cr_tknzr_peek_byte (PRIVATE (a_this)->tknzr, 1, &next_byte); @@ -3047,7 +3049,7 @@ cr_parser_parse_expr (CRParser * a_this, CRTerm ** a_expr) } if (next_byte == '/' || next_byte == ',') { - READ_NEXT_BYTE (a_this, &operator); + READ_NEXT_BYTE (a_this, &operatr); } cr_parser_try_to_skip_spaces_and_comments (a_this); @@ -3059,7 +3061,7 @@ cr_parser_parse_expr (CRParser * a_this, CRTerm ** a_expr) break; } - switch (operator) { + switch (operatr) { case '/': expr2->the_operator = DIVIDE; break; @@ -3072,7 +3074,7 @@ cr_parser_parse_expr (CRParser * a_this, CRTerm ** a_expr) expr = cr_term_append_term (expr, expr2); expr2 = NULL; - operator = 0; + operatr = 0; nb_terms++; } @@ -3316,7 +3318,7 @@ cr_parser_parse_statement_core (CRParser * a_this) *ruleset ::= selector [ ',' S* selector ]* *'{' S* declaration? [ ';' S* declaration? ]* '}' S*; * - *This methods calls the the SAC handler on the relevant SAC handler + *This methods calls the SAC handler on the relevant SAC handler *callbacks whenever it encounters some specific constructions. *See the documentation of #CRDocHandler (the SAC handler) to know *when which SAC handler is called. @@ -3710,7 +3712,7 @@ cr_parser_parse_media (CRParser * a_this) cur_char = 0; CRString *medium = NULL; GList *media_list = NULL; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; g_return_val_if_fail (a_this && PRIVATE (a_this), @@ -3881,7 +3883,7 @@ cr_parser_parse_page (CRParser * a_this) *page_pseudo_class = NULL, *property = NULL; gboolean important = TRUE; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); @@ -4223,7 +4225,7 @@ cr_parser_parse_font_face (CRParser * a_this) gboolean important = FALSE; guint32 next_char = 0, cur_char = 0; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); @@ -4519,8 +4521,5 @@ cr_parser_destroy (CRParser * a_this) PRIVATE (a_this) = NULL; } - if (a_this) { - g_free (a_this); - a_this = NULL; /*useless. Just for the sake of coherence */ - } + g_free (a_this); } diff --git a/src/cr-prop-list.c b/src/cr-prop-list.c index 0ce57fa..dc575d6 100644 --- a/src/cr-prop-list.c +++ b/src/cr-prop-list.c @@ -50,7 +50,7 @@ cr_prop_list_allocate (void) } memset (result, 0, sizeof (CRPropList)); PRIVATE (result) = g_try_malloc (sizeof (CRPropListPriv)); - if (!result) { + if (!PRIVATE (result)) { cr_utils_trace_info ("could not allocate CRPropListPriv"); g_free (result); return NULL; diff --git a/src/cr-rgb.c b/src/cr-rgb.c index 1b8b662..889f248 100644 --- a/src/cr-rgb.c +++ b/src/cr-rgb.c @@ -150,6 +150,7 @@ static const CRRgb gv_standard_colors[] = { {(const guchar*)"plum", 221, 160, 221, FALSE, FALSE, FALSE, {0,0,0}}, {(const guchar*)"powderblue", 176, 224, 230, FALSE, FALSE, FALSE, {0,0,0}}, {(const guchar*)"purple", 128, 0, 128, FALSE, FALSE, FALSE, {0,0,0}}, + {(const guchar*)"rebeccapurple", 102, 51, 153, FALSE, FALSE, FALSE, {0,0,0}}, {(const guchar*)"red", 255, 0, 0, FALSE, FALSE, FALSE, {0,0,0}}, {(const guchar*)"rosybrown", 188, 143, 143, FALSE, FALSE, FALSE, {0,0,0}}, {(const guchar*)"royalblue", 65, 105, 225, FALSE, FALSE, FALSE, {0,0,0}}, @@ -402,7 +403,7 @@ cr_rgb_is_set_to_inherit (CRRgb const *a_this) *@a_this: the current instance of *#CRRgb * - *Tests if the the rgb is set to the + *Tests if the rgb is set to the *value "transparent" or not. * *Returns TRUE if the rgb has been set to diff --git a/src/cr-sel-eng.c b/src/cr-sel-eng.c index 3cd7241..6f496df 100644 --- a/src/cr-sel-eng.c +++ b/src/cr-sel-eng.c @@ -23,6 +23,7 @@ #include #include "cr-sel-eng.h" +#include "cr-node-iface.h" /** *@CRSelEng: @@ -45,6 +46,7 @@ struct _CRSelEngPriv { /*not used yet */ gboolean case_sensitive; + CRNodeIface const *node_iface; CRStyleSheet *sheet; /** *where to store the next statement @@ -57,17 +59,17 @@ struct _CRSelEngPriv { } ; static gboolean class_add_sel_matches_node (CRAdditionalSel * a_add_sel, - xmlNode * a_node); + CRNodeIface const * a_node_iface, CRXMLNodePtr a_node); static gboolean id_add_sel_matches_node (CRAdditionalSel * a_add_sel, - xmlNode * a_node); + CRNodeIface const * a_node_iface, CRXMLNodePtr a_node); static gboolean attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, - xmlNode * a_node); + CRNodeIface const * a_node_iface, CRXMLNodePtr a_node); static enum CRStatus sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel, - xmlNode * a_node, + CRXMLNodePtr a_node, gboolean * a_result, gboolean a_eval_sel_list_from_end, gboolean a_recurse); @@ -75,7 +77,7 @@ static enum CRStatus sel_matches_node_real (CRSelEng * a_this, static enum CRStatus cr_sel_eng_get_matched_rulesets_real (CRSelEng * a_this, CRStyleSheet * a_stylesheet, - xmlNode * a_node, + CRXMLNodePtr a_node, CRStatement ** a_rulesets, gulong * a_len); @@ -87,34 +89,42 @@ static enum CRStatus put_css_properties_in_props_list (CRPropList ** a_props, static gboolean pseudo_class_add_sel_matches_node (CRSelEng * a_this, CRAdditionalSel * a_add_sel, - xmlNode * a_node); + CRXMLNodePtr a_node); static gboolean lang_pseudo_class_handler (CRSelEng * a_this, CRAdditionalSel * a_sel, - xmlNode * a_node); + CRXMLNodePtr a_node); static gboolean first_child_pseudo_class_handler (CRSelEng * a_this, CRAdditionalSel * a_sel, - xmlNode * a_node); + CRXMLNodePtr a_node); -static xmlNode *get_next_element_node (xmlNode * a_node); +static CRXMLNodePtr get_next_element_node (CRNodeIface const * a_node_iface, CRXMLNodePtr a_node); -static xmlNode *get_next_child_element_node (xmlNode * a_node); +static CRXMLNodePtr get_next_child_element_node (CRNodeIface const * a_node_iface, CRXMLNodePtr a_node); -static xmlNode *get_prev_element_node (xmlNode * a_node); +static CRXMLNodePtr get_prev_element_node (CRNodeIface const * a_node_iface, CRXMLNodePtr a_node); -static xmlNode *get_next_parent_element_node (xmlNode * a_node); +static CRXMLNodePtr get_next_parent_element_node (CRNodeIface const * a_node_iface, CRXMLNodePtr a_node); + +void +cr_sel_eng_set_node_iface (CRSelEng *const a_this, CRNodeIface const *const a_node_iface) +{ + /* Allow NULL: the caller may be just ensuring that the previous node_iface + value doesn't get used until next cr_sel_eng_set_node_iface call. */ + PRIVATE(a_this)->node_iface = a_node_iface; +} /* Quick strcmp. Test only for == 0 or != 0, not < 0 or > 0. */ #define strqcmp(str,lit,lit_len) \ (strlen (str) != (lit_len) || memcmp (str, lit, lit_len)) static gboolean -lang_pseudo_class_handler (CRSelEng * a_this, - CRAdditionalSel * a_sel, xmlNode * a_node) +lang_pseudo_class_handler (CRSelEng *const a_this, + CRAdditionalSel * a_sel, CRXMLNodePtr a_node) { - xmlNode *node = a_node; - xmlChar *val = NULL; + CRNodeIface const *node_iface; + CRXMLNodePtr node = a_node; gboolean result = FALSE; g_return_val_if_fail (a_this && PRIVATE (a_this) @@ -122,29 +132,31 @@ lang_pseudo_class_handler (CRSelEng * a_this, && a_sel->content.pseudo && a_sel->content.pseudo->name && a_sel->content.pseudo->name->stryng - && a_node, CR_BAD_PARAM_ERROR); + && a_node, FALSE); + + node_iface = PRIVATE(a_this)->node_iface; - if (strqcmp (a_sel->content.pseudo->name->stryng->str, - "lang", 4) + /* "xml:lang" needed for SVG */ + if ( (strqcmp (a_sel->content.pseudo->name->stryng->str, "lang", 4 ) && + (strqcmp (a_sel->content.pseudo->name->stryng->str, "xml:lang", 8 ) ) ) || a_sel->content.pseudo->type != FUNCTION_PSEUDO) { cr_utils_trace_info ("This handler is for :lang only"); - return CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR; + return FALSE; } /*lang code should exist and be at least of length 2 */ if (!a_sel->content.pseudo->extra || !a_sel->content.pseudo->extra->stryng || a_sel->content.pseudo->extra->stryng->len < 2) return FALSE; - for (; node; node = get_next_parent_element_node (node)) { - val = xmlGetProp (node, (const xmlChar *) "lang"); - if (val - && !strqcmp ((const char *) val, - a_sel->content.pseudo->extra->stryng->str, - a_sel->content.pseudo->extra->stryng->len)) { - result = TRUE; - } + for (; node; node = get_next_parent_element_node (node_iface, node)) { + char *val = node_iface->getProp (node, (const xmlChar *) "lang"); + if (!val) val = node_iface->getProp (node, (const xmlChar *) "xml:lang"); if (val) { - xmlFree (val); + if (!strcasecmp(val, a_sel->content.pseudo->extra->stryng->str)) { + result = TRUE; + break; + } + node_iface->freePropVal (val); val = NULL; } } @@ -153,36 +165,37 @@ lang_pseudo_class_handler (CRSelEng * a_this, } static gboolean -first_child_pseudo_class_handler (CRSelEng * a_this, - CRAdditionalSel * a_sel, xmlNode * a_node) +first_child_pseudo_class_handler (CRSelEng *const a_this, + CRAdditionalSel * a_sel, CRXMLNodePtr const a_node) { - xmlNode *node = NULL; + CRNodeIface const *node_iface = NULL; + CRXMLNodePtr node = NULL, parent = NULL; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_sel && a_sel->content.pseudo && a_sel->content.pseudo && a_sel->content.pseudo->name && a_sel->content.pseudo->name->stryng - && a_node, CR_BAD_PARAM_ERROR); + && a_node, FALSE); if (strcmp (a_sel->content.pseudo->name->stryng->str, "first-child") || a_sel->content.pseudo->type != IDENT_PSEUDO) { cr_utils_trace_info ("This handler is for :first-child only"); - return CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR; + return FALSE; } - if (!a_node->parent) + node_iface = PRIVATE(a_this)->node_iface; + parent = node_iface->getParentNode (a_node); + if (!parent) return FALSE; - node = get_next_child_element_node (a_node->parent); - if (node == a_node) - return TRUE; - return FALSE; + node = get_next_child_element_node (node_iface, parent); + return (node == a_node); } static gboolean pseudo_class_add_sel_matches_node (CRSelEng * a_this, CRAdditionalSel * a_add_sel, - xmlNode * a_node) + CRXMLNodePtr a_node) { enum CRStatus status = CR_OK; CRPseudoClassSelectorHandler handler = NULL; @@ -193,7 +206,7 @@ pseudo_class_add_sel_matches_node (CRSelEng * a_this, && a_add_sel->content.pseudo->name && a_add_sel->content.pseudo->name->stryng && a_add_sel->content.pseudo->name->stryng->str - && a_node, CR_BAD_PARAM_ERROR); + && a_node, FALSE); status = cr_sel_eng_get_pseudo_class_selector_handler (a_this, (guchar *) a_add_sel->content.pseudo->name->stryng->str, @@ -211,11 +224,11 @@ pseudo_class_add_sel_matches_node (CRSelEng * a_this, *the xml node given in argument, FALSE otherwise. */ static gboolean -class_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) +class_add_sel_matches_node (CRAdditionalSel * a_add_sel, + CRNodeIface const * a_node_iface, CRXMLNodePtr a_node) { gboolean result = FALSE; - xmlChar *klass = NULL, - *cur = NULL; + char *klass = NULL; g_return_val_if_fail (a_add_sel && a_add_sel->type == CLASS_ADD_SELECTOR @@ -224,8 +237,9 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) && a_add_sel->content.class_name->stryng->str && a_node, FALSE); - if (xmlHasProp (a_node, (const xmlChar *) "class")) { - klass = xmlGetProp (a_node, (const xmlChar *) "class"); + klass = a_node_iface->getProp (a_node, (const xmlChar *) "class"); + if (klass) { + char const *cur; for (cur = klass; cur && *cur; cur++) { while (cur && *cur && cr_utils_is_white_space (*cur) @@ -247,9 +261,7 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) if (cur && !*cur) break ; } - } - if (klass) { - xmlFree (klass); + a_node_iface->freePropVal (klass); klass = NULL; } return result; @@ -263,10 +275,11 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) *@param a_node the xml node to consider. */ static gboolean -id_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) +id_add_sel_matches_node (CRAdditionalSel * a_add_sel, + CRNodeIface const * a_node_iface, CRXMLNodePtr a_node) { gboolean result = FALSE; - xmlChar *id = NULL; + char *id = NULL; g_return_val_if_fail (a_add_sel && a_add_sel->type == ID_ADD_SELECTOR @@ -278,15 +291,13 @@ id_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) && a_add_sel->type == ID_ADD_SELECTOR && a_node, FALSE); - if (xmlHasProp (a_node, (const xmlChar *) "id")) { - id = xmlGetProp (a_node, (const xmlChar *) "id"); + id = a_node_iface->getProp (a_node, (const xmlChar *) "id"); + if (id) { if (!strqcmp ((const char *) id, a_add_sel->content.id_name->stryng->str, a_add_sel->content.id_name->stryng->len)) { result = TRUE; } - } - if (id) { - xmlFree (id); + a_node_iface->freePropVal (id); id = NULL; } return result; @@ -302,7 +313,8 @@ id_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) *FALSE otherwise. */ static gboolean -attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) +attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, + CRNodeIface const * a_node_iface, CRXMLNodePtr a_node) { CRAttrSel *cur_sel = NULL; @@ -312,69 +324,39 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) for (cur_sel = a_add_sel->content.attr_sel; cur_sel; cur_sel = cur_sel->next) { + if (!cur_sel->name + || !cur_sel->name->stryng + || !cur_sel->name->stryng->str) + return FALSE; + + char *const value = a_node_iface->getProp (a_node, cur_sel->name->stryng->str); + if (!value) + goto free_and_return_false; + switch (cur_sel->match_way) { case SET: - if (!cur_sel->name - || !cur_sel->name->stryng - || !cur_sel->name->stryng->str) - return FALSE; - - if (!xmlHasProp (a_node, - (const xmlChar *) cur_sel->name->stryng->str)) - return FALSE; break; case EQUALS: - { - xmlChar *value = NULL; - - if (!cur_sel->name - || !cur_sel->name->stryng - || !cur_sel->name->stryng->str - || !cur_sel->value - || !cur_sel->value->stryng - || !cur_sel->value->stryng->str) - return FALSE; - - if (!xmlHasProp - (a_node, - (const xmlChar *) cur_sel->name->stryng->str)) - return FALSE; - - value = xmlGetProp - (a_node, - (const xmlChar *) cur_sel->name->stryng->str); - - if (value - && strcmp - ((const char *) value, - cur_sel->value->stryng->str)) { - xmlFree (value); - return FALSE; - } - xmlFree (value); + if (!cur_sel->value + || !cur_sel->value->stryng + || !cur_sel->value->stryng->str) { + goto free_and_return_false; + } + if (strcmp + (value, + cur_sel->value->stryng->str)) { + goto free_and_return_false; } break; case INCLUDES: { - xmlChar *value = NULL, - *ptr1 = NULL, + char const *ptr1 = NULL, *ptr2 = NULL, *cur = NULL; gboolean found = FALSE; - if (!xmlHasProp - (a_node, - (const xmlChar *) cur_sel->name->stryng->str)) - return FALSE; - value = xmlGetProp - (a_node, - (const xmlChar *) cur_sel->name->stryng->str); - - if (!value) - return FALSE; - /* *here, make sure value is a space *separated list of "words", where one @@ -385,8 +367,8 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) *set ptr1 to the first non white space *char addr. */ - while (cr_utils_is_white_space - (*cur) == TRUE && *cur) + while (cr_utils_is_white_space (*cur) + && *cur) cur++; if (!*cur) break; @@ -395,8 +377,8 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) /* *set ptr2 to the end the word. */ - while (cr_utils_is_white_space - (*cur) == FALSE && *cur) + while (!cr_utils_is_white_space (*cur) + && *cur) cur++; cur--; ptr2 = cur; @@ -411,30 +393,19 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) ptr1 = ptr2 = NULL; } - if (found == FALSE) { - xmlFree (value); - return FALSE; + if (!found) { + goto free_and_return_false; } - xmlFree (value); } break; case DASHMATCH: { - xmlChar *value = NULL, - *ptr1 = NULL, + char const *ptr1 = NULL, *ptr2 = NULL, *cur = NULL; gboolean found = FALSE; - if (!xmlHasProp - (a_node, - (const xmlChar *) cur_sel->name->stryng->str)) - return FALSE; - value = xmlGetProp - (a_node, - (const xmlChar *) cur_sel->name->stryng->str); - /* *here, make sure value is an hyphen *separated list of "words", each of which @@ -453,22 +424,27 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) if (g_strstr_len ((const gchar *) ptr1, ptr2 - ptr1 + 1, cur_sel->value->stryng->str) - == (gchar *) ptr1) { + == ptr1) { found = TRUE; break; } } - if (found == FALSE) { - xmlFree (value); - return FALSE; + if (!found) { + goto free_and_return_false; } - xmlFree (value); } break; default: - return FALSE; + goto free_and_return_false; } + + a_node_iface->freePropVal (value); + continue; + + free_and_return_false: + a_node_iface->freePropVal (value); + return FALSE; } return TRUE; @@ -483,7 +459,7 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) static gboolean additional_selector_matches_node (CRSelEng * a_this, CRAdditionalSel * a_add_sel, - xmlNode * a_node) + CRXMLNodePtr a_node) { CRAdditionalSel *cur_add_sel = NULL, *tail = NULL ; gboolean evaluated = FALSE ; @@ -507,8 +483,9 @@ additional_selector_matches_node (CRSelEng * a_this, && cur_add_sel->content.class_name && cur_add_sel->content.class_name->stryng && cur_add_sel->content.class_name->stryng->str) { - if (class_add_sel_matches_node (cur_add_sel, - a_node) == FALSE) { + if (!class_add_sel_matches_node (cur_add_sel, + PRIVATE(a_this)->node_iface, + a_node)) { return FALSE; } continue ; @@ -516,7 +493,9 @@ additional_selector_matches_node (CRSelEng * a_this, && cur_add_sel->content.id_name && cur_add_sel->content.id_name->stryng && cur_add_sel->content.id_name->stryng->str) { - if (id_add_sel_matches_node (cur_add_sel, a_node) == FALSE) { + if (!id_add_sel_matches_node (cur_add_sel, + PRIVATE(a_this)->node_iface, + a_node)) { return FALSE; } continue ; @@ -527,18 +506,19 @@ additional_selector_matches_node (CRSelEng * a_this, *against an attribute additionnal selector *and an xml node. */ - if (attr_add_sel_matches_node (cur_add_sel, a_node) - == FALSE) { + if (!attr_add_sel_matches_node (cur_add_sel, + PRIVATE(a_this)->node_iface, + a_node)) { return FALSE; } continue ; } else if (cur_add_sel->type == PSEUDO_CLASS_ADD_SELECTOR && cur_add_sel->content.pseudo) { - if (pseudo_class_add_sel_matches_node - (a_this, cur_add_sel, a_node) == TRUE) { - return TRUE; + if (!pseudo_class_add_sel_matches_node + (a_this, cur_add_sel, a_node)) { + return FALSE; } - return FALSE; + continue ; } } if (evaluated == TRUE) @@ -546,60 +526,60 @@ additional_selector_matches_node (CRSelEng * a_this, return FALSE ; } -static xmlNode * -get_next_element_node (xmlNode * a_node) +static CRXMLNodePtr +get_next_element_node (CRNodeIface const * a_node_iface, CRXMLNodePtr a_node) { - xmlNode *cur_node = NULL; + CRXMLNodePtr cur_node = a_node; g_return_val_if_fail (a_node, NULL); - cur_node = a_node->next; - while (cur_node && cur_node->type != XML_ELEMENT_NODE) { - cur_node = cur_node->next; - } + do { + cur_node = a_node_iface->getNextSibling (cur_node); + } while (cur_node && !a_node_iface->isElementNode(cur_node)); return cur_node; } -static xmlNode * -get_next_child_element_node (xmlNode * a_node) +/* TODO: Consider renaming this to get_first_child_element_node. + (cf get_first_parent_element_node, which does getParent until element node + rather than getNextSibling). */ +static CRXMLNodePtr +get_next_child_element_node (CRNodeIface const * a_node_iface, CRXMLNodePtr a_node) { - xmlNode *cur_node = NULL; + CRXMLNodePtr cur_node = NULL; g_return_val_if_fail (a_node, NULL); - cur_node = a_node->children; + cur_node = a_node_iface->getFirstChild (a_node); if (!cur_node) return cur_node; - if (a_node->children->type == XML_ELEMENT_NODE) - return a_node->children; - return get_next_element_node (a_node->children); + if (a_node_iface->isElementNode (cur_node)) + return cur_node; + return get_next_element_node (a_node_iface, cur_node); } -static xmlNode * -get_prev_element_node (xmlNode * a_node) +static CRXMLNodePtr +get_prev_element_node (CRNodeIface const * a_node_iface, CRXMLNodePtr a_node) { - xmlNode *cur_node = NULL; + CRXMLNodePtr cur_node = a_node; g_return_val_if_fail (a_node, NULL); - cur_node = a_node->prev; - while (cur_node && cur_node->type != XML_ELEMENT_NODE) { - cur_node = cur_node->prev; - } + do { + cur_node = a_node_iface->getPrevSibling (cur_node); + } while (cur_node && !a_node_iface->isElementNode(cur_node)); return cur_node; } -static xmlNode * -get_next_parent_element_node (xmlNode * a_node) +static CRXMLNodePtr +get_next_parent_element_node (CRNodeIface const * a_node_iface, CRXMLNodePtr a_node) { - xmlNode *cur_node = NULL; + CRXMLNodePtr cur_node = a_node; g_return_val_if_fail (a_node, NULL); - cur_node = a_node->parent; - while (cur_node && cur_node->type != XML_ELEMENT_NODE) { - cur_node = cur_node->parent; - } + do { + cur_node = a_node_iface->getParentNode (cur_node); + } while (cur_node && !a_node_iface->isElementNode (cur_node)); return cur_node; } @@ -623,20 +603,22 @@ get_next_parent_element_node (xmlNode * a_node) */ static enum CRStatus sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel, - xmlNode * a_node, gboolean * a_result, + CRXMLNodePtr a_node, gboolean * a_result, gboolean a_eval_sel_list_from_end, gboolean a_recurse) { CRSimpleSel *cur_sel = NULL; - xmlNode *cur_node = NULL; + CRXMLNodePtr cur_node = NULL; + CRNodeIface const *node_iface = NULL; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_this && a_node && a_result, CR_BAD_PARAM_ERROR); + node_iface = PRIVATE(a_this)->node_iface; *a_result = FALSE; - if (a_node->type != XML_ELEMENT_NODE) + if (!node_iface->isElementNode(a_node)) return CR_OK; if (a_eval_sel_list_from_end == TRUE) { @@ -653,7 +635,7 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel, && cur_sel->name->stryng && cur_sel->name->stryng->str) && (!strcmp (cur_sel->name->stryng->str, - (const char *) cur_node->name))) + (const char *) node_iface->getLocalName(cur_node)))) || (cur_sel->type_mask & UNIVERSAL_SELECTOR)) { /* *this simple selector @@ -709,7 +691,7 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel, case COMB_WS: /*descendant selector */ { - xmlNode *n = NULL; + CRXMLNodePtr n = NULL; enum CRStatus status = CR_OK; gboolean matches = FALSE; @@ -717,7 +699,9 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel, *walk the xml tree upward looking for a parent *node that matches the preceding selector. */ - for (n = cur_node->parent; n; n = n->parent) { + for (n = node_iface->getParentNode (cur_node); + n; + n = node_iface->getParentNode (n)) { status = sel_matches_node_real (a_this, cur_sel->prev, n, &matches, FALSE, TRUE); @@ -750,13 +734,13 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel, } case COMB_PLUS: - cur_node = get_prev_element_node (cur_node); + cur_node = get_prev_element_node (node_iface, cur_node); if (!cur_node) goto done; break; case COMB_GT: - cur_node = get_next_parent_element_node (cur_node); + cur_node = get_next_parent_element_node (node_iface, cur_node); if (!cur_node) goto done; break; @@ -818,7 +802,7 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel, static enum CRStatus cr_sel_eng_get_matched_rulesets_real (CRSelEng * a_this, CRStyleSheet * a_stylesheet, - xmlNode * a_node, + CRXMLNodePtr a_node, CRStatement ** a_rulesets, gulong * a_len) { @@ -864,7 +848,7 @@ cr_sel_eng_get_matched_rulesets_real (CRSelEng * a_this, sel_list = NULL; /* - *get the the damn selector list in + *get the damn selector list in *which we have to look */ switch (cur_stmt->type) { @@ -1122,14 +1106,14 @@ cr_sel_eng_new (void) { CRSelEng *result = NULL; - result = g_try_malloc (sizeof (CRSelEng)); + result = (CRSelEng *) g_try_malloc (sizeof (CRSelEng)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CRSelEng)); - PRIVATE (result) = g_try_malloc (sizeof (CRSelEngPriv)); + PRIVATE (result) = (CRSelEngPriv *) g_try_malloc (sizeof (CRSelEngPriv)); if (!PRIVATE (result)) { cr_utils_trace_info ("Out of memory"); g_free (result); @@ -1138,11 +1122,11 @@ cr_sel_eng_new (void) memset (PRIVATE (result), 0, sizeof (CRSelEngPriv)); cr_sel_eng_register_pseudo_class_sel_handler (result, (guchar *) "first-child", - IDENT_PSEUDO, (CRPseudoClassSelectorHandler) + IDENT_PSEUDO, /*(CRPseudoClassSelectorHandler)*/ first_child_pseudo_class_handler); cr_sel_eng_register_pseudo_class_sel_handler (result, (guchar *) "lang", - FUNCTION_PSEUDO, (CRPseudoClassSelectorHandler) + FUNCTION_PSEUDO, /*(CRPseudoClassSelectorHandler)*/ lang_pseudo_class_handler); return result; @@ -1173,7 +1157,7 @@ cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng * a_this, g_return_val_if_fail (a_this && PRIVATE (a_this) && a_handler && a_name, CR_BAD_PARAM_ERROR); - handler_entry = g_try_malloc + handler_entry = (struct CRPseudoClassSelHandlerEntry *) g_try_malloc (sizeof (struct CRPseudoClassSelHandlerEntry)); if (!handler_entry) { return CR_OUT_OF_MEMORY_ERROR; @@ -1205,7 +1189,7 @@ cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng * a_this, for (elem = PRIVATE (a_this)->pcs_handlers; elem; elem = g_list_next (elem)) { - entry = elem->data; + entry = (struct CRPseudoClassSelHandlerEntry *) elem->data; if (!strcmp ((const char *) entry->name, (const char *) a_name) && entry->type == a_type) { found = TRUE; @@ -1216,9 +1200,11 @@ cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng * a_this, return CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR; PRIVATE (a_this)->pcs_handlers = g_list_delete_link (PRIVATE (a_this)->pcs_handlers, elem); - entry = elem->data; - if (entry->name) + entry = (struct CRPseudoClassSelHandlerEntry *) elem->data; + if (entry->name) { g_free (entry->name); + entry->name = NULL; + } g_free (elem); g_list_free (deleted_elem); @@ -1247,7 +1233,7 @@ cr_sel_eng_unregister_all_pseudo_class_sel_handlers (CRSelEng * a_this) return CR_OK; for (elem = PRIVATE (a_this)->pcs_handlers; elem; elem = g_list_next (elem)) { - entry = elem->data; + entry = (struct CRPseudoClassSelHandlerEntry *) elem->data; if (!entry) continue; if (entry->name) { @@ -1278,7 +1264,7 @@ cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng * a_this, for (elem = PRIVATE (a_this)->pcs_handlers; elem; elem = g_list_next (elem)) { - entry = elem->data; + entry = (struct CRPseudoClassSelHandlerEntry *) elem->data; if (!strcmp ((const char *) a_name, (const char *) entry->name) && entry->type == a_type) { found = TRUE; @@ -1310,13 +1296,13 @@ cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng * a_this, */ enum CRStatus cr_sel_eng_matches_node (CRSelEng * a_this, CRSimpleSel * a_sel, - xmlNode * a_node, gboolean * a_result) + CRXMLNodePtr a_node, gboolean * a_result) { g_return_val_if_fail (a_this && PRIVATE (a_this) && a_this && a_node && a_result, CR_BAD_PARAM_ERROR); - if (a_node->type != XML_ELEMENT_NODE) { + if (!PRIVATE(a_this)->node_iface->isElementNode (a_node)) { *a_result = FALSE; return CR_OK; } @@ -1347,7 +1333,7 @@ cr_sel_eng_matches_node (CRSelEng * a_this, CRSimpleSel * a_sel, enum CRStatus cr_sel_eng_get_matched_rulesets (CRSelEng * a_this, CRStyleSheet * a_sheet, - xmlNode * a_node, + CRXMLNodePtr a_node, CRStatement *** a_rulesets, gulong * a_len) { CRStatement **stmts_tab = NULL; @@ -1363,7 +1349,7 @@ cr_sel_eng_get_matched_rulesets (CRSelEng * a_this, && a_rulesets && *a_rulesets == NULL && a_len, CR_BAD_PARAM_ERROR); - stmts_tab = g_try_malloc (stmts_chunck_size * sizeof (CRStatement *)); + stmts_tab = (CRStatement **) g_try_malloc (stmts_chunck_size * sizeof (CRStatement *)); if (!stmts_tab) { cr_utils_trace_info ("Out of memory"); @@ -1378,9 +1364,9 @@ cr_sel_eng_get_matched_rulesets (CRSelEng * a_this, while ((status = cr_sel_eng_get_matched_rulesets_real (a_this, a_sheet, a_node, stmts_tab + index, &tab_len)) == CR_OUTPUT_TOO_SHORT_ERROR) { - stmts_tab = g_try_realloc (stmts_tab, - (tab_size + stmts_chunck_size) - * sizeof (CRStatement *)); + stmts_tab = (CRStatement **) g_try_realloc (stmts_tab, + (tab_size + stmts_chunck_size) + * sizeof (CRStatement *)); if (!stmts_tab) { cr_utils_trace_info ("Out of memory"); status = CR_ERROR; @@ -1413,7 +1399,7 @@ cr_sel_eng_get_matched_rulesets (CRSelEng * a_this, enum CRStatus cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, CRCascade * a_cascade, - xmlNode * a_node, + CRXMLNodePtr a_node, CRPropList ** a_props) { CRStatement **stmts_tab = NULL; @@ -1422,7 +1408,7 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, tab_len = 0, i = 0, index = 0; - enum CRStyleOrigin origin = 0; + enum CRStyleOrigin origin; gushort stmts_chunck_size = 8; CRStyleSheet *sheet = NULL; @@ -1430,12 +1416,12 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, && a_cascade && a_node && a_props, CR_BAD_PARAM_ERROR); - for (origin = ORIGIN_UA; origin < NB_ORIGINS; origin++) { + for (origin = ORIGIN_UA; origin < NB_ORIGINS; origin = (enum CRStyleOrigin) (origin + 1)) { sheet = cr_cascade_get_sheet (a_cascade, origin); if (!sheet) continue; if (tab_size - index < 1) { - stmts_tab = g_try_realloc + stmts_tab = (CRStatement **) g_try_realloc (stmts_tab, (tab_size + stmts_chunck_size) * sizeof (CRStatement *)); if (!stmts_tab) { @@ -1453,7 +1439,7 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, while ((status = cr_sel_eng_get_matched_rulesets_real (a_this, sheet, a_node, stmts_tab + index, &tab_len)) == CR_OUTPUT_TOO_SHORT_ERROR) { - stmts_tab = g_try_realloc + stmts_tab = (CRStatement **) g_try_realloc (stmts_tab, (tab_size + stmts_chunck_size) * sizeof (CRStatement *)); if (!stmts_tab) { @@ -1514,7 +1500,7 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, enum CRStatus cr_sel_eng_get_matched_style (CRSelEng * a_this, CRCascade * a_cascade, - xmlNode * a_node, + CRXMLNodePtr a_node, CRStyle * a_parent_style, CRStyle ** a_style, gboolean a_set_props_to_initial_values) diff --git a/src/cr-sel-eng.h b/src/cr-sel-eng.h index cab3d14..564debc 100644 --- a/src/cr-sel-eng.h +++ b/src/cr-sel-eng.h @@ -29,6 +29,7 @@ #include "cr-cascade.h" #include "cr-style.h" #include "cr-prop-list.h" +#include "cr-node-iface.h" #include @@ -56,10 +57,11 @@ struct _CRSelEng CRSelEngPriv *priv ; } ; +void cr_sel_eng_set_node_iface(CRSelEng *a_this, CRNodeIface const *); typedef gboolean (*CRPseudoClassSelectorHandler) (CRSelEng* a_this, CRAdditionalSel *a_add_sel, - xmlNode *a_node) ; + CRXMLNodePtr a_node) ; CRSelEng * cr_sel_eng_new (void) ; enum CRStatus cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng *a_this, @@ -80,24 +82,24 @@ enum CRStatus cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng *a_this, enum CRStatus cr_sel_eng_matches_node (CRSelEng *a_this, CRSimpleSel *a_sel, - xmlNode *a_node, + CRXMLNodePtr a_node, gboolean *a_result) ; enum CRStatus cr_sel_eng_get_matched_rulesets (CRSelEng *a_this, CRStyleSheet *a_sheet, - xmlNode *a_node, + CRXMLNodePtr a_node, CRStatement ***a_rulesets, gulong *a_len) ; enum CRStatus cr_sel_eng_get_matched_properties_from_cascade (CRSelEng *a_this, CRCascade *a_cascade, - xmlNode *a_node, + CRXMLNodePtr a_node, CRPropList **a_props) ; enum CRStatus cr_sel_eng_get_matched_style (CRSelEng *a_this, CRCascade *a_cascade, - xmlNode *a_node, + CRXMLNodePtr a_node, CRStyle *a_parent_style, CRStyle **a_style, gboolean a_set_props_to_initial_values) ; diff --git a/src/cr-selector.c b/src/cr-selector.c index 8902e1c..c56c43f 100644 --- a/src/cr-selector.c +++ b/src/cr-selector.c @@ -40,7 +40,8 @@ cr_selector_new (CRSimpleSel * a_simple_sel) { CRSelector *result = NULL; - result = g_try_malloc (sizeof (CRSelector)); + result = (CRSelector *) g_try_malloc (sizeof (CRSelector)); + if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -143,7 +144,7 @@ cr_selector_to_string (CRSelector const * a_this) guchar *result = NULL; GString *str_buf = NULL; - str_buf = g_string_new (NULL); + str_buf = (GString *) g_string_new (NULL); g_return_val_if_fail (str_buf, NULL); if (a_this) { diff --git a/src/cr-selector.h b/src/cr-selector.h index dd6a7f7..a7e0295 100644 --- a/src/cr-selector.h +++ b/src/cr-selector.h @@ -41,7 +41,7 @@ typedef struct _CRSelector CRSelector ; /** *Abstracts a CSS2 selector as defined in the right part - *of the 'ruleset" production in the appendix D.1 of the + *of the 'ruleset' production in the appendix D.1 of the *css2 spec. *It is actually the abstraction of a comma separated list *of simple selectors list. diff --git a/src/cr-simple-sel.c b/src/cr-simple-sel.c index ac90685..4df93fa 100644 --- a/src/cr-simple-sel.c +++ b/src/cr-simple-sel.c @@ -37,7 +37,7 @@ cr_simple_sel_new (void) { CRSimpleSel *result = NULL; - result = g_try_malloc (sizeof (CRSimpleSel)); + result = (CRSimpleSel *) g_try_malloc (sizeof (CRSimpleSel)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -298,10 +298,10 @@ cr_simple_sel_compute_specificity (CRSimpleSel * a_this) *@a_this: the this pointer of the current instance of #CRSimpleSel. * *The destructor of the current instance of - *#CRSimpleSel. + *#CRSimpleSel. Recursively calls the destructor of #CRSimpleSel->next */ void -cr_simple_sel_destroy (CRSimpleSel * a_this) +cr_simple_sel_destroy (CRSimpleSel * const a_this) { g_return_if_fail (a_this); @@ -317,9 +317,8 @@ cr_simple_sel_destroy (CRSimpleSel * a_this) if (a_this->next) { cr_simple_sel_destroy (a_this->next); + a_this->next = NULL; } - if (a_this) { - g_free (a_this); - } + g_free (a_this); } diff --git a/src/cr-statement.c b/src/cr-statement.c index 638e5bb..e31123a 100644 --- a/src/cr-statement.c +++ b/src/cr-statement.c @@ -41,6 +41,8 @@ parse_font_face_start_font_face_cb (CRDocHandler * a_this, CRStatement *stmt = NULL; enum CRStatus status = CR_OK; + (void) a_location; + stmt = cr_statement_new_at_font_face_rule (NULL, NULL); g_return_if_fail (stmt); @@ -82,6 +84,8 @@ parse_font_face_property_cb (CRDocHandler * a_this, CRStatement *stmt = NULL; CRStatement **stmtptr = NULL; + (void) a_important; + g_return_if_fail (a_this && a_name); stmtptr = &stmt; @@ -144,6 +148,8 @@ parse_page_start_page_cb (CRDocHandler * a_this, enum CRStatus status = CR_OK; CRString *page_name = NULL, *pseudo_name = NULL ; + (void) a_location; + if (a_name) page_name = cr_string_dup (a_name) ; if (a_pseudo_page) @@ -217,6 +223,9 @@ parse_page_end_page_cb (CRDocHandler * a_this, CRStatement *stmt = NULL; CRStatement **stmtptr = NULL; + (void) a_name; + (void) a_pseudo_page; + stmtptr = &stmt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr); g_return_if_fail (status == CR_OK && stmt); @@ -235,6 +244,8 @@ parse_at_media_start_media_cb (CRDocHandler * a_this, CRStatement *at_media = NULL; GList *media_list = NULL; + (void) a_location; + g_return_if_fail (a_this && a_this->priv); if (a_media_list) { @@ -367,6 +378,8 @@ parse_at_media_end_media_cb (CRDocHandler * a_this, CRStatement *at_media = NULL; CRStatement **at_media_ptr = NULL; + (void) a_media_list; + g_return_if_fail (a_this && a_this->priv); at_media_ptr = &at_media; @@ -594,7 +607,10 @@ cr_statement_ruleset_to_string (CRStatement const * a_this, glong a_indent) g_return_val_if_fail (a_this && a_this->type == RULESET_STMT, NULL); - stringue = g_string_new (NULL); + stringue = (GString *) g_string_new (NULL); + if (!stringue) { + return result; + } if (a_this->kind.ruleset->sel_list) { if (a_indent) @@ -625,10 +641,9 @@ cr_statement_ruleset_to_string (CRStatement const * a_this, glong a_indent) g_string_append (stringue, "}"); result = stringue->str; - if (stringue) { - g_string_free (stringue, FALSE); - stringue = NULL; - } + g_string_free (stringue, FALSE); + stringue = NULL; + if (tmp_str) { g_free (tmp_str); tmp_str = NULL; @@ -661,7 +676,7 @@ cr_statement_font_face_rule_to_string (CRStatement const * a_this, NULL); if (a_this->kind.font_face_rule->decl_list) { - stringue = g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; g_return_val_if_fail (stringue, NULL) ; if (a_indent) cr_utils_dump_n_chars2 (' ', stringue, @@ -749,7 +764,7 @@ cr_statement_at_page_rule_to_string (CRStatement const *a_this, GString *stringue = NULL; gchar *result = NULL ; - stringue = g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; cr_utils_dump_n_chars2 (' ', stringue, a_indent) ; g_string_append (stringue, "@page"); @@ -806,7 +821,7 @@ cr_statement_media_rule_to_string (CRStatement const *a_this, NULL); if (a_this->kind.media_rule) { - stringue = g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; cr_utils_dump_n_chars2 (' ', stringue, a_indent); g_string_append (stringue, "@media"); @@ -863,7 +878,7 @@ cr_statement_import_rule_to_string (CRStatement const *a_this, if (a_this->kind.import_rule->url && a_this->kind.import_rule->url->stryng) { - stringue = g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; g_return_val_if_fail (stringue, NULL) ; str = g_strndup (a_this->kind.import_rule->url->stryng->str, a_this->kind.import_rule->url->stryng->len); @@ -1037,7 +1052,7 @@ cr_statement_parse_from_buf (const guchar * a_buf, enum CREncoding a_encoding) *@a_buf: the buffer to parse. *@a_enc: the character encoding of a_buf. * - *Parses a buffer that contains a ruleset statement an instanciates + *Parses a buffer that contains a ruleset statement and instanciates *a #CRStatement of type RULESET_STMT. * *Returns the newly built instance of #CRStatement in case of successful parsing, @@ -1061,7 +1076,7 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf, g_return_val_if_fail (parser, NULL); sac_handler = cr_doc_handler_new (); - g_return_val_if_fail (parser, NULL); + g_return_val_if_fail (sac_handler, NULL); sac_handler->start_selector = parse_ruleset_start_selector_cb; sac_handler->end_selector = parse_ruleset_end_selector_cb; @@ -1133,7 +1148,7 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet, NULL); } - result = g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1142,7 +1157,7 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = RULESET_STMT; - result->kind.ruleset = g_try_malloc (sizeof (CRRuleSet)); + result->kind.ruleset = (CRRuleSet *) g_try_malloc (sizeof (CRRuleSet)); if (!result->kind.ruleset) { cr_utils_trace_info ("Out of memory"); @@ -1268,7 +1283,7 @@ cr_statement_new_at_media_rule (CRStyleSheet * a_sheet, if (a_rulesets) g_return_val_if_fail (a_rulesets->type == RULESET_STMT, NULL); - result = g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1278,7 +1293,7 @@ cr_statement_new_at_media_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_MEDIA_RULE_STMT; - result->kind.media_rule = g_try_malloc (sizeof (CRAtMediaRule)); + result->kind.media_rule = (CRAtMediaRule *) g_try_malloc (sizeof (CRAtMediaRule)); if (!result->kind.media_rule) { cr_utils_trace_info ("Out of memory"); g_free (result); @@ -1327,7 +1342,7 @@ cr_statement_new_at_import_rule (CRStyleSheet * a_container_sheet, { CRStatement *result = NULL; - result = g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1337,7 +1352,7 @@ cr_statement_new_at_import_rule (CRStyleSheet * a_container_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_IMPORT_RULE_STMT; - result->kind.import_rule = g_try_malloc (sizeof (CRAtImportRule)); + result->kind.import_rule = (CRAtImportRule *) g_try_malloc (sizeof (CRAtImportRule)); if (!result->kind.import_rule) { cr_utils_trace_info ("Out of memory"); @@ -1376,7 +1391,7 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf, CRStatement *result = NULL; GList *media_list = NULL; CRString *import_string = NULL; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); @@ -1450,7 +1465,7 @@ cr_statement_new_at_page_rule (CRStyleSheet * a_sheet, { CRStatement *result = NULL; - result = g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1460,7 +1475,7 @@ cr_statement_new_at_page_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_PAGE_RULE_STMT; - result->kind.page_rule = g_try_malloc (sizeof (CRAtPageRule)); + result->kind.page_rule = (CRAtPageRule *) g_try_malloc (sizeof (CRAtPageRule)); if (!result->kind.page_rule) { cr_utils_trace_info ("Out of memory"); @@ -1575,7 +1590,7 @@ cr_statement_new_at_charset_rule (CRStyleSheet * a_sheet, g_return_val_if_fail (a_charset, NULL); - result = g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1585,7 +1600,7 @@ cr_statement_new_at_charset_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_CHARSET_RULE_STMT; - result->kind.charset_rule = g_try_malloc (sizeof (CRAtCharsetRule)); + result->kind.charset_rule = (CRAtCharsetRule *) g_try_malloc (sizeof (CRAtCharsetRule)); if (!result->kind.charset_rule) { cr_utils_trace_info ("Out of memory"); @@ -1669,7 +1684,7 @@ cr_statement_new_at_font_face_rule (CRStyleSheet * a_sheet, { CRStatement *result = NULL; - result = g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1678,7 +1693,7 @@ cr_statement_new_at_font_face_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_FONT_FACE_RULE_STMT; - result->kind.font_face_rule = g_try_malloc + result->kind.font_face_rule = (CRAtFontFaceRule *) g_try_malloc (sizeof (CRAtFontFaceRule)); if (!result->kind.font_face_rule) { @@ -2001,7 +2016,7 @@ cr_statement_ruleset_set_sel_list (CRStatement * a_this, * cr_statement_ruleset_get_declarations: * *@a_this: the current instance of #CRStatement. - *@a_decl_list: out parameter. A pointer to the the returned + *@a_decl_list: out parameter. A pointer to the returned *list of declaration. Must not be NULL. * *Gets a pointer to the list of declaration contained diff --git a/src/cr-string.c b/src/cr-string.c index 1b10bb2..86ad343 100644 --- a/src/cr-string.c +++ b/src/cr-string.c @@ -34,7 +34,7 @@ cr_string_new (void) { CRString *result = NULL ; - result = g_try_malloc (sizeof (CRString)) ; + result = (CRString *) g_try_malloc (sizeof (CRString)) ; if (!result) { cr_utils_trace_info ("Out of memory") ; return NULL ; diff --git a/src/cr-style.c b/src/cr-style.c index 24919eb..2b865c2 100644 --- a/src/cr-style.c +++ b/src/cr-style.c @@ -36,7 +36,7 @@ *Each supported css property has an ID which is *an entry into a property "population" jump table. *each entry of the property population jump table - *contains code to tranform the literal form of + *contains code to transform the literal form of *a property value into a strongly typed value. */ enum CRPropertyID { @@ -142,13 +142,13 @@ static CRPropertyDesc gv_prop_table[] = { {"font-weight", PROP_ID_FONT_WEIGHT}, {"white-space", PROP_ID_WHITE_SPACE}, /*must be the last one */ - {NULL, 0} + {NULL, (enum CRPropertyID) 0} }; /** *A the key/value pair of this hash table *are: - *key => name of the the css propertie found in gv_prop_table + *key => name of the css property found in gv_prop_table *value => matching property id found in gv_prop_table. *So this hash table is here just to retrieval of a property id *from a property name. @@ -185,7 +185,7 @@ static struct CRNumPropEnumDumpInfo gv_num_props_dump_infos[] = { {NUM_PROP_MARGIN_BOTTOM, "margin-bottom"}, {NUM_PROP_MARGIN_LEFT, "margin-left"}, {NUM_PROP_WIDTH, "width"}, - {0, NULL} + {(enum CRNumProp) 0, NULL} }; struct CRRgbPropEnumDumpInfo { @@ -200,7 +200,7 @@ static struct CRRgbPropEnumDumpInfo gv_rgb_props_dump_infos[] = { {RGB_PROP_BORDER_LEFT_COLOR, "left-color"}, {RGB_PROP_COLOR, "color"}, {RGB_PROP_BACKGROUND_COLOR, "background-color"}, - {0, NULL} + {(enum CRRgbProp) 0, NULL} }; struct CRBorderStylePropEnumDumpInfo { @@ -215,7 +215,7 @@ static struct CRBorderStylePropEnumDumpInfo gv_border_style_props_dump_infos[] {BORDER_STYLE_PROP_RIGHT, "border-style-right"}, {BORDER_STYLE_PROP_BOTTOM, "boder-style-bottom"}, {BORDER_STYLE_PROP_LEFT, "border-style-left"}, - {0, NULL} + {(enum CRBorderStyleProp) 0, NULL} }; static enum CRStatus @@ -421,11 +421,11 @@ cr_style_get_prop_id (const guchar * a_prop) cr_style_init_properties (); } - raw_id = g_hash_table_lookup (gv_prop_hash, a_prop); + raw_id = (gpointer *) g_hash_table_lookup (gv_prop_hash, a_prop); if (!raw_id) { return PROP_ID_NOT_KNOWN; } - return GPOINTER_TO_INT (raw_id); + return (enum CRPropertyID)GPOINTER_TO_INT (raw_id); } static enum CRStatus @@ -570,8 +570,6 @@ set_prop_border_width_from_value (CRStyle *a_style, CRTerm *a_value) { CRTerm *cur_term = NULL ; - enum CRDirection direction = DIR_TOP ; - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; cur_term = a_value ; @@ -579,9 +577,10 @@ set_prop_border_width_from_value (CRStyle *a_style, if (!cur_term) return CR_ERROR ; - for (direction = DIR_TOP ; - direction < NB_DIRS ; direction ++) { - set_prop_border_x_width_from_value (a_style, + int dir; + for (dir = (int) DIR_TOP ; dir < (int)NB_DIRS ; dir++) { + enum CRDirection direction = (enum CRDirection)dir; + set_prop_border_x_width_from_value (a_style, cur_term, direction) ; } @@ -699,7 +698,6 @@ set_prop_border_style_from_value (CRStyle *a_style, CRTerm *a_value) { CRTerm *cur_term = NULL ; - enum CRDirection direction = DIR_TOP ; g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; @@ -709,9 +707,9 @@ set_prop_border_style_from_value (CRStyle *a_style, return CR_ERROR ; } - for (direction = DIR_TOP ; - direction < NB_DIRS ; - direction ++) { + int dir; + for (dir = (int)DIR_TOP ; dir < (int)NB_DIRS ; dir++) { + enum CRDirection direction = (enum CRDirection)dir; set_prop_border_x_style_from_value (a_style, cur_term, direction) ; @@ -1166,14 +1164,13 @@ set_prop_border_x_from_value (CRStyle * a_style, CRTerm * a_value, static enum CRStatus set_prop_border_from_value (CRStyle * a_style, CRTerm * a_value) { - enum CRDirection direction = 0; - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - for (direction = 0; direction < NB_DIRS; direction++) { + int dir; + for (dir = 0; dir < (int)NB_DIRS; dir++) { set_prop_border_x_from_value (a_style, a_value, - direction); + (enum CRDirection)dir); } return CR_OK; @@ -1183,7 +1180,6 @@ static enum CRStatus set_prop_padding_from_value (CRStyle * a_style, CRTerm * a_value) { CRTerm *cur_term = NULL; - enum CRDirection direction = 0; enum CRStatus status = CR_OK; g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); @@ -1197,8 +1193,10 @@ set_prop_padding_from_value (CRStyle * a_style, CRTerm * a_value) if (!cur_term) return CR_ERROR ; - for (direction = 0; direction < NB_DIRS; direction++) { - set_prop_padding_x_from_value (a_style, cur_term, direction); + int dir; + for (dir = 0; dir < (int)NB_DIRS; dir++) { + set_prop_padding_x_from_value (a_style, + cur_term, (enum CRDirection)dir); } cur_term = cur_term->next; @@ -1234,7 +1232,6 @@ static enum CRStatus set_prop_margin_from_value (CRStyle * a_style, CRTerm * a_value) { CRTerm *cur_term = NULL; - enum CRDirection direction = 0; enum CRStatus status = CR_OK; g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); @@ -1248,8 +1245,10 @@ set_prop_margin_from_value (CRStyle * a_style, CRTerm * a_value) if (!cur_term) return CR_OK; - for (direction = 0; direction < NB_DIRS; direction++) { - set_prop_margin_x_from_value (a_style, cur_term, direction); + int dir; + for (dir = 0; dir < (int)NB_DIRS; dir++) { + set_prop_margin_x_from_value(a_style, + cur_term, (enum CRDirection)dir); } cur_term = cur_term->next; @@ -1713,7 +1712,7 @@ cr_style_new (gboolean a_set_props_to_initial_values) { CRStyle *result = NULL; - result = g_try_malloc (sizeof (CRStyle)); + result = (CRStyle *) g_try_malloc (sizeof (CRStyle)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -2682,7 +2681,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) *before outputing it value */ cr_utils_dump_n_chars2 (' ', str, indent); - tmp_str = (gchar *) num_prop_code_to_string (i); + tmp_str = (gchar *) num_prop_code_to_string ((enum CRNumProp) i); if (tmp_str) { g_string_append_printf (str, "%s: ", tmp_str); } else { @@ -2696,7 +2695,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) } /*loop over the rgb_props and to_string() them all */ for (i = RGB_PROP_BORDER_TOP_COLOR; i < NB_RGB_PROPS; i++) { - tmp_str = (gchar *) rgb_prop_code_to_string (i); + tmp_str = (gchar *) rgb_prop_code_to_string ((enum CRRgbProp) i); cr_utils_dump_n_chars2 (' ', str, indent); if (tmp_str) { g_string_append_printf (str, "%s: ", tmp_str); @@ -2711,7 +2710,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) } /*loop over the border_style_props and to_string() them */ for (i = BORDER_STYLE_PROP_TOP; i < NB_BORDER_STYLE_PROPS; i++) { - tmp_str = (gchar *) border_style_prop_code_to_string (i); + tmp_str = (gchar *) border_style_prop_code_to_string ((enum CRBorderStyleProp) i); cr_utils_dump_n_chars2 (' ', str, indent); if (tmp_str) { g_string_append_printf (str, "%s: ", tmp_str); diff --git a/src/cr-stylesheet.c b/src/cr-stylesheet.c index 69909da..cb5de69 100644 --- a/src/cr-stylesheet.c +++ b/src/cr-stylesheet.c @@ -38,7 +38,7 @@ cr_stylesheet_new (CRStatement * a_stmts) { CRStyleSheet *result; - result = g_try_malloc (sizeof (CRStyleSheet)); + result = (CRStyleSheet *) g_try_malloc (sizeof (CRStyleSheet)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; diff --git a/src/cr-term.c b/src/cr-term.c index 9ffe672..1c50aed 100644 --- a/src/cr-term.c +++ b/src/cr-term.c @@ -86,7 +86,7 @@ cr_term_new (void) { CRTerm *result = NULL; - result = g_try_malloc (sizeof (CRTerm)); + result = (CRTerm *) g_try_malloc (sizeof (CRTerm)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -767,12 +767,12 @@ cr_term_unref (CRTerm * a_this) } /** - *The destructor of the the #CRTerm class. + *The destructor of the #CRTerm class. *@param a_this the "this pointer" of the current instance *of #CRTerm. */ void -cr_term_destroy (CRTerm * a_this) +cr_term_destroy (CRTerm * const a_this) { g_return_if_fail (a_this); @@ -783,8 +783,5 @@ cr_term_destroy (CRTerm * a_this) a_this->next = NULL; } - if (a_this) { - g_free (a_this); - } - + g_free (a_this); } diff --git a/src/cr-term.h b/src/cr-term.h index 0f22dda..e85867a 100644 --- a/src/cr-term.h +++ b/src/cr-term.h @@ -35,7 +35,7 @@ G_BEGIN_DECLS /** *@file - *Declaration of the #CRTem class. + *Declaration of the #CRTerm class. */ enum CRTermType diff --git a/src/cr-tknzr.c b/src/cr-tknzr.c index ca9316e..83f6ab3 100644 --- a/src/cr-tknzr.c +++ b/src/cr-tknzr.c @@ -434,7 +434,7 @@ cr_tknzr_parse_comment (CRTknzr * a_this, CRInputPos init_pos; guint32 cur_char = 0, next_char= 0; CRString *comment = NULL; - CRParsingLocation loc = {0} ; + CRParsingLocation loc = {0,0,0} ; g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input, @@ -699,13 +699,14 @@ cr_tknzr_parse_string (CRTknzr * a_this, CRString ** a_str) guchar next_chars[2] = { 0 }; PEEK_BYTE (a_this, 1, &next_chars[0]); - PEEK_BYTE (a_this, 2, &next_chars[1]); if (next_chars[0] == '\\') { guchar *tmp_char_ptr1 = NULL, *tmp_char_ptr2 = NULL; guint32 esc_code = 0; + PEEK_BYTE (a_this, 2, &next_chars[1]); + if (next_chars[1] == '\'' || next_chars[1] == '"') { g_string_append_unichar (str->stryng, next_chars[1]); @@ -1023,7 +1024,7 @@ cr_tknzr_parse_name (CRTknzr * a_this, gboolean str_needs_free = FALSE, is_first_nmchar=TRUE ; glong i = 0; - CRParsingLocation loc = {0} ; + CRParsingLocation loc = {0,0,0} ; g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input @@ -1075,7 +1076,7 @@ cr_tknzr_parse_hash (CRTknzr * a_this, CRString ** a_str) CRInputPos init_pos; enum CRStatus status = CR_OK; gboolean str_needs_free = FALSE; - CRParsingLocation loc = {0} ; + CRParsingLocation loc = {0,0,0} ; g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input, @@ -1128,7 +1129,7 @@ cr_tknzr_parse_uri (CRTknzr * a_this, enum CRStatus status = CR_PARSING_ERROR; guchar tab[4] = { 0 }, *tmp_ptr1 = NULL, *tmp_ptr2 = NULL; CRString *str = NULL; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; g_return_val_if_fail (a_this && PRIVATE (a_this) @@ -1253,7 +1254,7 @@ cr_tknzr_parse_rgb (CRTknzr * a_this, CRRgb ** a_rgb) blue = 0, i = 0; gboolean is_percentage = FALSE; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); @@ -1280,7 +1281,7 @@ cr_tknzr_parse_rgb (CRTknzr * a_this, CRRgb ** a_rgb) status = cr_tknzr_parse_num (a_this, &num); ENSURE_PARSING_COND ((status == CR_OK) && (num != NULL)); - red = num->val; + red = (glong)num->val; cr_num_destroy (num); num = NULL; @@ -1306,9 +1307,9 @@ cr_tknzr_parse_rgb (CRTknzr * a_this, CRRgb ** a_rgb) } if (i == 0) { - green = num->val; + green = (glong)num->val; } else if (i == 1) { - blue = num->val; + blue = (glong)num->val; } if (num) { @@ -1485,7 +1486,7 @@ cr_tknzr_parse_num (CRTknzr * a_this, next_char = 0; gdouble numerator, denominator = 1; CRInputPos init_pos; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; int sign = 1; g_return_val_if_fail (a_this && PRIVATE (a_this) @@ -1587,7 +1588,7 @@ cr_tknzr_new (CRInput * a_input) { CRTknzr *result = NULL; - result = g_try_malloc (sizeof (CRTknzr)); + result = (CRTknzr *) g_try_malloc (sizeof (CRTknzr)); if (result == NULL) { cr_utils_trace_info ("Out of memory"); @@ -1596,7 +1597,7 @@ cr_tknzr_new (CRInput * a_input) memset (result, 0, sizeof (CRTknzr)); - result->priv = g_try_malloc (sizeof (CRTknzrPriv)); + result->priv = (CRTknzrPriv *)g_try_malloc (sizeof (CRTknzrPriv)); if (result->priv == NULL) { cr_utils_trace_info ("Out of memory"); @@ -1968,7 +1969,7 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk) CRInput *input = NULL; CRString *str = NULL; CRRgb *rgb = NULL; - CRParsingLocation location = {0} ; + CRParsingLocation location = {0,0,0} ; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_tk && *a_tk == NULL diff --git a/src/cr-token.c b/src/cr-token.c index e240ab8..dfe83e2 100644 --- a/src/cr-token.c +++ b/src/cr-token.c @@ -135,7 +135,7 @@ cr_token_new (void) { CRToken *result = NULL; - result = g_try_malloc (sizeof (CRToken)); + result = (CRToken *) g_try_malloc (sizeof (CRToken)); if (result == NULL) { cr_utils_trace_info ("Out of memory"); diff --git a/src/cr-utils.c b/src/cr-utils.c index 2420cec..bfb5870 100644 --- a/src/cr-utils.c +++ b/src/cr-utils.c @@ -722,7 +722,7 @@ cr_utils_utf8_str_to_ucs4 (const guchar * a_in, g_return_val_if_fail (status == CR_OK, status); - *a_out = g_malloc0 (*a_out_len * sizeof (guint32)); + *a_out = (guint32 *) g_malloc0 (*a_out_len * sizeof (guint32)); status = cr_utils_utf8_to_ucs4 (a_in, a_in_len, *a_out, a_out_len); @@ -959,7 +959,7 @@ cr_utils_ucs1_str_to_utf8 (const guchar * a_in, g_return_val_if_fail (status == CR_OK, status); - *a_out = g_malloc0 (out_len); + *a_out = (guchar *) g_malloc0 (out_len); status = cr_utils_ucs1_to_utf8 (a_in, a_in_len, *a_out, &out_len); @@ -1158,7 +1158,7 @@ cr_utils_utf8_str_to_ucs1 (const guchar * a_in, g_return_val_if_fail (status == CR_OK, status); - *a_out = g_malloc0 (*a_out_len * sizeof (guint32)); + *a_out = (guchar *) g_malloc0 (*a_out_len * sizeof (guint32)); status = cr_utils_utf8_to_ucs1 (a_in, a_in_len, *a_out, a_out_len); return status; diff --git a/src/cr-utils.h b/src/cr-utils.h index 54aa249..3959b10 100644 --- a/src/cr-utils.h +++ b/src/cr-utils.h @@ -26,7 +26,10 @@ #include #include -#include "libcroco-config.h" +/* + * We're disabling this #include for Inkscape: see comment in libcroco.h. +//#include "libcroco-config.h" + */ G_BEGIN_DECLS diff --git a/src/libcroco.h b/src/libcroco.h index eabc596..579715a 100644 --- a/src/libcroco.h +++ b/src/libcroco.h @@ -21,7 +21,11 @@ #ifndef __LIBCROCO_H__ #define __LIBCROCO_H__ -#include "libcroco-config.h" +/* + * We're disabling this for inkscape: none of its macros are actually used anyway, + * so we might as well keep the build process simple. +//#include "libcroco-config.h" + */ #include "cr-utils.h" #include "cr-pseudo.h"