diff options
42 files changed, 973 insertions, 540 deletions
diff --git a/src/cr-declaration.c b/src/cr-declaration.c index 2e5986e..77e58bd 100644 --- a/src/cr-declaration.c +++ b/src/cr-declaration.c @@ -121,7 +121,7 @@ cr_declaration_parse_from_buf (CRStatement * a_statement, g_return_val_if_fail (a_statement->type == RULESET_STMT, NULL); - parser = cr_parser_new_from_buf (a_str, strlen (a_str), a_enc, FALSE); + parser = cr_parser_new_from_buf ((guchar*)a_str, strlen (a_str), a_enc, FALSE); g_return_val_if_fail (parser, NULL); status = cr_parser_try_to_skip_spaces_and_comments (parser); @@ -183,7 +183,7 @@ cr_declaration_parse_list_from_buf (const guchar * a_str, g_return_val_if_fail (a_str, NULL); - parser = cr_parser_new_from_buf (a_str, strlen (a_str), a_enc, FALSE); + parser = cr_parser_new_from_buf ((guchar*)a_str, strlen (a_str), a_enc, FALSE); g_return_val_if_fail (parser, NULL); status = cr_parser_get_tknzr (parser, &tokenizer); if (status != CR_OK || !tokenizer) { diff --git a/src/cr-doc-handler.c b/src/cr-doc-handler.c index de8fb74..6ff51e6 100644 --- a/src/cr-doc-handler.c +++ b/src/cr-doc-handler.c @@ -3,8 +3,6 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2.1 of the GNU Lesser General Public * License as published by the Free Software Foundation. @@ -18,6 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * + * See COPRYRIGHTS file for copyright information. */ #include "cr-doc-handler.h" @@ -72,7 +72,6 @@ cr_doc_handler_new (void) return NULL; } - cr_doc_handler_ref (result); cr_doc_handler_set_default_sac_handler (result); return result; diff --git a/src/cr-input.c b/src/cr-input.c index 6d3d639..64c14f8 100644 --- a/src/cr-input.c +++ b/src/cr-input.c @@ -117,6 +117,7 @@ cr_input_new_real (void) /** *Creates a new input stream from a memory buffer. *@param a_buf the memory buffer to create the input stream from. + *The #CRInput keeps this pointer so user should not free it !. *@param a_len the size of the input buffer. *@param a_enc the buffer's encoding. *@param a_free_buf if set to TRUE, this a_buf will be freed @@ -125,9 +126,10 @@ cr_input_new_real (void) *@return the newly built instance of #CRInput. */ CRInput * -cr_input_new_from_buf (const guchar * a_buf, +cr_input_new_from_buf (guchar * a_buf, gulong a_len, - enum CREncoding a_enc, gboolean a_free_buf) + enum CREncoding a_enc, + gboolean a_free_buf) { CRInput *result = NULL; enum CRStatus status = CR_OK; @@ -150,20 +152,22 @@ cr_input_new_from_buf (const guchar * a_buf, (enc_handler, a_buf, &len, &PRIVATE (result)->in_buf, &PRIVATE (result)->in_buf_size); - if (status != CR_OK) goto error; - + PRIVATE (result)->free_in_buf = TRUE; + if (a_free_buf == TRUE && a_buf) { + g_free (a_buf) ; + a_buf = NULL ; + } PRIVATE (result)->line = 1; PRIVATE (result)->nb_bytes = PRIVATE (result)->in_buf_size; } else { PRIVATE (result)->in_buf = (guchar *) a_buf; PRIVATE (result)->in_buf_size = a_len; PRIVATE (result)->nb_bytes = a_len; + PRIVATE (result)->free_in_buf = a_free_buf; } - PRIVATE (result)->free_in_buf = a_free_buf; - return result; error: @@ -247,6 +251,11 @@ cr_input_new_from_uri (const gchar * a_file_uri, enum CREncoding a_enc) if (!result) { goto cleanup; } + /* + *we should free buf here because it's own by CRInput. + *(see the last parameter of cr_input_new_from_buf(). + */ + buf = NULL ; } cleanup: diff --git a/src/cr-input.h b/src/cr-input.h index 3c450a5..99ba8df 100644 --- a/src/cr-input.h +++ b/src/cr-input.h @@ -3,8 +3,6 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2.1 of the GNU Lesser General Public * License as published by the Free Software Foundation. @@ -18,6 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * + * See the COPYRIGHTS file for copyrights information. */ @@ -64,7 +64,7 @@ struct _CRInputPos } ; CRInput * -cr_input_new_from_buf (const guchar *a_buf, gulong a_len, +cr_input_new_from_buf (guchar *a_buf, gulong a_len, enum CREncoding a_enc, gboolean a_free_buf) ; CRInput * cr_input_new_from_uri (const gchar *a_file_uri, enum CREncoding a_enc) ; diff --git a/src/cr-om-parser.c b/src/cr-om-parser.c index d1b85e3..4b0ab0b 100644 --- a/src/cr-om-parser.c +++ b/src/cr-om-parser.c @@ -216,11 +216,13 @@ start_font_face (CRDocHandler * a_this) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; + ParsingContext **ctxtptr = NULL; g_return_if_fail (a_this); g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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); @@ -235,12 +237,14 @@ 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); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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 @@ -276,9 +280,11 @@ end_document (CRDocHandler * a_this) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; + ParsingContext **ctxtptr = NULL; g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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) @@ -308,10 +314,11 @@ charset (CRDocHandler * a_this, GString * a_charset) GString *charset = NULL; ParsingContext *ctxt = NULL; + ParsingContext **ctxtptr = NULL; g_return_if_fail (a_this); - - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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); @@ -342,10 +349,11 @@ start_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; + ParsingContext **ctxtptr = NULL; g_return_if_fail (a_this); - - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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); @@ -384,11 +392,12 @@ end_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo_page) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; + ParsingContext **ctxtptr = NULL; CRStatement *stmt = NULL; g_return_if_fail (a_this); - - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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 @@ -416,10 +425,12 @@ start_media (CRDocHandler * a_this, GList * a_media_list) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; + ParsingContext **ctxtptr = NULL; GList *media_list = NULL; g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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 @@ -443,10 +454,12 @@ 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); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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 @@ -475,11 +488,13 @@ import_style (CRDocHandler * a_this, GList * a_media_list, CRStatement *stmt = NULL, *stmt2 = NULL; ParsingContext *ctxt = NULL; + ParsingContext **ctxtptr = NULL; GList *media_list = NULL, *cur = NULL; g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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); @@ -538,10 +553,11 @@ 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); - - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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 */ @@ -558,10 +574,11 @@ end_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); - - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + 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); @@ -611,12 +628,14 @@ property (CRDocHandler * a_this, { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; + ParsingContext **ctxtptr = NULL; CRDeclaration *decl = NULL, *decl2 = NULL; GString *str = NULL; g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + ctxtptr = &ctxt; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); /* @@ -711,10 +730,11 @@ error (CRDocHandler * a_this) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; + ParsingContext **ctxtptr = NULL; g_return_if_fail (a_this); - - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + ctxtptr = &ctxt; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK && ctxt); if (ctxt->cur_stmt) { @@ -728,8 +748,10 @@ unrecoverable_error (CRDocHandler * a_this) { enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; + ParsingContext **ctxtptr = NULL; - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + ctxtptr = &ctxt; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); g_return_if_fail (status == CR_OK); if (ctxt) { @@ -828,14 +850,15 @@ cr_om_parser_parse_buf (CROMParser * a_this, if (status == CR_OK) { CRStyleSheet *result = NULL; + CRStyleSheet **resultptr = NULL; CRDocHandler *sac_handler = NULL; cr_parser_get_sac_handler (PRIVATE (a_this)->parser, &sac_handler); g_return_val_if_fail (sac_handler, CR_ERROR); - + resultptr = &result; status = cr_doc_handler_get_result (sac_handler, - (gpointer *) & result); + (gpointer *) resultptr); g_return_val_if_fail (status == CR_OK, status); if (result) @@ -912,14 +935,15 @@ cr_om_parser_parse_file (CROMParser * a_this, if (status == CR_OK) { CRStyleSheet *result = NULL; + CRStyleSheet **resultptr = NULL; CRDocHandler *sac_handler = NULL; cr_parser_get_sac_handler (PRIVATE (a_this)->parser, &sac_handler); g_return_val_if_fail (sac_handler, CR_ERROR); - + resultptr = &result; status = cr_doc_handler_get_result - (sac_handler, (gpointer *) & result); + (sac_handler, (gpointer *) resultptr); g_return_val_if_fail (status == CR_OK, status); if (result) *a_result = result; diff --git a/src/cr-parser.c b/src/cr-parser.c index 9e51695..b1e6f8d 100644 --- a/src/cr-parser.c +++ b/src/cr-parser.c @@ -355,9 +355,6 @@ static enum CRStatus cr_parser_parse_string (CRParser * a_this, static enum CRStatus cr_parser_parse_ident (CRParser * a_this, GString ** a_str); -static enum CRStatus cr_parser_parse_vendor_specific_ident (CRParser * a_this, - GString ** a_str); - static enum CRStatus cr_parser_parse_uri (CRParser * a_this, GString ** a_str); @@ -1491,7 +1488,6 @@ cr_parser_parse_any_core (CRParser * a_this) case DASHMATCH_TK: case S_TK: case IMPORTANT_SYM_TK: - case SEMICOLON_TK: status = CR_OK; break; case FUNCTION_TK: @@ -1756,9 +1752,6 @@ cr_parser_parse_property (CRParser * a_this, GString ** a_property) RECORD_INITIAL_POS (a_this, &init_pos); status = cr_parser_parse_ident (a_this, a_property); - if (status != CR_OK) - status = cr_parser_parse_vendor_specific_ident - (a_this, a_property); CHECK_PARSING_STATUS (status, TRUE); cr_parser_try_to_skip_spaces_and_comments (a_this); @@ -2495,35 +2488,6 @@ cr_parser_parse_ident (CRParser * a_this, GString ** a_str) } /** - *Parses a "vendor-specific-ident" as not defined in the CSS2 spec. - *It's only a dash followed by an identifier. - * - *@param a_this the currens instance of #CRParser. - * - *@param a_str a pointer to parsed ident. If *a_str is NULL, - *this function allocates a new instance of GString. If not, - *the function just appends the parsed string to the one passed. - *In both cases it is up to the caller to free *a_str. - * - *@return CR_OK upon successfull completion, an error code - *otherwise. - */ -static enum CRStatus -cr_parser_parse_vendor_specific_ident (CRParser * a_this, GString ** a_str) -{ - enum CRStatus status = CR_OK; - - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->tknzr - && a_str, CR_BAD_PARAM_ERROR); - - status = cr_tknzr_parse_token (PRIVATE (a_this)->tknzr, - VENDOR_SPECIFIC_IDENT_TK, NO_ET, a_str, - NULL); - return status; -} - -/** *Parses a stylesheet as defined in the css2 spec in appendix D.1: *stylesheet ::= [ CHARSET_SYM S* STRING S* ';' ]? * [S|CDO|CDC]* [ import [S|CDO|CDC]* ]* @@ -3021,9 +2985,10 @@ cr_parser_new (CRTknzr * a_tknzr) *@return the newly built parser, or NULL if an error arises. */ CRParser * -cr_parser_new_from_buf (const guchar * a_buf, +cr_parser_new_from_buf (guchar * a_buf, gulong a_len, - enum CREncoding a_enc, gboolean a_free_buf) + enum CREncoding a_enc, + gboolean a_free_buf) { CRParser *result = NULL; CRInput *input = NULL; @@ -3372,6 +3337,7 @@ cr_parser_parse_declaration (CRParser * a_this, if (status == CR_END_OF_INPUT_ERROR) goto error; + CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, "while parsing declaration: next property is malformed", @@ -3550,8 +3516,7 @@ cr_parser_parse_ruleset (CRParser * a_this) PRIVATE (a_this)->state = TRY_PARSE_RULESET_STATE; status = cr_parser_parse_declaration (a_this, &property, - &expr, &is_important); - + &expr, &is_important); if (expr) { cr_term_ref (expr); } @@ -3561,8 +3526,7 @@ cr_parser_parse_ruleset (CRParser * a_this) PRIVATE (a_this)->sac_handler->property (PRIVATE (a_this)->sac_handler, property, expr, is_important); - } - + } if (status == CR_OK) { /* *free the allocated @@ -3573,11 +3537,22 @@ cr_parser_parse_ruleset (CRParser * a_this) g_string_free (property, TRUE); property = NULL; } - if (expr) { cr_term_unref (expr); expr = NULL; } + } else {/*status != CR_OK*/ + guint32 c = 0 ; + /* + *test if we have reached '}', which + *would mean that we are parsing an empty ruleset (eg. x{ }) + *In that case, goto end_of_ruleset. + */ + status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, &c) ; + if (status == CR_OK && c == '}') { + status = CR_OK ; + goto end_of_ruleset ; + } } CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, @@ -3616,10 +3591,10 @@ cr_parser_parse_ruleset (CRParser * a_this) expr = NULL; } } - cr_parser_try_to_skip_spaces_and_comments (a_this); + end_of_ruleset: + cr_parser_try_to_skip_spaces_and_comments (a_this); READ_NEXT_CHAR (a_this, &cur_char); - ENSURE_PARSING_COND_ERR (a_this, cur_char == '}', "while parsing rulset: current char must be a '}'", @@ -3652,7 +3627,7 @@ cr_parser_parse_ruleset (CRParser * a_this) return CR_OK; - error: + error: if (start_selector == TRUE && PRIVATE (a_this)->sac_handler && PRIVATE (a_this)->sac_handler->error) { @@ -4544,7 +4519,7 @@ cr_parser_parse_buf (CRParser * a_this, g_return_val_if_fail (a_this && PRIVATE (a_this) && a_buf, CR_BAD_PARAM_ERROR); - tknzr = cr_tknzr_new_from_buf (a_buf, a_len, a_enc, FALSE); + tknzr = cr_tknzr_new_from_buf ((guchar*)a_buf, a_len, a_enc, FALSE); g_return_val_if_fail (tknzr != NULL, CR_ERROR); diff --git a/src/cr-parser.h b/src/cr-parser.h index 1729ff6..69c7bcc 100644 --- a/src/cr-parser.h +++ b/src/cr-parser.h @@ -3,8 +3,6 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2.1 of the GNU Lesser General Public * License as published by the Free Software Foundation. @@ -18,6 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * + * See COPYRIGHTS file for copyrights information. */ @@ -60,7 +60,7 @@ CRParser * cr_parser_new (CRTknzr *a_tknzr) ; CRParser * -cr_parser_new_from_buf (const guchar *a_buf, gulong a_len, +cr_parser_new_from_buf (guchar *a_buf, gulong a_len, enum CREncoding a_enc, gboolean a_free_buf) ; CRParser * diff --git a/src/cr-rgb.c b/src/cr-rgb.c index 5cacb3e..7ceea11 100644 --- a/src/cr-rgb.c +++ b/src/cr-rgb.c @@ -3,8 +3,6 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2.1 of the GNU Lesser General Public * License as published by the Free Software Foundation. @@ -18,11 +16,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * + * See COPYRIGHTS file for copyrights information. */ -/* - *$Id$ - */ #include <stdio.h> #include <string.h> @@ -378,7 +375,7 @@ cr_rgb_set_from_name (CRRgb * a_this, const guchar * a_color_name) if (i < sizeof (gv_standard_colors)) status = CR_OK; else - status = CR_UNKNOWN_TYPE_ERROR; + status = CR_UNKNOWN_TYPE_ERROR; return status; } diff --git a/src/cr-sel-eng.c b/src/cr-sel-eng.c index 3161adc..2e23442 100644 --- a/src/cr-sel-eng.c +++ b/src/cr-sel-eng.c @@ -144,11 +144,12 @@ lang_pseudo_class_handler (CRSelEng * a_this, a_sel->content.pseudo->extra->len)) { result = TRUE; } + if (val) { + xmlFree (val); + val = NULL; + } } - if (val) { - xmlFree (val); - val = NULL; - } + return result; } @@ -222,18 +223,22 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) if (xmlHasProp (a_node, "class")) { klass = xmlGetProp (a_node, "class"); - for (cur = klass; *cur; cur++) { - while (cr_utils_is_white_space (*cur) == TRUE && *cur) + for (cur = klass; cur && *cur; cur++) { + while (cur && *cur + && cr_utils_is_white_space (*cur) + == TRUE) cur++; if (!*cur) break; if (!strncmp (cur, a_add_sel->content.class_name->str, a_add_sel->content.class_name->len)) { cur += a_add_sel->content.class_name->len; - if (!*cur + if ((cur && !*cur) || cr_utils_is_white_space (*cur) == TRUE) result = TRUE; } + if (cur && !*cur) + break ; } } @@ -1757,14 +1762,16 @@ cr_sel_eng_destroy (CRSelEng * a_this) { g_return_if_fail (a_this); - if (PRIVATE (a_this)) { - g_free (PRIVATE (a_this)); - PRIVATE (a_this) = NULL; + if (!PRIVATE (a_this)) + goto end ; + if (PRIVATE (a_this)->pcs_handlers) { + cr_sel_eng_unregister_all_pseudo_class_sel_handlers + (a_this) ; + PRIVATE (a_this)->pcs_handlers = NULL ; } - /* - *FIXME: - *unregister all the pseudo class sel handlers. - */ + g_free (PRIVATE (a_this)); + PRIVATE (a_this) = NULL; + end: if (a_this) { g_free (a_this); } diff --git a/src/cr-selector.c b/src/cr-selector.c index 7444969..498efc5 100644 --- a/src/cr-selector.c +++ b/src/cr-selector.c @@ -56,7 +56,7 @@ cr_selector_parse_from_buf (const guchar * a_char_buf, enum CREncoding a_enc) g_return_val_if_fail (a_char_buf, NULL); - parser = cr_parser_new_from_buf (a_char_buf, strlen (a_char_buf), + parser = cr_parser_new_from_buf ((guchar*)a_char_buf, strlen (a_char_buf), a_enc, FALSE); g_return_val_if_fail (parser, NULL); diff --git a/src/cr-statement.c b/src/cr-statement.c index bf25d71..915a0e6 100644 --- a/src/cr-statement.c +++ b/src/cr-statement.c @@ -3,8 +3,6 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2.1 of the GNU Lesser General Public * License as published by the Free Software Foundation. @@ -18,11 +16,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * + * See COPYRIGHTS files for copyrights information. */ -/* - *$Id$ - */ #include <string.h> #include "cr-statement.h" @@ -35,28 +32,9 @@ #define DECLARATION_INDENT_NB 2 -static void - cr_statement_clear (CRStatement * a_this); - -static void - cr_statement_dump_ruleset (CRStatement * a_this, FILE * a_fp, glong a_indent); - -static void - cr_statement_dump_charset (CRStatement * a_this, FILE * a_fp, - gulong a_indent); +static void cr_statement_clear (CRStatement * a_this); -static void - cr_statement_dump_page (CRStatement * a_this, FILE * a_fp, gulong a_indent); - -static void - cr_statement_dump_media_rule (CRStatement * a_this, FILE * a_fp, - gulong a_indent); - -static void - cr_statement_dump_import_rule (CRStatement * a_this, FILE * a_fp, - gulong a_indent); - -static void +static void parse_font_face_start_font_face_cb (CRDocHandler * a_this) { CRStatement *stmt = NULL; @@ -73,11 +51,13 @@ static void parse_font_face_unrecoverable_error_cb (CRDocHandler * a_this) { CRStatement *stmt = NULL; + CRStatement **stmtptr = NULL; enum CRStatus status = CR_OK; g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + stmtptr = &stmt; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr); if (status != CR_OK) { cr_utils_trace_info ("Couldn't get parsing context. " "This may lead to some memory leaks."); @@ -99,10 +79,12 @@ parse_font_face_property_cb (CRDocHandler * a_this, GString *name = NULL; CRDeclaration *decl = NULL; CRStatement *stmt = NULL; + CRStatement **stmtptr = NULL; g_return_if_fail (a_this && a_name); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + stmtptr = &stmt; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr); g_return_if_fail (status == CR_OK && stmt); g_return_if_fail (stmt->type == AT_FONT_FACE_RULE_STMT); @@ -137,11 +119,13 @@ static void parse_font_face_end_font_face_cb (CRDocHandler * a_this) { CRStatement *result = NULL; + CRStatement **resultptr = NULL; enum CRStatus status = CR_OK; g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & result); + resultptr = &result; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) resultptr); g_return_if_fail (status == CR_OK && result); g_return_if_fail (result->type == AT_FONT_FACE_RULE_STMT); @@ -176,11 +160,13 @@ static void parse_page_unrecoverable_error_cb (CRDocHandler * a_this) { CRStatement *stmt = NULL; + CRStatement **stmtptr = NULL; enum CRStatus status = CR_OK; g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + stmtptr = &stmt; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr); if (status != CR_OK) { cr_utils_trace_info ("Couldn't get parsing context. " "This may lead to some memory leaks."); @@ -200,10 +186,12 @@ parse_page_property_cb (CRDocHandler * a_this, { GString *name = NULL; CRStatement *stmt = NULL; + CRStatement **stmtptr = NULL; CRDeclaration *decl = NULL; enum CRStatus status = CR_OK; - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + stmtptr = &stmt; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr); g_return_if_fail (status == CR_OK && stmt->type == AT_PAGE_RULE_STMT); name = g_string_new_len (a_name->str, a_name->len); @@ -223,8 +211,10 @@ parse_page_end_page_cb (CRDocHandler * a_this, { enum CRStatus status = CR_OK; CRStatement *stmt = NULL; + CRStatement **stmtptr = NULL; - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + stmtptr = &stmt; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr); g_return_if_fail (status == CR_OK && stmt); g_return_if_fail (stmt->type == AT_PAGE_RULE_STMT); @@ -262,10 +252,12 @@ parse_at_media_unrecoverable_error_cb (CRDocHandler * a_this) { enum CRStatus status = CR_OK; CRStatement *stmt = NULL; + CRStatement **stmtptr = NULL; g_return_if_fail (a_this); - status = cr_doc_handler_get_result (a_this, (gpointer *) & stmt); + stmtptr = &stmt; + status = cr_doc_handler_get_result (a_this, (gpointer *) stmtptr); if (status != CR_OK) { cr_utils_trace_info ("Couldn't get parsing context. " "This may lead to some memory leaks."); @@ -284,12 +276,14 @@ parse_at_media_start_selector_cb (CRDocHandler * a_this, CRSelector * a_sellist) { enum CRStatus status = CR_OK; - CRStatement *at_media = NULL, - *ruleset = NULL; + CRStatement *at_media = NULL; + CRStatement **at_media_ptr = NULL; + CRStatement *ruleset = NULL; g_return_if_fail (a_this && a_this->priv && a_sellist); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & at_media); + at_media_ptr = &at_media; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) at_media_ptr); g_return_if_fail (status == CR_OK && at_media); g_return_if_fail (at_media->type == AT_MEDIA_RULE_STMT); ruleset = cr_statement_new_ruleset (NULL, a_sellist, NULL, at_media); @@ -310,6 +304,7 @@ parse_at_media_property_cb (CRDocHandler * a_this, *current at-media being parsed. */ CRStatement *stmt = NULL; + CRStatement **stmtptr = NULL; CRDeclaration *decl = NULL; GString *name = NULL; @@ -318,7 +313,8 @@ parse_at_media_property_cb (CRDocHandler * a_this, name = g_string_new_len (a_name->str, a_name->len); g_return_if_fail (name); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + stmtptr = &stmt; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr); g_return_if_fail (status == CR_OK && stmt); g_return_if_fail (stmt->type == RULESET_STMT); @@ -339,10 +335,12 @@ parse_at_media_end_selector_cb (CRDocHandler * a_this, CRSelector * a_sellist) *current at-media being parsed. */ CRStatement *stmt = NULL; + CRStatement **stmtptr = NULL; g_return_if_fail (a_this && a_sellist); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + stmtptr = &stmt; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr); g_return_if_fail (status == CR_OK && stmt && stmt->type == RULESET_STMT); g_return_if_fail (stmt->kind.ruleset->parent_media_rule); @@ -357,10 +355,12 @@ parse_at_media_end_media_cb (CRDocHandler * a_this, GList * a_media_list) { enum CRStatus status = CR_OK; CRStatement *at_media = NULL; + CRStatement **at_media_ptr = NULL; g_return_if_fail (a_this && a_this->priv); - status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & at_media); + at_media_ptr = &at_media; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) at_media_ptr); g_return_if_fail (status == CR_OK && at_media); status = cr_doc_handler_set_result (a_this, at_media); @@ -384,9 +384,11 @@ static void parse_ruleset_unrecoverable_error_cb (CRDocHandler * a_this) { CRStatement *stmt = NULL; + CRStatement **stmtptr = NULL; enum CRStatus status = CR_OK; - status = cr_doc_handler_get_result (a_this, (gpointer *) & stmt); + stmtptr = &stmt; + status = cr_doc_handler_get_result (a_this, (gpointer *) stmtptr); if (status != CR_OK) { cr_utils_trace_info ("Couldn't get parsing context. " "This may lead to some memory leaks."); @@ -406,6 +408,7 @@ parse_ruleset_property_cb (CRDocHandler * a_this, { enum CRStatus status = CR_OK; CRStatement *ruleset = NULL; + CRStatement **rulesetptr = NULL; CRDeclaration *decl = NULL; GString *stringue = NULL; @@ -414,7 +417,8 @@ parse_ruleset_property_cb (CRDocHandler * a_this, stringue = g_string_new (a_name->str); g_return_if_fail (stringue); - status = cr_doc_handler_get_result (a_this, (gpointer *) & ruleset); + rulesetptr = &ruleset; + status = cr_doc_handler_get_result (a_this, (gpointer *) rulesetptr); g_return_if_fail (status == CR_OK && ruleset && ruleset->type == RULESET_STMT); @@ -429,11 +433,13 @@ static void parse_ruleset_end_selector_cb (CRDocHandler * a_this, CRSelector * a_sellist) { CRStatement *result = NULL; + CRStatement **resultptr = NULL; enum CRStatus status = CR_OK; g_return_if_fail (a_this && a_sellist); - status = cr_doc_handler_get_result (a_this, (gpointer *) & result); + resultptr = &result; + status = cr_doc_handler_get_result (a_this, (gpointer *) resultptr); g_return_if_fail (status == CR_OK && result && result->type == RULESET_STMT); @@ -585,18 +591,11 @@ cr_statement_ruleset_to_string (CRStatement * a_this, glong a_indent) tmp_str = NULL; } } - + g_string_append_printf (stringue, " {\n"); if (a_this->kind.ruleset->decl_list) { - g_string_append_printf (stringue, " {\n"); - tmp_str = cr_declaration_list_to_string2 (a_this->kind.ruleset->decl_list, a_indent + DECLARATION_INDENT_NB, TRUE); - /* - cr_declaration_dump (a_this->kind.ruleset->decl_list, - a_fp, a_indent + DECLARATION_INDENT_NB, - TRUE) ; - */ if (tmp_str) { g_string_append_printf (stringue, "%s", tmp_str); g_free (tmp_str); @@ -604,9 +603,8 @@ cr_statement_ruleset_to_string (CRStatement * a_this, glong a_indent) } g_string_append_printf (stringue, "%s", "\n"); cr_utils_dump_n_chars2 (' ', stringue, a_indent); - g_string_append_printf (stringue, "%s", "}"); } - + g_string_append_printf (stringue, "%s", "}"); result = stringue->str; if (stringue) { @@ -620,82 +618,93 @@ cr_statement_ruleset_to_string (CRStatement * a_this, glong a_indent) return result; } -/** - *Dumps a ruleset statement to a file. - *@param a_this the current instance of #CRStatement. - *@param a_fp the destination file pointer. - *@param a_indent the number of indentation white spaces to add. - */ -static void -cr_statement_dump_ruleset (CRStatement * a_this, FILE * a_fp, glong a_indent) -{ - guchar *str = NULL; - - g_return_if_fail (a_fp && a_this); - str = cr_statement_ruleset_to_string (a_this, a_indent); - if (str) { - fprintf (a_fp, str); - g_free (str); - str = NULL; - } -} /** - *TODO: write cr_statement_font_face_rule_to_string() - *and make this function use it. - *Dumps a font face rule statement to a file. - *@param a_this the current instance of font face rule statement. - *@param a_fp the destination file pointer. - *@param a_indent the number of white space indentation. + *Serializes a font face rule statement into a string. + *@param a_this the current instance of #CRStatement to consider + *It must be a font face rule statement. + *@param a_indent the number of white spaces of indentation. + *@return the serialized string. Must be deallocated by the caller + *using g_free(). */ -static void -cr_statement_dump_font_face_rule (CRStatement * a_this, FILE * a_fp, - glong a_indent) +static gchar * +cr_statement_font_face_rule_to_string (CRStatement * a_this, + glong a_indent) { - g_return_if_fail (a_this && a_this->type == AT_FONT_FACE_RULE_STMT); + gchar *result = NULL, *tmp_str = NULL ; + GString *stringue = NULL ; - if (a_this->kind.font_face_rule->decl_list) { - cr_utils_dump_n_chars (' ', a_fp, a_indent); + g_return_val_if_fail (a_this + && a_this->type == AT_FONT_FACE_RULE_STMT, + NULL); + if (a_this->kind.font_face_rule->decl_list) { + stringue = g_string_new (NULL) ; + g_return_val_if_fail (stringue, NULL) ; if (a_indent) - cr_utils_dump_n_chars (' ', a_fp, a_indent); - - fprintf (a_fp, "@font-face {\n"); - cr_declaration_dump + cr_utils_dump_n_chars2 (' ', stringue, + a_indent); + g_string_append_printf (stringue, "@font-face {\n"); + tmp_str = cr_declaration_list_to_string2 (a_this->kind.font_face_rule->decl_list, - a_fp, a_indent + DECLARATION_INDENT_NB, TRUE); - fprintf (a_fp, "\n}"); + a_indent + DECLARATION_INDENT_NB, TRUE) ; + if (tmp_str) { + g_string_append_printf (stringue, "%s" + ,tmp_str) ; + g_free (tmp_str) ; + tmp_str = NULL ; + } + g_string_append_printf (stringue, "\n}"); } + if (stringue) { + result = stringue->str ; + g_string_free (stringue, FALSE) ; + stringue = NULL ; + } + return result ; } + /** - *Dumps an @charset rule statement to a file. - *@param a_this the current instance of the @charset rule statement. - *@param a_fp the destination file pointer. - *@param a_indent the number of indentation white spaces. + *Serialises an @charset statement into a string. + *@param a_this the statement to serialize. + *@return the serialized charset statement. Must be + *freed by the caller using g_free(). */ -static void -cr_statement_dump_charset (CRStatement * a_this, FILE * a_fp, gulong a_indent) +static gchar * +cr_statement_charset_to_string (CRStatement *a_this, + gulong a_indent) { - guchar *str = NULL; + gchar *str = NULL ; + GString *stringue = NULL ; - g_return_if_fail (a_this && a_this->type == AT_CHARSET_RULE_STMT); + g_return_val_if_fail (a_this + && a_this->type == AT_CHARSET_RULE_STMT, + NULL) ; - if (a_this->kind.charset_rule && a_this->kind.charset_rule->charset) { + if (a_this->kind.charset_rule + && a_this->kind.charset_rule->charset) { str = g_strndup (a_this->kind.charset_rule->charset->str, a_this->kind.charset_rule->charset->len); - - g_return_if_fail (str); - - cr_utils_dump_n_chars (' ', a_fp, a_indent); - fprintf (a_fp, "@charset \"%s\" ;", str); + g_return_val_if_fail (str, NULL); + stringue = g_string_new (NULL) ; + g_return_val_if_fail (stringue, NULL) ; + cr_utils_dump_n_chars2 (' ', stringue, a_indent); + g_string_append_printf (stringue, + "@charset \"%s\" ;", str); if (str) { g_free (str); str = NULL; } } + if (stringue) { + str = stringue->str ; + g_string_free (stringue, FALSE) ; + } + return str ; } + /** *Serialises the at page rule statement into a string *@param a_this the current instance of #CRStatement. Must @@ -745,86 +754,30 @@ cr_statement_at_page_rule_to_string (CRStatement *a_this, return result ; } -/** - *Dumps an @page rule statement on stdout. - *@param a_this the statement to dump on stdout. - *@param a_fp the destination file pointer. - *@param a_indent the number of indentation white spaces. - */ -static void -cr_statement_dump_page (CRStatement * a_this, FILE * a_fp, gulong a_indent) -{ - guchar *str = NULL; - - g_return_if_fail (a_this - && a_this->type == AT_PAGE_RULE_STMT - && a_this->kind.page_rule); - - str = cr_statement_at_page_rule_to_string (a_this, a_indent) ; - if (str) { - fprintf (a_fp, str); - g_free (str) ; - str = NULL ; - } -} - - -/** - *Return the number of rules in the statement list; - *@param a_this the current instance of #CRStatement. - *@return number of rules in the statement list. - */ -int -cr_statement_nr_rules (CRStatement * a_this) -{ - CRStatement *cur = NULL; - int nr = 0; - - g_return_val_if_fail (a_this, -1); - - for (cur = a_this; cur; cur = cur->next) - nr++; - return nr; -} - -/** - *Use an index to get a CRStatement from the statement list. - *@param a_this the current instance of #CRStatement. - *@param itemnr the index into the statement list. - *@return CRStatement at position itemnr, if itemnr > number of statements - 1, - *it will return NULL. - */ -CRStatement * -cr_statement_get_from_list (CRStatement * a_this, int itemnr) -{ - CRStatement *cur = NULL; - int nr = 0; - - g_return_val_if_fail (a_this, NULL); - - for (cur = a_this; cur; cur = cur->next) - if (nr++ == itemnr) - return cur; - return NULL; -} /** - *Dumps an @media rule statement to a file. - *@param a_this the statement to dump. - *@param a_fp the destination file pointer - *@param a_indent the number of white spaces indentation. + *Serializes an @media statement. + *@param a_this the current instance of #CRStatement + *@param a_indent the number of spaces of indentation. + *@return the serialized @media statement. Must be freed + *by the caller using g_free(). */ -static void -cr_statement_dump_media_rule (CRStatement * a_this, FILE * a_fp, - gulong a_indent) +static gchar * +cr_statement_media_rule_to_string (CRStatement *a_this, + gulong a_indent) { + gchar *str = NULL ; + GString *stringue = NULL ; GList *cur = NULL; - g_return_if_fail (a_this->type == AT_MEDIA_RULE_STMT); + g_return_val_if_fail (a_this->type == AT_MEDIA_RULE_STMT, + NULL); if (a_this->kind.media_rule) { - cr_utils_dump_n_chars (' ', a_fp, a_indent); - fprintf (a_fp, "@media"); + stringue = g_string_new (NULL) ; + cr_utils_dump_n_chars2 (' ', stringue, a_indent); + g_string_append (stringue, "@media"); + for (cur = a_this->kind.media_rule->media_list; cur; cur = cur->next) { if (cur->data) { @@ -834,46 +787,63 @@ cr_statement_dump_media_rule (CRStatement * a_this, FILE * a_fp, if (str) { if (cur->prev) { - fprintf (a_fp, ","); + g_string_append + (stringue, + ","); } - fprintf (a_fp, " %s", str); + g_string_append_printf + (stringue, + " %s", str); g_free (str); str = NULL; } } } - fprintf (a_fp, " {\n"); - cr_statement_dump (a_this->kind.media_rule->rulesets, - a_fp, a_indent + DECLARATION_INDENT_NB); - fprintf (a_fp, "\n}"); + g_string_append (stringue, " {\n"); + str = cr_statement_to_string + (a_this->kind.media_rule->rulesets, + a_indent + DECLARATION_INDENT_NB) ; + if (str) { + g_string_append (stringue, str) ; + g_free (str) ; + str = NULL ; + } + g_string_append (stringue, "\n}"); + } + if (stringue) { + str = stringue->str ; + g_string_free (stringue, FALSE) ; } + return str ; } -/** - *Dumps an @import rule statement to a file. - *@param a_fp the destination file pointer. - *@param a_indent the number of white space indentations. - */ -static void -cr_statement_dump_import_rule (CRStatement * a_this, FILE * a_fp, - gulong a_indent) + +static gchar * +cr_statement_import_rule_to_string (CRStatement *a_this, + gulong a_indent) { - g_return_if_fail (a_this - && a_this->type == AT_IMPORT_RULE_STMT - && a_this->kind.import_rule); + GString *stringue = NULL ; + guchar *str = NULL; - if (a_this->kind.import_rule->url) { - guchar *str = NULL; + g_return_val_if_fail (a_this + && a_this->type == AT_IMPORT_RULE_STMT + && a_this->kind.import_rule, + NULL) ; + if (a_this->kind.import_rule->url) { + stringue = g_string_new (NULL) ; + g_return_val_if_fail (stringue, NULL) ; str = g_strndup (a_this->kind.import_rule->url->str, a_this->kind.import_rule->url->len); - cr_utils_dump_n_chars (' ', a_fp, a_indent); - + cr_utils_dump_n_chars2 (' ', stringue, a_indent); if (str) { - fprintf (a_fp, "@import url(\"%s\")", str); + g_string_append_printf (stringue, + "@import url(\"%s\")", + str); g_free (str); + str = NULL ; } else /*there is no url, so no import rule, get out! */ - return; + return NULL; if (a_this->kind.import_rule->media_list) { GList *cur = NULL; @@ -884,22 +854,27 @@ cr_statement_dump_import_rule (CRStatement * a_this, FILE * a_fp, GString *gstr = cur->data; if (cur->prev) { - fprintf (a_fp, ", "); - } - - str = g_strndup (gstr->str, - gstr->len); - if (str) { - fprintf (a_fp, str); - g_free (str); + g_string_append + (stringue, ", "); } + g_string_append_len + (stringue, + gstr->str, + gstr->len) ; } } } - fprintf (a_fp, " ;"); + g_string_append (stringue, " ;"); } + if (stringue) { + str = stringue->str ; + g_string_free (stringue, FALSE) ; + stringue = NULL ; + } + return str ; } + /******************* *public functions ******************/ @@ -920,7 +895,7 @@ cr_statement_does_buf_parses_against_core (const guchar * a_buf, enum CRStatus status = CR_OK; gboolean result = FALSE; - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen (a_buf), a_encoding, FALSE); g_return_val_if_fail (parser, FALSE); @@ -1026,12 +1001,14 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf, { enum CRStatus status = CR_OK; CRStatement *result = NULL; + CRStatement **resultptr = NULL; CRParser *parser = NULL; CRDocHandler *sac_handler = NULL; g_return_val_if_fail (a_buf, NULL); - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), a_enc, FALSE); + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen (a_buf), + a_enc, FALSE); g_return_val_if_fail (parser, NULL); @@ -1051,8 +1028,9 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf, goto cleanup; } + resultptr = &result; status = cr_doc_handler_get_result (sac_handler, - (gpointer *) & result); + (gpointer *) resultptr); if (!((status == CR_OK) && result)) { if (result) { cr_statement_destroy (result); @@ -1064,6 +1042,7 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf, if (parser) { cr_parser_destroy (parser); parser = NULL; + sac_handler = NULL ; } if (sac_handler) { cr_doc_handler_unref (sac_handler); @@ -1153,10 +1132,12 @@ cr_statement_at_media_rule_parse_from_buf (const guchar * a_buf, { CRParser *parser = NULL; CRStatement *result = NULL; + CRStatement **resultptr = NULL; CRDocHandler *sac_handler = NULL; enum CRStatus status = CR_OK; - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), a_enc, FALSE); + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen (a_buf), + a_enc, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of the parser failed"); goto cleanup; @@ -1189,8 +1170,9 @@ cr_statement_at_media_rule_parse_from_buf (const guchar * a_buf, if (status != CR_OK) goto cleanup; + resultptr = &result; status = cr_doc_handler_get_result (sac_handler, - (gpointer *) & result); + (gpointer *) resultptr); if (status != CR_OK) goto cleanup; @@ -1199,6 +1181,7 @@ cr_statement_at_media_rule_parse_from_buf (const guchar * a_buf, if (parser) { cr_parser_destroy (parser); parser = NULL; + sac_handler = NULL ; } if (sac_handler) { cr_doc_handler_unref (sac_handler); @@ -1326,7 +1309,7 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf, GList *media_list = NULL; GString *import_string = NULL; - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen (a_buf), a_encoding, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of parser failed."); @@ -1438,10 +1421,11 @@ cr_statement_at_page_rule_parse_from_buf (const guchar * a_buf, CRParser *parser = NULL; CRDocHandler *sac_handler = NULL; CRStatement *result = NULL; + CRStatement **resultptr = NULL; g_return_val_if_fail (a_buf, NULL); - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen (a_buf), a_encoding, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of the parser failed."); @@ -1472,21 +1456,22 @@ cr_statement_at_page_rule_parse_from_buf (const guchar * a_buf, if (status != CR_OK) goto cleanup; + resultptr = &result; status = cr_doc_handler_get_result (sac_handler, - (gpointer *) & result); + (gpointer *) resultptr); cleanup: if (parser) { cr_parser_destroy (parser); parser = NULL; + sac_handler = NULL ; } if (sac_handler) { cr_doc_handler_unref (sac_handler); sac_handler = NULL; } return result; - } /** @@ -1547,7 +1532,7 @@ cr_statement_at_charset_rule_parse_from_buf (const guchar * a_buf, g_return_val_if_fail (a_buf, NULL); - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen (a_buf), a_encoding, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of the parser failed."); @@ -1630,11 +1615,12 @@ cr_statement_font_face_rule_parse_from_buf (const guchar * a_buf, enum CREncoding a_encoding) { CRStatement *result = NULL; + CRStatement **resultptr = NULL; CRParser *parser = NULL; CRDocHandler *sac_handler = NULL; enum CRStatus status = CR_OK; - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen (a_buf), a_encoding, FALSE); if (!parser) goto cleanup; @@ -1668,8 +1654,9 @@ cr_statement_font_face_rule_parse_from_buf (const guchar * a_buf, if (status != CR_OK) goto cleanup; + resultptr = &result; status = cr_doc_handler_get_result (sac_handler, - (gpointer *) & result); + (gpointer *) resultptr); if (status != CR_OK || !result) goto cleanup; @@ -1677,6 +1664,7 @@ cr_statement_font_face_rule_parse_from_buf (const guchar * a_buf, if (parser) { cr_parser_destroy (parser); parser = NULL; + sac_handler = NULL ; } if (sac_handler) { cr_doc_handler_unref (sac_handler); @@ -1814,6 +1802,45 @@ cr_statement_unlink (CRStatement * a_stmt) } /** + *Return the number of rules in the statement list; + *@param a_this the current instance of #CRStatement. + *@return number of rules in the statement list. + */ +gint +cr_statement_nr_rules (CRStatement * a_this) +{ + CRStatement *cur = NULL; + int nr = 0; + + g_return_val_if_fail (a_this, -1); + + for (cur = a_this; cur; cur = cur->next) + nr++; + return nr; +} + +/** + *Use an index to get a CRStatement from the statement list. + *@param a_this the current instance of #CRStatement. + *@param itemnr the index into the statement list. + *@return CRStatement at position itemnr, if itemnr > number of statements - 1, + *it will return NULL. + */ +CRStatement * +cr_statement_get_from_list (CRStatement * a_this, int itemnr) +{ + CRStatement *cur = NULL; + int nr = 0; + + g_return_val_if_fail (a_this, NULL); + + for (cur = a_this; cur; cur = cur->next) + if (nr++ == itemnr) + return cur; + return NULL; +} + +/** *Sets a selector list to a ruleset statement. *@param a_this the current ruleset statement. *@param a_sel_list the selector list to set. Note @@ -2247,52 +2274,213 @@ cr_statement_at_font_face_rule_add_decl (CRStatement * a_this, } /** - *Dumps the css2 statement to a file. - *@param a_this the current css2 statement. - *@param a_fp the destination file pointer. - *@param a_indent the number of white space indentation characters. + *Serializes a css statement into a string + *@param a_this the current statement to serialize + *@param a_indent the number of white space of indentation. + *@return the serialized statement. Must be freed by the caller + *using g_free(). */ -void -cr_statement_dump (CRStatement * a_this, FILE * a_fp, gulong a_indent) +gchar * +cr_statement_to_string (CRStatement * a_this, gulong a_indent) { + gchar *str = NULL ; if (!a_this) - return; - - if (a_this->prev) { - fprintf (a_fp, "\n\n"); - } + return NULL; switch (a_this->type) { case RULESET_STMT: - cr_statement_dump_ruleset (a_this, a_fp, a_indent); + str = cr_statement_ruleset_to_string + (a_this, a_indent); break; case AT_FONT_FACE_RULE_STMT: - cr_statement_dump_font_face_rule (a_this, a_fp, a_indent); + str = cr_statement_font_face_rule_to_string + (a_this, a_indent) ; break; case AT_CHARSET_RULE_STMT: - cr_statement_dump_charset (a_this, a_fp, a_indent); + str = cr_statement_charset_to_string + (a_this, a_indent); break; case AT_PAGE_RULE_STMT: - cr_statement_dump_page (a_this, a_fp, a_indent); + str = cr_statement_at_page_rule_to_string + (a_this, a_indent); break; case AT_MEDIA_RULE_STMT: - cr_statement_dump_media_rule (a_this, a_fp, a_indent); + str = cr_statement_media_rule_to_string + (a_this, a_indent); break; case AT_IMPORT_RULE_STMT: - cr_statement_dump_import_rule (a_this, a_fp, a_indent); + str = cr_statement_import_rule_to_string + (a_this, a_indent); break; default: - fprintf (a_fp, "Statement unrecognized at %s:%d", - __FILE__, __LINE__); + cr_utils_trace_info ("Statement unrecognized"); break; } + return str ; +} + +/** + *Dumps the css2 statement to a file. + *@param a_this the current css2 statement. + *@param a_fp the destination file pointer. + *@param a_indent the number of white space indentation characters. + */ +void +cr_statement_dump (CRStatement * a_this, FILE * a_fp, gulong a_indent) +{ + gchar *str = NULL ; + + if (!a_this) + return; + + str = cr_statement_to_string (a_this, a_indent) ; + if (str) { + fprintf (a_fp, "%s",str) ; + g_free (str) ; + str = NULL ; + } +} + +/** + *Dumps a ruleset statement to a file. + *@param a_this the current instance of #CRStatement. + *@param a_fp the destination file pointer. + *@param a_indent the number of indentation white spaces to add. + */ +void +cr_statement_dump_ruleset (CRStatement * a_this, FILE * a_fp, glong a_indent) +{ + guchar *str = NULL; + + g_return_if_fail (a_fp && a_this); + str = cr_statement_ruleset_to_string (a_this, a_indent); + if (str) { + fprintf (a_fp, str); + g_free (str); + str = NULL; + } +} + +/** + *Dumps a font face rule statement to a file. + *@param a_this the current instance of font face rule statement. + *@param a_fp the destination file pointer. + *@param a_indent the number of white space indentation. + */ +void +cr_statement_dump_font_face_rule (CRStatement * a_this, FILE * a_fp, + glong a_indent) +{ + gchar *str = NULL ; + g_return_if_fail (a_this + && a_this->type == AT_FONT_FACE_RULE_STMT); + + str = cr_statement_font_face_rule_to_string (a_this, + a_indent) ; + if (str) { + fprintf (a_fp, "%s", str) ; + g_free (str) ; + str = NULL ; + } +} + +/** + *Dumps an @charset rule statement to a file. + *@param a_this the current instance of the @charset rule statement. + *@param a_fp the destination file pointer. + *@param a_indent the number of indentation white spaces. + */ +void +cr_statement_dump_charset (CRStatement * a_this, FILE * a_fp, gulong a_indent) +{ + guchar *str = NULL; + + g_return_if_fail (a_this && a_this->type == AT_CHARSET_RULE_STMT); + + str = cr_statement_charset_to_string (a_this, + a_indent) ; + if (str) { + fprintf (a_fp, str) ; + g_free (str) ; + str = NULL ; + } +} + + +/** + *Dumps an @page rule statement on stdout. + *@param a_this the statement to dump on stdout. + *@param a_fp the destination file pointer. + *@param a_indent the number of indentation white spaces. + */ +void +cr_statement_dump_page (CRStatement * a_this, FILE * a_fp, gulong a_indent) +{ + guchar *str = NULL; + + g_return_if_fail (a_this + && a_this->type == AT_PAGE_RULE_STMT + && a_this->kind.page_rule); + + str = cr_statement_at_page_rule_to_string (a_this, a_indent) ; + if (str) { + fprintf (a_fp, str); + g_free (str) ; + str = NULL ; + } +} + + +/** + *Dumps an @media rule statement to a file. + *@param a_this the statement to dump. + *@param a_fp the destination file pointer + *@param a_indent the number of white spaces indentation. + */ +void +cr_statement_dump_media_rule (CRStatement * a_this, + FILE * a_fp, + gulong a_indent) +{ + gchar *str = NULL ; + g_return_if_fail (a_this->type == AT_MEDIA_RULE_STMT); + + str = cr_statement_media_rule_to_string (a_this, a_indent) ; + if (str) { + fprintf (a_fp, str) ; + g_free (str) ; + str = NULL ; + } +} + +/** + *Dumps an @import rule statement to a file. + *@param a_fp the destination file pointer. + *@param a_indent the number of white space indentations. + */ +void +cr_statement_dump_import_rule (CRStatement * a_this, FILE * a_fp, + gulong a_indent) +{ + gchar *str = NULL ; + g_return_if_fail (a_this + && a_this->type == AT_IMPORT_RULE_STMT + && a_fp + && a_this->kind.import_rule); + + str = cr_statement_import_rule_to_string (a_this, a_indent) ; + if (str) { + fprintf (a_fp, str) ; + g_free (str) ; + str = NULL ; + } } /** diff --git a/src/cr-statement.h b/src/cr-statement.h index f393d12..0323dbb 100644 --- a/src/cr-statement.h +++ b/src/cr-statement.h @@ -350,7 +350,7 @@ enum CRStatus cr_statement_at_import_rule_get_url (CRStatement *a_this, GString **a_url) ; -int +gint cr_statement_at_media_nr_rules (CRStatement *a_this) ; CRStatement * @@ -393,10 +393,38 @@ cr_statement_at_font_face_rule_add_decl (CRStatement *a_this, GString *a_prop, CRTerm *a_value) ; +gchar * +cr_statement_to_string (CRStatement * a_this, gulong a_indent) ; + void cr_statement_dump (CRStatement *a_this, FILE *a_fp, gulong a_indent) ; -int +void +cr_statement_dump_ruleset (CRStatement * a_this, FILE * a_fp, + glong a_indent) ; + +void +cr_statement_dump_font_face_rule (CRStatement * a_this, + FILE * a_fp, + glong a_indent) ; + +void +cr_statement_dump_page (CRStatement * a_this, FILE * a_fp, + gulong a_indent) ; + + +void +cr_statement_dump_media_rule (CRStatement * a_this, + FILE * a_fp, + gulong a_indent) ; + +void +cr_statement_dump_import_rule (CRStatement * a_this, FILE * a_fp, + gulong a_indent) ; +void +cr_statement_dump_charset (CRStatement * a_this, FILE * a_fp, + gulong a_indent) ; +gint cr_statement_nr_rules (CRStatement *a_this) ; CRStatement * diff --git a/src/cr-stylesheet.c b/src/cr-stylesheet.c index 3f3665a..ee6e475 100644 --- a/src/cr-stylesheet.c +++ b/src/cr-stylesheet.c @@ -57,6 +57,43 @@ cr_stylesheet_new (CRStatement * a_stmts) } /** + *@param a_this the current instance of #CRStyleSheet + *@return the serialized stylesheet. + */ +gchar * +cr_stylesheet_to_string (CRStyleSheet *a_this) +{ + gchar *str = NULL; + GString *stringue = NULL; + CRStatement *cur_stmt = NULL; + + g_return_val_if_fail (a_this, NULL); + + if (a_this->statements) { + stringue = g_string_new (NULL) ; + g_return_val_if_fail (stringue, NULL) ; + } + for (cur_stmt = a_this->statements; + cur_stmt; cur_stmt = cur_stmt->next) { + if (cur_stmt->prev) { + g_string_append (stringue, "\n\n") ; + } + str = cr_statement_to_string (cur_stmt, 0) ; + if (str) { + g_string_append (stringue, str) ; + g_free (str) ; + str = NULL ; + } + } + if (stringue) { + str = stringue->str ; + g_string_free (stringue, FALSE) ; + stringue = NULL ; + } + return str ; +} + +/** *Dumps the current css2 stylesheet to a file. *@param a_this the current instance of #CRStyleSheet. *@param a_fp the destination file @@ -64,14 +101,16 @@ cr_stylesheet_new (CRStatement * a_stmts) void cr_stylesheet_dump (CRStyleSheet * a_this, FILE * a_fp) { - CRStatement *cur_stmt = NULL; + gchar *str = NULL ; g_return_if_fail (a_this); - for (cur_stmt = a_this->statements; - cur_stmt; cur_stmt = cur_stmt->next) { - cr_statement_dump (cur_stmt, a_fp, 0); - } + str = cr_stylesheet_to_string (a_this) ; + if (str) { + fprintf (a_fp, str) ; + g_free (str) ; + str = NULL ; + } } /** diff --git a/src/cr-stylesheet.h b/src/cr-stylesheet.h index 0209311..3766a28 100644 --- a/src/cr-stylesheet.h +++ b/src/cr-stylesheet.h @@ -3,8 +3,6 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2.1 of the GNU Lesser General Public * License as published by the Free Software Foundation. @@ -18,11 +16,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * + * see COPYRIGHTS file for copyright information. */ -/* - *$Id$ - */ #ifndef __CR_STYLESHEET_H__ #define __CR_STYLESHEET_H__ @@ -87,6 +84,7 @@ struct _CRStyleSheet CRStyleSheet * cr_stylesheet_new (CRStatement *a_stmts) ; +gchar * cr_stylesheet_to_string (CRStyleSheet *a_this) ; void cr_stylesheet_dump (CRStyleSheet *a_this, FILE *a_fp) ; gint cr_stylesheet_nr_rules (CRStyleSheet *a_this) ; diff --git a/src/cr-term.c b/src/cr-term.c index 8760f74..9828a3d 100644 --- a/src/cr-term.c +++ b/src/cr-term.c @@ -114,7 +114,7 @@ cr_term_parse_expression_from_buf (const guchar * a_buf, g_return_val_if_fail (a_buf, NULL); - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen (a_buf), a_encoding, FALSE); g_return_val_if_fail (parser, NULL); @@ -500,6 +500,45 @@ cr_term_dump (CRTerm * a_this, FILE * a_fp) } /** + *Return the number of terms in the expression. + *@param a_this the current instance of #CRTerm. + *@return number of terms in the expression. + */ +int +cr_term_nr_values (CRTerm *a_this) +{ + CRTerm *cur = NULL ; + int nr = 0; + + g_return_val_if_fail (a_this, -1) ; + + for (cur = a_this ; cur ; cur = cur->next) + nr ++; + return nr; +} + +/** + *Use an index to get a CRTerm from the expression. + *@param a_this the current instance of #CRTerm. + *@param itemnr the index into the expression. + *@return CRTerm at position itemnr, if itemnr > number of terms - 1, + *it will return NULL. + */ +CRTerm * +cr_term_get_from_list (CRTerm *a_this, int itemnr) +{ + CRTerm *cur = NULL ; + int nr = 0; + + g_return_val_if_fail (a_this, NULL) ; + + for (cur = a_this ; cur ; cur = cur->next) + if (nr++ == itemnr) + return cur; + return NULL; +} + +/** *Increments the reference counter of the current instance *of #CRTerm.* *@param a_this the current instance of #CRTerm. diff --git a/src/cr-term.h b/src/cr-term.h index 89b460c..e203ed9 100644 --- a/src/cr-term.h +++ b/src/cr-term.h @@ -187,6 +187,12 @@ cr_term_to_string (CRTerm *a_this) ; void cr_term_dump (CRTerm *a_this, FILE *a_fp) ; +int +cr_term_nr_values (CRTerm *a_this) ; + +CRTerm * +cr_term_get_from_list (CRTerm *a_this, int itemnr) ; + void cr_term_ref (CRTerm *a_this) ; diff --git a/src/cr-tknzr.c b/src/cr-tknzr.c index 87a46a2..11f85ad 100644 --- a/src/cr-tknzr.c +++ b/src/cr-tknzr.c @@ -765,7 +765,7 @@ cr_tknzr_parse_string (CRTknzr * a_this, GString ** a_str) } /** - *Parses the an nmstart as defined by css spec [4.1.1]: + *Parses the an nmstart as defined by the css2 spec [4.1.1]: * nmstart [a-zA-Z]|{nonascii}|{escape} * *@param a_this the current instance of #CRTknzr. @@ -890,6 +890,8 @@ cr_tknzr_parse_nmchar (CRTknzr * a_this, guint32 * a_char) *Parses an "ident" as defined in css spec [4.1.1]: *ident ::= {nmstart}{nmchar}* * + *Actually parses it using the css3 grammar: + *ident ::= -?{nmstart}{nmchar}* *@param a_this the currens instance of #CRTknzr. * *@param a_str a pointer to parsed ident. If *a_str is NULL, @@ -904,6 +906,7 @@ static enum CRStatus cr_tknzr_parse_ident (CRTknzr * a_this, GString ** a_str) { guint32 tmp_char = 0; + GString *stringue = NULL ; CRInputPos init_pos; enum CRStatus status = CR_OK; @@ -912,90 +915,49 @@ cr_tknzr_parse_ident (CRTknzr * a_this, GString ** a_str) && a_str, CR_BAD_PARAM_ERROR); RECORD_INITIAL_POS (a_this, &init_pos); + PEEK_NEXT_CHAR (a_this, &tmp_char) ; + stringue = g_string_new (NULL) ; + g_return_val_if_fail (stringue, CR_OUT_OF_MEMORY_ERROR) ; - status = cr_tknzr_parse_nmstart (a_this, &tmp_char); - - if (status != CR_OK) - return CR_PARSING_ERROR; - - if (*a_str == NULL) { - *a_str = g_string_new (NULL); - } - - g_string_append_unichar (*a_str, tmp_char); - - for (;;) { - status = cr_tknzr_parse_nmchar (a_this, &tmp_char); - - if (status != CR_OK) - break; - - g_string_append_unichar (*a_str, tmp_char); + if (tmp_char == '-') { + READ_NEXT_CHAR (a_this, &tmp_char) ; + g_string_append_unichar (stringue, tmp_char) ; } - - return CR_OK; -} - -/** - *Parses a "vendor-specific-ident". This is only a dash followed - *by a an identifier. This is not specified by the CSS2 spec but - *is heavily used by a lot of user agents. - *@param a_this the currens instance of #CRTknzr. - * - *@param a_str a pointer to parsed ident. If *a_str is NULL, - *this function allocates a new instance of GString. If not, - *the function just appends the parsed string to the one passed. - *In both cases it is up to the caller to free *a_str. - * - *@return CR_OK upon successfull completion, an error code - *otherwise. - */ -static enum CRStatus -cr_tknzr_parse_vendor_specific_ident (CRTknzr * a_this, GString ** a_str) -{ - guint32 tmp_char = 0; - CRInputPos init_pos; - enum CRStatus status = CR_OK; - - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input - && a_str, CR_BAD_PARAM_ERROR); - - RECORD_INITIAL_POS (a_this, &init_pos); - - if (BYTE (PRIVATE (a_this)->input, 1, NULL) == '-') { - SKIP_BYTES (a_this, 1); - } else { - return CR_PARSING_ERROR; - } - status = cr_tknzr_parse_nmstart (a_this, &tmp_char); if (status != CR_OK) { status = CR_PARSING_ERROR; - goto error; + goto end ; } - if (*a_str == NULL) { - *a_str = g_string_new (NULL); - } - g_string_append_c (*a_str, '-'); - g_string_append_unichar (*a_str, tmp_char); - + g_string_append_unichar (stringue, tmp_char); for (;;) { status = cr_tknzr_parse_nmchar (a_this, &tmp_char); - - if (status != CR_OK) + if (status != CR_OK) { + status = CR_OK ; break; - - g_string_append_unichar (*a_str, tmp_char); + } + g_string_append_unichar (stringue, tmp_char); + } + if (status == CR_OK) { + if (!*a_str) { + *a_str = stringue ; + + } else { + g_string_append_len (*a_str, stringue->str, stringue->len) ; + g_string_free (stringue, TRUE) ; + } + stringue = NULL ; } - return CR_OK; - - error: - cr_tknzr_set_cur_pos (a_this, &init_pos); - return status; + error: + end: + if (stringue) { + g_string_free (stringue, TRUE) ; + stringue = NULL ; + } + return status ; } + /** *Parses a "name" as defined by css spec [4.1.1]: *name ::= {nmchar}+ @@ -1595,8 +1557,9 @@ cr_tknzr_new (CRInput * a_input) } CRTknzr * -cr_tknzr_new_from_buf (const guchar * a_buf, gulong a_len, - enum CREncoding a_enc, gboolean a_free_at_destroy) +cr_tknzr_new_from_buf (guchar * a_buf, gulong a_len, + enum CREncoding a_enc, + gboolean a_free_at_destroy) { CRTknzr *result = NULL; CRInput *input = NULL; @@ -2094,10 +2057,10 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk) CHECK_PARSING_STATUS (status, TRUE); goto done; } else { - status = cr_tknzr_parse_vendor_specific_ident + status = cr_tknzr_parse_ident (a_this, &str); if (status == CR_OK) { - cr_token_set_vendor_specific_ident + cr_token_set_ident (token, str); goto done; } @@ -2132,6 +2095,7 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk) goto done; } } + break ; case ';': SKIP_CHARS (a_this, 1); @@ -2496,7 +2460,6 @@ cr_tknzr_parse_token (CRTknzr * a_this, enum CRTokenType a_type, case STRING_TK: case IDENT_TK: - case VENDOR_SPECIFIC_IDENT_TK: case HASH_TK: case ATKEYWORD_TK: case FUNCTION_TK: diff --git a/src/cr-tknzr.h b/src/cr-tknzr.h index 3a7765c..4e3d849 100644 --- a/src/cr-tknzr.h +++ b/src/cr-tknzr.h @@ -3,8 +3,6 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2.1 of the GNU Lesser General Public * License as published by the Free Software Foundation. @@ -18,6 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * + * See COPYRIGHTS file for coypyright information. */ /* @@ -63,7 +63,7 @@ cr_tknzr_new_from_uri (const guchar *a_file_uri, enum CREncoding a_enc) ; CRTknzr * -cr_tknzr_new_from_buf (const guchar *a_buf, gulong a_len, +cr_tknzr_new_from_buf (guchar *a_buf, gulong a_len, enum CREncoding a_enc, gboolean a_free_at_destroy) ; diff --git a/src/cr-token.c b/src/cr-token.c index 8988e8b..7eaa218 100644 --- a/src/cr-token.c +++ b/src/cr-token.c @@ -53,6 +53,13 @@ cr_token_clear (CRToken * a_this) case CHARSET_SYM_TK: case IMPORT_SYM_TK: case IMPORTANT_SYM_TK: + case SEMICOLON_TK: + case NO_TK: + case DELIM_TK: + case CBO_TK: + case CBC_TK: + case BO_TK: + case BC_TK: break; case STRING_TK: @@ -61,7 +68,7 @@ cr_token_clear (CRToken * a_this) case URI_TK: case FUNCTION_TK: case COMMENT_TK: - case VENDOR_SPECIFIC_IDENT_TK: + case ATKEYWORD_TK: if (a_this->u.str) { g_string_free (a_this->u.str, TRUE); a_this->u.str = NULL; @@ -76,6 +83,8 @@ cr_token_clear (CRToken * a_this) case FREQ_TK: case PERCENTAGE_TK: case NUMBER_TK: + case PO_TK: + case PC_TK: if (a_this->u.num) { cr_num_destroy (a_this->u.num); a_this->u.num = NULL; @@ -95,11 +104,19 @@ cr_token_clear (CRToken * a_this) break; + case RGB_TK: + if (a_this->u.rgb) { + cr_rgb_destroy (a_this->u.rgb) ; + a_this->u.rgb = NULL ; + } + break ; + case UNICODERANGE_TK: /*not supported yet. */ break; default: + cr_utils_trace_info ("I don't know how to clear this token\n") ; break; } @@ -265,18 +282,6 @@ cr_token_set_ident (CRToken * a_this, GString * a_ident) return CR_OK; } -enum CRStatus -cr_token_set_vendor_specific_ident (CRToken * a_this, GString * a_ident) -{ - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - - cr_token_clear (a_this); - - a_this->type = VENDOR_SPECIFIC_IDENT_TK; - - a_this->u.str = a_ident; - return CR_OK; -} enum CRStatus cr_token_set_function (CRToken * a_this, GString * a_fun_name) diff --git a/src/cr-token.h b/src/cr-token.h index 3e2f907..8eb7624 100644 --- a/src/cr-token.h +++ b/src/cr-token.h @@ -73,8 +73,7 @@ enum CRTokenType PC_TK, /*closing parenthesis*/ BO_TK, /*opening bracket*/ BC_TK, /*closing bracket*/ - DELIM_TK, - VENDOR_SPECIFIC_IDENT_TK + DELIM_TK } ; enum CRTokenExtraType @@ -145,9 +144,6 @@ enum CRStatus cr_token_set_ident (CRToken *a_this, GString * a_ident) ; enum CRStatus -cr_token_set_vendor_specific_ident (CRToken *a_this, GString * a_ident) ; - -enum CRStatus cr_token_set_hash (CRToken *a_this, GString *a_hash) ; enum CRStatus diff --git a/src/cr-utils.c b/src/cr-utils.c index e4036a2..daceb9b 100644 --- a/src/cr-utils.c +++ b/src/cr-utils.c @@ -897,8 +897,15 @@ cr_utils_ucs1_to_utf8 (const guchar * a_in, out_len = 0; enum CRStatus status = CR_OK; - g_return_val_if_fail (a_in && a_in_len && a_out - && a_out_len, CR_BAD_PARAM_ERROR); + g_return_val_if_fail (a_in && a_in_len + && a_out_len, + CR_BAD_PARAM_ERROR); + + if (*a_in_len == 0) { + *a_out_len = 0 ; + return CR_OK ; + } + g_return_val_if_fail (a_out, CR_BAD_PARAM_ERROR) ; if (*a_in_len < 1) { status = CR_OK; diff --git a/src/libcroco-config.h b/src/libcroco-config.h index f16cc00..504ed26 100644 --- a/src/libcroco-config.h +++ b/src/libcroco-config.h @@ -1,9 +1,9 @@ #ifndef LIBCROCO_VERSION_NUMBER -#define LIBCROCO_VERSION_NUMBER 400 +#define LIBCROCO_VERSION_NUMBER 500 #endif #ifndef LIBCROCO_VERSION -#define LIBCROCO_VERSION "0.4.0" +#define LIBCROCO_VERSION "0.5.0" #endif #ifndef G_DISABLE_CHECKS diff --git a/tests/Makefile.am b/tests/Makefile.am index e17e2fa..3f5ecfe 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,8 @@ SUBDIRS=test-inputs test-output-refs +EXTRA_DIST=testctl vg.supp global-vars.sh\ +test-prop-ident.sh \ +test-unknown-at-rule.sh \ +test-unknown-at-rule2.sh #the list of all possible tests goes here. diff --git a/tests/global-vars.sh b/tests/global-vars.sh new file mode 100644 index 0000000..2fc8473 --- /dev/null +++ b/tests/global-vars.sh @@ -0,0 +1,10 @@ +TEST_INPUTS_DIR=$HERE_DIR/test-inputs +CSSLINT=$HERE_DIR/../csslint/.libs/csslint +if ! test -x $CSSLINT ; then + echo "Aarg Could not find an executable csslint. I was looking for $CSSLINT" + echo $ +fi + +if ! test x"$VALGRIND" = x ; then + CSSLINT="$VALGRIND $CSSLINT" +fi diff --git a/tests/test-inputs/Makefile.am b/tests/test-inputs/Makefile.am index 62d0338..53ee855 100644 --- a/tests/test-inputs/Makefile.am +++ b/tests/test-inputs/Makefile.am @@ -1,11 +1,14 @@ -EXTRA_DIST=test0.1.css \ -test1.css \ +EXTRA_DIST= prop-vendor-ident.css \ +test0.1.css \ +test1.css \ test2.1.css \ test2.2.css \ -test2.css \ +test2.css \ test3.1.css \ test3.2.css \ -test3.css \ +test3.css \ test4.1.css \ test4.2.css \ -test5.1.css +test5.1.css \ +unknown-at-rule2.css \ +unknown-at-rule.css diff --git a/tests/test-inputs/prop-vendor-ident.css b/tests/test-inputs/prop-vendor-ident.css new file mode 100644 index 0000000..f7aa8b5 --- /dev/null +++ b/tests/test-inputs/prop-vendor-ident.css @@ -0,0 +1,3 @@ +:-foo-pseudo { + -foo-bar-prop: -foobar-value +} diff --git a/tests/test-inputs/unknown-at-rule.css b/tests/test-inputs/unknown-at-rule.css new file mode 100644 index 0000000..7680999 --- /dev/null +++ b/tests/test-inputs/unknown-at-rule.css @@ -0,0 +1,3 @@ +@namespace url(http://www.w3.org/1999/xhtml); /* set default namespace +to +HTML */
\ No newline at end of file diff --git a/tests/test-inputs/unknown-at-rule2.css b/tests/test-inputs/unknown-at-rule2.css new file mode 100644 index 0000000..0c4a191 --- /dev/null +++ b/tests/test-inputs/unknown-at-rule2.css @@ -0,0 +1,3 @@ +@namespace url(http://www.w3.org/1999/xhtml); dummyrule { } /* set +default +namespace to HTML */
\ No newline at end of file diff --git a/tests/test-output-refs/Makefile.am b/tests/test-output-refs/Makefile.am index 9e678b5..0b1b528 100644 --- a/tests/test-output-refs/Makefile.am +++ b/tests/test-output-refs/Makefile.am @@ -1,13 +1,15 @@ EXTRA_DIST=test0.1.css.out \ -test1.css.out \ -test2.1.css.out \ -test2.2.css.out \ -test2.css.out \ -test3.1.css.out \ -test3.2.css.out \ -test3.css.out \ -test4.1.css.out \ -test4.2.css.out \ -test5.1.css.out \ -test6.out \ -test7.out
\ No newline at end of file +test1.css.out \ +test2.1.css.out \ +test2.2.css.out \ +test2.css.out \ +test3.1.css.out \ +test3.2.css.out \ +test3.css.out \ +test4.1.css.out \ +test4.2.css.out \ +test6.out \ +test-prop-ident.out \ +test-unknown-at-rule.out \ +test-unknown-at-rule2.out \ +test5.1.css.out diff --git a/tests/test-output-refs/test-prop-ident.out b/tests/test-output-refs/test-prop-ident.out new file mode 100644 index 0000000..149e8f5 --- /dev/null +++ b/tests/test-output-refs/test-prop-ident.out @@ -0,0 +1,3 @@ +:-foo-pseudo { + -foo-bar-prop : -foobar-value +} diff --git a/tests/test-output-refs/test-unknown-at-rule.out b/tests/test-output-refs/test-unknown-at-rule.out new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/test-output-refs/test-unknown-at-rule.out @@ -0,0 +1 @@ + diff --git a/tests/test-output-refs/test-unknown-at-rule2.out b/tests/test-output-refs/test-unknown-at-rule2.out new file mode 100644 index 0000000..a356a7d --- /dev/null +++ b/tests/test-output-refs/test-unknown-at-rule2.out @@ -0,0 +1,2 @@ +dummyrule { +} diff --git a/tests/test-output-refs/test5.1.css.out b/tests/test-output-refs/test5.1.css.out index 75b17d0..2f0bc54 100644 --- a/tests/test-output-refs/test5.1.css.out +++ b/tests/test-output-refs/test5.1.css.out @@ -1,8 +1,6 @@ ''''''''''''''''''''''''' xml start element: document - - :first-child { first-child-prop : first-child-value } @@ -12,13 +10,9 @@ xml end element: document ''''''''''''''''''''''''' xml start element: E0 - - :first-child { first-child-prop : first-child-value } - - E0 { prop0 : val0 } @@ -28,8 +22,6 @@ xml end element: E0 ''''''''''''''''''''''''' xml start element: E1 - - E0+E1 { pro1 : val1 } @@ -39,23 +31,15 @@ xml end element: E1 ''''''''''''''''''''''''' xml start element: E1-1 - - :first-child { first-child-prop : first-child-value } - - E1 E1-1 { prop2 : val2 } - - E1>E1-1 { prop3 : val3 } - - document E1-1 { prop4 : val4 } @@ -65,13 +49,9 @@ xml end element: E1-1 ''''''''''''''''''''''''' xml start element: E2 - - [attr2="val2"] { prop5 : val5 } - - E2[attr2="val2"] { prop8 : val8 } @@ -81,8 +61,6 @@ xml end element: E2 ''''''''''''''''''''''''' xml start element: E3 - - [attr3~="val3_2"] { prop6 : val6 } @@ -92,8 +70,6 @@ xml end element: E3 ''''''''''''''''''''''''' xml start element: E4 - - [attr4|="val4"] { prop7 : val7 } @@ -112,8 +88,6 @@ xml end element: E5 ''''''''''''''''''''''''' xml start element: E6 - - #id6 { prop9 : val9 } @@ -123,8 +97,6 @@ xml end element: E6 ''''''''''''''''''''''''' xml start element: E7 - - :lang(fr) { lang-prop : lang-value } diff --git a/tests/test-prop-ident.sh b/tests/test-prop-ident.sh new file mode 100755 index 0000000..e07005d --- /dev/null +++ b/tests/test-prop-ident.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +HERE_DIR=`dirname $0` +. $HERE_DIR/global-vars.sh + +$CSSLINT $TEST_INPUTS_DIR/prop-vendor-ident.css diff --git a/tests/test-unknown-at-rule.sh b/tests/test-unknown-at-rule.sh new file mode 100755 index 0000000..a9de6c8 --- /dev/null +++ b/tests/test-unknown-at-rule.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +HERE_DIR=`dirname $0` +. $HERE_DIR/global-vars.sh + +$CSSLINT $TEST_INPUTS_DIR/unknown-at-rule.css diff --git a/tests/test-unknown-at-rule2.sh b/tests/test-unknown-at-rule2.sh new file mode 100755 index 0000000..8b421ad --- /dev/null +++ b/tests/test-unknown-at-rule2.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +HERE_DIR=`dirname $0` +. $HERE_DIR/global-vars.sh + +$CSSLINT $TEST_INPUTS_DIR/unknown-at-rule2.css diff --git a/tests/test1-main.c b/tests/test1-main.c index 019e6dc..b7e657f 100644 --- a/tests/test1-main.c +++ b/tests/test1-main.c @@ -3,8 +3,6 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2.1 of the GNU Lesser General Public * License as published by the Free Software Foundation. @@ -18,6 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * + * See COPYRIGHTS file for copyright information */ /* diff --git a/tests/test2-main.c b/tests/test2-main.c index d64071c..fc991cd 100644 --- a/tests/test2-main.c +++ b/tests/test2-main.c @@ -3,8 +3,6 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> - * * This program is free software; you can redistribute it and/or * modify it under the terms * of version 2.1 of the GNU Lesser General Public @@ -20,6 +18,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * + * See COPYRIGHTS file for copyright information. */ /* diff --git a/tests/test4-main.c b/tests/test4-main.c index 5880cc5..78501dc 100644 --- a/tests/test4-main.c +++ b/tests/test4-main.c @@ -140,9 +140,9 @@ test_cr_statement_at_page_rule_parse_from_buf (void) stmt = cr_statement_at_page_rule_parse_from_buf (gv_at_page_buf, CR_UTF_8) ; if (!stmt) { - return CR_ERROR ; - + return CR_ERROR ; } + cr_statement_destroy (stmt) ; return CR_OK ; } @@ -237,7 +237,6 @@ test_cr_statement_ruleset_parse (void) cr_statement_destroy (stmt); stmt = NULL; } - return CR_OK; } diff --git a/tests/test5-main.c b/tests/test5-main.c index 59d81aa..1610382 100644 --- a/tests/test5-main.c +++ b/tests/test5-main.c @@ -192,7 +192,10 @@ test_sel_eng (guchar * a_file_uri) cr_stylesheet_destroy (stylesheet); stylesheet = NULL; } - + if (selection_engine) { + cr_sel_eng_destroy (selection_engine) ; + selection_engine = NULL ; + } xmlCleanupParser (); return status; diff --git a/tests/testctl b/tests/testctl index 96a541b..18ec9ed 100755 --- a/tests/testctl +++ b/tests/testctl @@ -27,7 +27,13 @@ TEST_OUTPUT_DIR=test-outputs ERROR_REPORT_FILE=tests-error.log COMMAND_LIST= COMMAND= -RUN_VALGRIND=no +if test x$RUN_VALGRIND = x ; then + RUN_VALGRIND=no +else + RUN_VALGRIND=yes +fi +VALGRIND_LOGS_DIR=valgrind-logs +VALGRIND= TEST_PROG= EGREP=`which egrep` if test "empty$EGREP" = "empty" ; then @@ -53,8 +59,8 @@ display_usage () echo "commands are:" echo "==============" echo "run run the tests and display their result" - echo "mkref run the tests but saves their output as a reference" - echo "mkcleanup removes the tmp directories that may have been created" + echo "ref run the tests but saves their output as a reference" + echo "cleanup removes the tmp directories that may have been created" echo "" echo "run command options:" echo "--valgrind runs the test using valgrind" @@ -87,7 +93,7 @@ parse_command_line () exit 0 ;; - run|mkref|mkcleanup) + run|ref|cleanup) COMMAND_LIST=$arg REMAINING_ARGS=$@ echo "REMAINING_ARGS=$REMAINING_ARGS" @@ -106,8 +112,9 @@ parse_command_line () #builds the list of available test functions. build_tests_list () { - for TEST_PROG in `ls -1 $HERE | egrep ^test\([0-9]\)+$` ; do - echo "$un test: $TEST_PROG" + for TEST_PROG in `find $HERE -type f -print | egrep ^$HERE/test\(\([-0-9a-zA-Z_]\)+\)?\(\.sh\)?$ | grep -v testctl` ; do + TEST_PROG=`basename $TEST_PROG` + echo "run test: $TEST_PROG" TEST_PROG_LIST="$TEST_PROG_LIST $TEST_PROG" done } @@ -123,16 +130,38 @@ run_test_prog () TEST_PROG=$1 REFERENCE=$2 DISPLAY_ON_STDOUT=$3 - OUTPUT_DIR= OUTPUT_SUFFIX= TEST_INPUT_LIST= + VALGRIND_OPTIONS="--error-limit=no --num-callers=100 --logfile=$HERE/$VALGRIND_LOGS_DIR/$TEST_PROG-valgrind.log --leak-check=yes --show-reachable=yes --quiet --suppressions=$HERE/vg.supp" + if test x$RUN_VALGRIND = xno ; then + VALGRIND= + else + VALGRIND=`which valgrind` + if test x$VALGRIND = x ; then + echo "Could not find valgrind in your path" + else + VALGRIND="$VALGRIND $VALGRIND_OPTIONS" + echo "Gonna run the tests with valgrind, using the following options: $VALGRIND_OPTIONS" + fi + fi + export VALGRIND + is_shell_script=`echo $TEST_PROG | egrep "(.*)?.sh"` + if test x$is_shell_script = x ; then + is_shell_script=no + else + is_shell_script=yes + fi + + if ! test -d $HERE/$VALGRIND_LOGS_DIR ; then + mkdir $HERE/$VALGRIND_LOGS_DIR + fi for TEST_INPUT in `ls -1 $HERE/$TEST_INPUT_DIR | egrep ^${TEST_PROG}\([\.0-9]\)+\css\$` ; do TEST_INPUT_LIST="$TEST_INPUT_LIST $TEST_INPUT" done - if test "$REFERENCE" = "yes" ; then + if test "$REFERENCE" = "yes" ; then OUTPUT_DIR=$HERE/$TEST_OUT_REF_DIR OUTPUT_SUFFIX=.out @@ -151,37 +180,52 @@ run_test_prog () if test "empty$TEST_INPUT_LIST" != "empty" ; then for TEST_INPUT in $TEST_INPUT_LIST ; do + TEST_INPUT_NAME=`basename $TEST_INPUT .sh` if test "$DISPLAY_ON_STDOUT" = "yes" ; then echo "###############################################" - echo "launching $HERE/$TEST_PROG $HERE/$TEST_INPUT_DIR/$TEST_INPUT".... - echo "###############################################" - $HERE/$TEST_PROG $HERE/$TEST_INPUT_DIR/$TEST_INPUT + echo "launching $VALGRIND $HERE/$TEST_PROG $HERE/$TEST_INPUT_DIR/$TEST_INPUT".... + echo "###############################################" + if test x$is_shell_script = xyes ; then + $HERE/$TEST_PROG $HERE/$TEST_INPUT_DIR/$TEST_INPUT + else + $VALGRIND $HERE/.libs/$TEST_PROG $HERE/$TEST_INPUT_DIR/$TEST_INPUT + fi echo "###############################################" echo "done" echo "###############################################" echo "" else - echo "executing $HERE/$TEST_PROG $HERE/$TEST_INPUT_DIR/$TEST_INPUT > $OUTPUT_DIR/${TEST_INPUT}${OUTPUT_SUFFIX} ..." - $HERE/$TEST_PROG $HERE/$TEST_INPUT_DIR/$TEST_INPUT > $OUTPUT_DIR/${TEST_INPUT}${OUTPUT_SUFFIX} + echo "executing $VALGRIND $HERE/$TEST_PROG $HERE/$TEST_INPUT_DIR/$TEST_INPUT > $OUTPUT_DIR/${TEST_INPUT_NAME}${OUTPUT_SUFFIX} ..." + $VALGRIND $HERE/.libs/$TEST_PROG $HERE/$TEST_INPUT_DIR/$TEST_INPUT > $OUTPUT_DIR/${TEST_INPUT_NAME}${OUTPUT_SUFFIX} echo "done" fi done else if test "$DISPLAY_ON_STDOUT" = "yes" ; then echo "####################################################" - echo "launching $HERE/$TEST_PROG ..." + echo "launching $VALGRIND $HERE/$TEST_PROG ..." echo "####################################################" - $HERE/$TEST_PROG + if test x$is_shell_script = xyes ; then + $HERE/$TEST_PROG + else + $VALGRIND $HERE/.libs/$TEST_PROG + fi echo "####################################################" echo "done" echo "####################################################" echo "" else - echo "executing $HERE/$TEST_PROG > $OUTPUT_DIR/${TEST_INPUT}${OUTPUT_SUFFIX} ..." - $HERE/$TEST_PROG > $OUTPUT_DIR/${TEST_PROG}${OUTPUT_SUFFIX} + TEST_INPUT_NAME=`basename $TEST_PROG .sh` + echo "executing $VALGRIND $HERE/$TEST_PROG > $OUTPUT_DIR/${TEST_PROG}${OUTPUT_SUFFIX} ..." + if test x$is_shell_script = xyes ; then + $HERE/$TEST_PROG > $OUTPUT_DIR/${TEST_INPUT_NAME}${OUTPUT_SUFFIX} + else + $VALGRIND $HERE/.libs/$TEST_PROG > $OUTPUT_DIR/${TEST_INPUT_NAME}${OUTPUT_SUFFIX} + fi echo "done" fi fi + unset VALGRIND } cleanup_tests () @@ -189,12 +233,16 @@ cleanup_tests () if test -d $HERE/$TEST_OUTPUT_DIR ; then echo "removing $HERE/$TEST_OUTPUT_DIR" rm -rf $HERE/$TEST_OUTPUT_DIR/* + rm -rf $HERE/$VALGRIND_LOGS_DIR + fi + if test -f $HERE/$ERROR_REPORT_FILE ; then + rm $HERE/$ERROR_REPORT_FILE fi } run_test_report () { - diff -ur --exclude=*CVS* --exclude=*cvs* --exclude=Makefile* $HERE/$TEST_OUT_REF_DIR $HERE/$TEST_OUTPUT_DIR > /tmp/toto$$ + diff -ur --exclude=*CVS* --exclude=*cvs* --exclude=Makefile* --exclude=.arch-ids $HERE/$TEST_OUT_REF_DIR $HERE/$TEST_OUTPUT_DIR > /tmp/toto$$ NB_DIFF=`cat /tmp/toto$$ | wc -l` if test "$NB_DIFF" -eq 0 ; then @@ -205,6 +253,32 @@ run_test_report () mv /tmp/toto$$ $HERE/$ERROR_REPORT_FILE echo "See $HERE/$ERROR_REPORT_FILE to see what's going on" fi + + ################### + #Valgrind errors # + ################### + memleaks=no + for vg_log in `find $HERE/$VALGRIND_LOGS_DIR -name "*-valgrind.log*" -print` ; do + if test -s $vg_log ; then + leaks=`cat $vg_log | grep -i leak | grep -v no` + errors=`cat $vg_log | grep -w Invalid` + if test "x$leaks" = "x" -a "x$errors" = "x" ; then + rm -f $vg_log ; + else + echo "valgrind reported some memory leaks/corruptions in $vg_log" + memleaks=yes + fi + else + rm $vg_log + fi + done + if test "x$RUN_VALGRIND" = "xyes" ; then + if test "x$memleaks" = "xno" ; then + echo "Oh, YESSSSSS!, VALGRIND DID NOT DETECT ANY MEMLEAK !! You can go have a beer." + else + echo "Please report these leaks by sending the valgrind logs to the authors of libcroco." + fi + fi } ############################ @@ -286,7 +360,7 @@ execute_command () execute_run_cmd $@ ;; - mkref) + ref) build_tests_list ; if test "empty$TEST_PROG_LIST" = "empty" ; then echo "could not find any test to run" @@ -298,12 +372,8 @@ execute_command () done ;; - mkcleanup) - rm -f $HERE/$TEST_OUTPUT_DIR/* - - if test -f $HERE/$ERROR_REPORT_FILE ; then - rm $HERE/$ERROR_REPORT_FILE - fi + cleanup) + cleanup_tests ;; *) diff --git a/tests/vg.supp b/tests/vg.supp new file mode 100644 index 0000000..5a3d109 --- /dev/null +++ b/tests/vg.supp @@ -0,0 +1,57 @@ +{ + g_print_ALLOC_LEAK + Memcheck:Leak + fun:malloc + fun:realloc + fun:g_realloc + fun:g_array_maybe_expand + fun:g_array_set_size + fun:g_static_private_set + fun:g_get_charset + fun:g_print +} + +{ + g_slist_prepend_LEAK + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:g_allocator_new + fun:_g_slist_alloc + fun:g_slist_prepend +} + +{ + g_print_CONVERT_LEAK + Memcheck:Leak + fun:malloc + obj:*libc-2.3.3.so + fun:iconv_open + fun:try_conversion + fun:g_iconv_open + fun:open_converter + fun:g_convert + fun:g_convert_with_fallback + fun:strdup_convert + fun:g_print +} + +{ + g_string_new_CHUNCK_LEAK + Memcheck:Leak + fun:malloc + fun:g_malloc + fun:g_mem_chunk_new + fun:g_string_sized_new + fun:g_string_new +} + +{ + g_list_prepend_LEAK + Memcheck:Leak + fun:calloc + fun:g_malloc0 + fun:g_allocator_new + fun:_g_list_alloc + fun:g_list_prepend +} |