diff options
author | Dodji Seketeli <dodji@src.gnome.org> | 2004-04-18 13:07:23 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2004-04-18 13:07:23 +0000 |
commit | e5ddd1eaed7d332f062d01a4086b5235cffaba1c (patch) | |
tree | c0c1b3499acba882288d426890409c70e6ea7390 | |
parent | 242b66d43d931c4a1b46a99cb47a9cd76271a1ca (diff) | |
download | libcroco-e5ddd1eaed7d332f062d01a4086b5235cffaba1c.tar.gz |
Changes from arch/CVS synchronization
45 files changed, 1489 insertions, 797 deletions
@@ -1,6 +1,197 @@ 2004-04-18 Dodji Seketeli <dodji@gnome.org> - * src/libcroco-config.h: removed this from CVS. + * configure.in: bumped the version info 3.0.1 + and version number to 0.5.1 + +2004-04-17 Dodji Seketeli <dodji@gnome.org> + + * src/cr-parser.c: + (cr_parser_parse_stylesheet): + Correctly detect @import run parsing errors. + This fixes http://bugzilla.gnome.org/show_bug.cgi?id=140334 . + + * src/cr-parser.c: + (cr_parser_parse_simple_selector): + correctly detect when class additional selector parsing + fails. + (cr_parser_parse_simple_sels): + Make sure a pointer is not null before derefencing it. + append a simple sel to the list of simple sels only if + the simple sel is not NULL. + This entry fixes http://bugzilla.gnome.org/show_bug.cgi?id=140317 + . + + * src/cr-statement.[ch]: + (cr_statement_list_to_string): + added this to "to_string" a list of statements. + (cr_statement_media_rule_to_string): dump the + *list of statements* contained in the media rule, and + not only the first one. + This entry fixes http://bugzilla.gnome.org/show_bug.cgi?id=139891 . + * tests/*: added the test-several-media.sh regression test. + + * src/cr-om-parser.c: + (end_media): set the "current statement" and + "current media statement" context variable to NULL + at the end a media statement. + This fixes http://bugzilla.gnome.org/show_bug.cgi?id=139889 . + +2004-04-16 Dodji Seketeli <dodji@gnome.org> + + * src/cr-num.c: + remove the '...' construction. This fixes + http://bugzilla.gnome.org/show_bug.cgi?id=138267. + +2004-04-10 Dodji Seketeli <dodji@gnome.org> + + * src/cr-parser.c: + (cr_parser_parse_atrule_core): + Make sure to return an error code when parsing fail. + This should fix http://bugzilla.gnome.org/show_bug.cgi?id=139615. + This fix keeps abi compatibility with libcroco 0.5. + +2004-03-16 Dodji <dodji@gnome.org> + + * ==================== 0.5 release ==================== + +2004-03-16 Dodji <dodji@gnome.org> + + * croco-config.in: fixed this to include libxml2 and glib + into cflags and libs. + * docs/examples/cssom-example-1.c,docs/examples/sac-example-1.c, + docs/examples/sac-example-2.c, docs/examples/selection-example-1.c,src/cr-sel-eng.c: + fix the code examples to reflect changes in 0.5, kill some + memleaks where needed. + * src/cr-sel-eng.c: killed a memleak in the selection engine. + +2004-03-15 Dodji <dodji@gnome.org> + + * tests/Makefile.am: added the tests/valgrind-version.sh file in + the distribution. + + * tests/testctl: enforced the use of valgrind 2.1.1 or higher. + * tests/valgrind-version.sh: added this file to test the version of + the currently installed version of valgrind. + +2004-03-14 Dodji <dodji@gnome.org> + + * src/cr-style.c: + (cr_style_set_props_to_defaults): added more default props + init. + * src/cr-fonts.h: modified some declarations here to + ease the support of the "font-weight: bolder" and + "font-weight: lighter" support in sewfox. + + * src/cr-parser.[ch],src/cr-rgb.[ch],src/cr-style.c: + applied a patch from Benjamin Dauvergne to add + CRRgb::parse_from_buf() and CRRgb::set_from_term() + methods. Modified the patch to comply with libcroco + coding style and to kill a compiler warning. + +2004-03-13 Dodji <dodji@gnome.org> + + * Makefile.am,tests/Makefile.am,tests/test-output-refs/Makefile.am: + Added some distribution plumbing. + + * configure.in: bumped version number to 0.5 and bumped version-info. + + * src/cr-sel-eng.c,src/cr-stylesheet.c, + src/cr-tknzr.c,tests/test5-main.c,tests/testctl: + massive mem leaks/corruption killing. + * vg.supp: added this to suppress glib normal leaks + from the leak report. + +2004-03-12 Dodji <dodji@gnome.org> + + * src/cr-declaration.c,src/cr-doc-handler.c, + src/cr-input.[ch],src/cr-parser.c,src/cr-rgb.c, + src/cr-selector.c,src/cr-term.c,src/cr-token.c, + tests/test1-main.c,tests/test4-main.c: started to kill mem leaks + and corruptions. + + * tests/testctl: added the --show-reachable=yes flag to valgrind. + + * tests/testctl: added better valgrind error reporting. + +2004-03-11 Dodji <dodji@gnome.org> + + * Makefile.am: now, tests are to be run by doing "make test". + Also, cleans up the previous test output before actually running. + * global-vars.sh: added this sh script that sets variable used + in all the test sh scripts based on csslint. + * test-prop-ident,test-unknown-at-rule,test-unknown-at-rule2: + renamed these into *.sh (e.g) test-prop-ident.sh to reflect + that it's a shell script, not a test written in C. + Also, make these use global-vars.sh + * tests/testctl: added a descent valgrind support when runned + with like "./testctl run --valgrind" or RUN_VALGRIND=yes ./testctl run. + Puts the valgrind logs in valgrind-logs/ and report their presence + to the user. This'll help catch mem leaks/corruption at the + regression test level. + Also make sure to launch ./libs/testblah and not ./testblah which + is actually a shell script. + + * tests/testctl: don't activate valgrind tests by default. + +2004-03-10 Dodji <dodji@gnome.org> + + * src/cr-statement.[ch]: + (cr_statement_to_string): do not add leading end of lines. + * cr-stylesheet.c: added cr_stylesheet_to_string(), handle + end of lines between statements here. + * tests/test-output-refs/test5.1.css.out: updated non + regression tests. + + * tests/testctl: added valgrind support in the non regression + tests. I think I still need to improve it to make it detect + the errors when there are some, and report it in a consistent + way. + + * tests/testctl: added support for tests that gets + called without any argument. + * tests/* added csslint based non regression tests for proprietary INDENT and + unknown at rule. + + * src/cr-utils.c: + (cr_utils_ucs1_to_utf8): handle zero length input gently. + + * src/cr-statement.c: finish the coding of the + cr_statement_to_string() function and make cr_statement_dump() + use it. + * src/cr-term.c: merge from libcroco--mainline--0.1 + +2004-03-09 Dodji <dodji@gnome.org> + + * src/cr-term.[ch]: applied a patch from Rob BUIS that adds + two new methods: + (cr_term_get_from_list) and (cr_term_get_from_list). + + * src/cr-statement.c: + (cr_statement_font_face_rule_to_string): added this method. + (cr_statement_dump_font_face_rule): make this use the new + cr_statement_font_face_rule_to_string() function. + * tests/testctl: update this to exclude .arch-ids from the diffs. + + * src/cr-parser.c,src/cr-tknzr.c: droped the way I was handling + the vendor proprietary properties and make sure to parse and IDENT by + following css3 rules. + + * src/cr-parser.c: + (cr_parser_parse_any_core): semicolon (';') is not part of the 'any' + production. + (cr_parser_parse_ruleset): consider the case where we have an empty ruleset (e.g 'x{}') + * {arch}/=tagging-method: changed this to make objects generation by the + compilation accepted by tla. + +2004-03-08 Dodji <dodji@gnome.org> + + * Merged in the following patches: + => dodji@seketeli.org--2004-xml-style-d/libcroco--dodji-d--0.1--base-0 + tag of dodji@gnome.org--xml-style-2004/libcroco--mainline--0.1--base-0 + => dodji@seketeli.org--2004-xml-style-d/libcroco--dodji-d--0.1--patch-1 + removed useless files. + + * files.txt,dirs.txt: removed these files. 2004-03-07 Dodji Seketeli <dodji@gnome.org> @@ -348,7 +539,7 @@ 2004-01-04 Dodji Seketeli <dodji@gnome.org> * src/parser/cr-declaration.c: - (cr_declaration_unlin): fixed a bug spoted by + (cr_declaration_unlink): fixed a bug spoted by Rob BUIS. 2003-12-27 Dodji Seketeli <dodji@gnome.org> diff --git a/Makefile.am b/Makefile.am index 37da322..dffc8dc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,7 +11,7 @@ bin_SCRIPTS=croco-config man_MANS = croco-config.1 EXTRA_DIST= croco-config.in libcroco.pc libcroco.spec TODO Doxyfile \ -HACKING COPYING.LIB COPYING libcroco.spec tests/testctl $(man_MANS) +HACKING COPYING.LIB COPYING libcroco.spec $(man_MANS) cleantar: @(rm -f libcroco*.tar.gz) @@ -20,8 +20,8 @@ cleantar: rpm: cleantar @(mkdir -p $(top_srcdir)/rpmbuildroot ; $(MAKE) dist && rpmbuild -ta --buildroot $(top_srcdir)/rpmbuildroot $(distdir).tar.gz) -nr-tests: - if test -x $(top_srcdir)/tests/testctl ; then $(top_srcdir)/tests/testctl mkcleanup ; $(top_srcdir)/tests/testctl run ; fi +test: + if test -x $(top_srcdir)/tests/testctl ; then $(top_srcdir)/tests/testctl cleanup ; $(top_srcdir)/tests/testctl ; $(top_srcdir)/tests/testctl run ; fi apidoc: if ! test -d docs/apis ; then mkdir -p docs/apis ; fi ; @@ -1,3 +1,31 @@ +0.5.1: April 18 2004: + + - fixes: #140334, #140317, #139891, #139615. + +0.5: March 16 2004: + + - better regression suite framework [Dodji Seketeli] + - support of the 'color' property gathering [Benjamin Dauvergne] + - furious memory leaks/corruptions hunting [Dodji Seketeli, Rob BUIS] + - total support of the !important keyword [Dodji Seketeli, Rob BUIS] + - selectors evaluation in csslint [Dodji Seketeli, Rob BUIS] + - fix compilation warnings [David A Knight, Dodji Seketeli] + - more complete CSS statement serialisation [Dodji Seketeli] + - better gathering of style information [Dodjij Seketeli] + - better cascading algorithm conformance [Dodji Seketeli, Rob BUIS] + - @import rule parsing fix [Dodji Seketeli] + - support of CSS3 indentifiers [Dodji Seketeli] + - better w3c DOM integration support [Rob BUIS, Dodji Seketeli] + - many parsing fixes [Dodji Seketeli] + - style structure debuging facility [Dodji Seketeli] + - better fragment parsing support [Dodji Seketeli] + - Split libcroco and sewfox [Dodji Seketeli] + - class selector evaluation fix [Rob BUIS] + - csslint cleanup and bugfixes [Dodji Seketeli] + - :first-child pseudo class selector support [Dodji Seketeli] + - pluggable pseudo class selectors evaluators [Dodji Seketeli] + + libcroco 0.2.0 2003 Jun 29 libcroco 0.2.0 ChangeLog: diff --git a/configure.in b/configure.in index df9361a..8eaaba2 100644 --- a/configure.in +++ b/configure.in @@ -9,12 +9,12 @@ AM_CONFIG_HEADER(config.h) AM_MAINTAINER_MODE LIBCROCO_MAJOR_VERSION=0 -LIBCROCO_MINOR_VERSION=4 -LIBCROCO_MICRO_VERSION=0 +LIBCROCO_MINOR_VERSION=5 +LIBCROCO_MICRO_VERSION=1 -LIBCROCO_CURRENT=1 -LIBCROCO_REVISION=1 -LIBCROCO_AGE=0 +LIBCROCO_CURRENT=3 +LIBCROCO_REVISION=0 +LIBCROCO_AGE=1 #LIBCROCO_VERSION_INFO=`expr $LIBCROCO_MAJOR_VERSION + $LIBCROCO_MINOR_VERSION`:$LIBCROCO_MICRO_VERSION:$LIBCROCO_MINOR_VERSION LIBCROCO_VERSION_INFO="$LIBCROCO_CURRENT:$LIBCROCO_REVISION:$LIBCROCO_AGE" diff --git a/croco-config.in b/croco-config.in index b242e40..78911ff 100644 --- a/croco-config.in +++ b/croco-config.in @@ -68,11 +68,11 @@ while test $# -gt 0; do ;; --cflags) - echo @CROCO_CFLAGS@ + echo @CROCO_CFLAGS@ @GLIB2_CFLAGS@ @LIBXML2_CFLAGS@ ;; --libs) - echo @CROCO_LIBS@ + echo @CROCO_LIBS@ @GLIB2_LIBS@ @LIBXML2_LIBS@ ;; *) diff --git a/csslint/csslint.c b/csslint/csslint.c index 914cf47..aa17aa3 100644 --- a/csslint/csslint.c +++ b/csslint/csslint.c @@ -3,7 +3,7 @@ /* * csslint.c : a small tester program for CSS2 input * - * Copyright (C) 2002-2003 Gaël Chamoulaud, Dodji Seketeli. + * Copyright (C) 2002-2004 Gaël Chamoulaud, Dodji Seketeli. * * 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 diff --git a/docs/examples/cssom-example-1.c b/docs/examples/cssom-example-1.c index 663f86f..a41165e 100644 --- a/docs/examples/cssom-example-1.c +++ b/docs/examples/cssom-example-1.c @@ -8,19 +8,15 @@ * *To compile it using gcc, type * - *gcc -g `croco-config --cflags` `croco-config --libs` -o cssom-example-1 cssom-example-1.c + *gcc -g -Wall `croco-config --cflags` `croco-config --libs` -o cssom-example-1 cssom-example-1.c * *Prior to that, you must have compiled and installed libcroco, of course. * - *@author Dodji Seketeli <dodji@seketeli.org> - */ - -/* - *$Id$ + *@author Dodji Seketeli */ #include <string.h> -#include <libcroco.h> +#include <libcroco/libcroco.h> /** *Displays the usage of this program. diff --git a/docs/examples/sac-example-1.c b/docs/examples/sac-example-1.c index c7fd410..6e30eaa 100644 --- a/docs/examples/sac-example-1.c +++ b/docs/examples/sac-example-1.c @@ -9,7 +9,7 @@ * *To compile this file, type: * - *gcc -g -o sac-example-1 `croco-config --cflags` `croco-config --libs` sac-example-1.c + *gcc -g -Wall -o sac-example-1 `croco-config --cflags` `croco-config --libs` sac-example-1.c * *Make sure you have compiled and installed libcroco prior to trying to *compile this file :) @@ -23,7 +23,8 @@ *Initial Author: Dodji Seketeli <Dodji 47 seketeli dot org> */ -#include <libcroco.h> +#include <string.h> +#include <libcroco/libcroco.h> /** *This is a callback function that will diff --git a/docs/examples/sac-example-2.c b/docs/examples/sac-example-2.c index f8a0e9b..a9aa9e4 100644 --- a/docs/examples/sac-example-2.c +++ b/docs/examples/sac-example-2.c @@ -20,7 +20,7 @@ * *To compile this file, type: * - *gcc -g -o sac-example-2 `croco-config --cflags` `croco-config --libs` sac-example-2.c + *gcc -g -Wall -o sac-example-2 `croco-config --cflags` `croco-config --libs` sac-example-2.c * *Make sure you have compiled and installed libcroco prior to trying to *compile this file :) @@ -33,8 +33,9 @@ * *Initial Author: Dodji Seketeli <Dodji 47 seketeli dot org> */ +#include <string.h> #include <stdlib.h> -#include <libcroco.h> +#include <libcroco/libcroco.h> /** *A Context that will hold the @@ -45,10 +46,10 @@ struct MyFooContext { /**the total number of rulesets in the stylesheet.*/ - unsigned long nb_rulesets ; + int nb_rulesets ; /**the number of property per ruleset.*/ - unsigned long nb_props_per_ruleset ; + int nb_props_per_ruleset ; } ; /** @@ -131,7 +132,8 @@ start_selector_cb (CRDocHandler *a_handler, static void property_cb (CRDocHandler *a_handler, GString *a_name, - CRTerm *a_value) + CRTerm *a_value, + gboolean a_important) { struct MyFooContext *context = NULL ; @@ -241,7 +243,7 @@ main (int argc, char **argv) *available now, so this is *a bit redundant... */ - display_usage ((unsigned char*)argv[0]) ; + /*display_usage ((unsigned char*)argv[0]) ;*/ } } @@ -343,7 +345,5 @@ main (int argc, char **argv) */ cr_parser_destroy (parser) ; - cr_doc_handler_unref (sac_handler) ; - return 0 ; } diff --git a/docs/examples/selection-example-1.c b/docs/examples/selection-example-1.c index 4932a86..3fb9dfe 100644 --- a/docs/examples/selection-example-1.c +++ b/docs/examples/selection-example-1.c @@ -5,156 +5,185 @@ * * To compile it using gcc, type * - * gcc -g `croco-config --cflags` `croco-config --libs` -o selection-example-1 selection-example-1.c + * gcc -g -Wall `croco-config --cflags` `croco-config --libs` -o selection-example-1 selection-example-1.c * - * @author Stefan Seefeld <seefeld@sympatico.ca> + * Initial author: Stefan Seefeld. */ -#include <libcroco.h> +#include <libcroco/libcroco.h> #include <libxml/tree.h> #include <libxml/xpath.h> -void usage_and_exit(char *progname) +void +usage_and_exit (char *progname) { - fprintf(stderr, "Usage: %s <xml doc> <stylesheet> <xpath>\n", progname); - exit(-1); + fprintf (stderr, + "Usage: %s <xml doc> <stylesheet> <xpath>\n", + progname); + exit(-1); } struct workspace { - xmlDoc *document; - xmlXPathContext *xpath; - xmlXPathObject *result; - CRStyleSheet *stylesheet; - CRCascade *cascade; - CRSelEng *selector; + xmlDoc *document; + xmlXPathContext *xpath; + xmlXPathObject *result; + CRStyleSheet *stylesheet; + CRCascade *cascade; + CRSelEng *selector; }; /** *construct workspace members in order... * return 0 on success and -1 on error */ -int init(struct workspace *ws, char **args) +int +init (struct workspace *ws, char **args) { - short i = 0; - enum CRStatus status = CR_OK; - - ws->document = 0; - ws->xpath = 0; - ws->result = 0; - ws->stylesheet = 0; - ws->cascade = 0; - ws->selector = 0; - - - ws->document = xmlParseFile(args[0]); - if (!ws->document) - { - fprintf(stderr, "could not parse the document %s", args[0]); - return -1; - } - ws->xpath = xmlXPathNewContext(ws->document); - if (!ws->xpath) - { - fprintf(stderr, "Error: unable to create new XPath context\n"); - return -1; - } - ws->result = xmlXPathEvalExpression((xmlChar *)args[2], ws->xpath); - if (!ws->result) - { - fprintf(stderr, "Error: unable to evaluate xpath expression\n"); - return -1; - } - if (ws->result->type != XPATH_NODESET || !ws->result->nodesetval) - { - fprintf(stderr, "Error: xpath does not evaluate to a node set\n"); - return -1; - } - - status = cr_om_parser_simply_parse_file((const guchar*)args[1] /*sheet*/, - CR_ASCII /*the encoding*/, - &ws->stylesheet); - if (status != CR_OK || !ws->stylesheet) - { - fprintf(stderr, "could not parse the stylesheet %s", args[1]); - return -1; - } - ws->cascade = cr_cascade_new(ws->stylesheet, 0, 0); - ws->selector = cr_sel_eng_new(); + enum CRStatus status = CR_OK; + + ws->document = 0; + ws->xpath = 0; + ws->result = 0; + ws->stylesheet = 0; + ws->cascade = 0; + ws->selector = 0; + + + ws->document = xmlParseFile(args[0]); + if (!ws->document) + { + fprintf(stderr, "could not parse the document %s", args[0]); + return -1; + } + ws->xpath = xmlXPathNewContext(ws->document); + if (!ws->xpath) + { + fprintf(stderr, "Error: unable to create new XPath context\n"); + return -1; + } + ws->result = xmlXPathEvalExpression((xmlChar *)args[2], ws->xpath); + if (!ws->result) + { + fprintf(stderr, "Error: unable to evaluate xpath expression\n"); + return -1; + } + if (ws->result->type != XPATH_NODESET || !ws->result->nodesetval) + { + fprintf(stderr, "Error: xpath does not evaluate to a node set\n"); + return -1; + } + + status = cr_om_parser_simply_parse_file((const guchar*)args[1] /*sheet*/, + CR_ASCII /*the encoding*/, + &ws->stylesheet); + if (status != CR_OK || !ws->stylesheet) + { + fprintf(stderr, "could not parse the stylesheet %s", args[1]); + return -1; + } + ws->cascade = cr_cascade_new(ws->stylesheet, 0, 0); + ws->selector = cr_sel_eng_new(); + return 1 ; } /* ...and destruct in reverse order*/ -void fini(struct workspace *ws) +void +fini(struct workspace *ws) { - if (ws->selector) - { - cr_sel_eng_destroy(ws->selector); - ws->selector = NULL ; - } - if (ws->cascade) - { - cr_cascade_destroy(ws->cascade); - ws->cascade = NULL ; - } - - if (ws->result) - { - xmlXPathFreeObject(ws->result); - ws->result = NULL ; - } - if (ws->xpath) - { - xmlXPathFreeContext(ws->xpath); - ws->xpath = NULL ; - } - if (ws->document) - { - xmlFreeDoc(ws->document); - ws->document = NULL ; - } + if (ws->selector) + { + cr_sel_eng_destroy(ws->selector); + ws->selector = NULL ; + } + if (ws->cascade) + { + cr_cascade_destroy(ws->cascade); + ws->cascade = NULL ; + } + + if (ws->result) + { + xmlXPathFreeObject(ws->result); + ws->result = NULL ; + } + if (ws->xpath) + { + xmlXPathFreeContext(ws->xpath); + ws->xpath = NULL ; + } + if (ws->document) + { + xmlFreeDoc(ws->document); + ws->document = NULL ; + } + xmlCleanupParser () ; } -void print_property(gpointer name, gpointer decl, gpointer data) +void +print_properties_real (CRPropList *proplist) { - CRDeclaration *declaration = (CRDeclaration *)decl; - printf("%s\n", (char *)cr_declaration_to_string(declaration, 0)); + CRDeclaration *decl = NULL ; + CRPropList *cur_pair = NULL ; + + for (cur_pair = proplist ; cur_pair ; + cur_pair= cr_prop_list_get_next (cur_pair)) { + decl = NULL ; + gchar *str = NULL ; + cr_prop_list_get_decl (cur_pair, &decl) ; + if (decl) { + str = cr_declaration_to_string (decl, 0) ; + if (str) { + printf ("%s\n", str) ; + g_free (str); + str = NULL ; + } + } + } } -void print_properties(struct workspace *ws) +void +print_properties (struct workspace *ws) { - enum CRStatus status; - GHashTable *table = g_hash_table_new(g_str_hash, g_str_equal); - xmlNode *node = ws->result->nodesetval->nodeTab[0]; - if (!table) - { - fprintf(stderr, "unable to allocate a hash table\n"); - return; - } - status = cr_sel_eng_get_matched_properties_from_cascade(ws->selector, - ws->cascade, - node, - &table); - if (status != CR_OK) - fprintf(stderr, "Error retrieving properties\n"); - else - { - printf("properties for node %s :\n", (char *)xmlGetNodePath(node)); - g_hash_table_foreach(table, print_property, 0); - } - g_hash_table_destroy(table); + enum CRStatus status; + CRPropList *prop_list = NULL; + xmlNode *node = ws->result->nodesetval->nodeTab[0]; + + status = cr_sel_eng_get_matched_properties_from_cascade + (ws->selector, ws->cascade, + node, &prop_list); + + if (status != CR_OK) + fprintf(stderr, "Error retrieving properties\n"); + else + { + xmlChar *prop = NULL ; + prop = xmlGetNodePath(node) ; + if (prop) { + printf("properties for node %s :\n", prop); + xmlFree (prop) ; + prop = NULL ; + } + print_properties_real (prop_list) ; + } + cr_prop_list_destroy (prop_list) ; } -int main(int argc, char **argv) +int +main(int argc, char **argv) { - struct workspace ws; - if (argc != 4) usage_and_exit(argv[0]); - if (!init(&ws, argv + 1)) fini(&ws); + struct workspace ws; + if (argc != 4) usage_and_exit(argv[0]); + if (!init(&ws, argv + 1)) { + fini(&ws); + return -1 ; + } - if (ws.result->nodesetval->nodeNr == 0) - printf("no matching nodes found\n"); - else - print_properties(&ws); + if (ws.result->nodesetval->nodeNr == 0) + printf("no matching nodes found\n"); + else + print_properties(&ws); - fini(&ws); - return 0; + fini(&ws); + return 0; } 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-fonts.h b/src/cr-fonts.h index 76effe7..29fdfe3 100644 --- a/src/cr-fonts.h +++ b/src/cr-fonts.h @@ -189,20 +189,21 @@ enum CRFontVariant enum CRFontWeight { - FONT_WEIGHT_NORMAL=0, - FONT_WEIGHT_BOLD, - FONT_WEIGHT_BOLDER, - FONT_WEIGHT_LIGHTER, - FONT_WEIGHT_100, - FONT_WEIGHT_200, - FONT_WEIGHT_300, - FONT_WEIGHT_400, - FONT_WEIGHT_500, - FONT_WEIGHT_600, - FONT_WEIGHT_700, - FONT_WEIGHT_800, - FONT_WEIGHT_900, - FONT_WEIGHT_INHERIT, + FONT_WEIGHT_NORMAL = 1, + FONT_WEIGHT_BOLD = 1<<1, + FONT_WEIGHT_BOLDER = 1<<2, + FONT_WEIGHT_LIGHTER = 1<<3, + FONT_WEIGHT_100 = 1<<4, + FONT_WEIGHT_200 = 1<<5, + FONT_WEIGHT_300 = 1<<6, + FONT_WEIGHT_400 = 1<<7, + FONT_WEIGHT_500 = 1<<8, + FONT_WEIGHT_600 = 1<<9, + FONT_WEIGHT_700 = 1<<10, + FONT_WEIGHT_800 = 1<<11, + FONT_WEIGHT_900 = 1<<12, + FONT_WEIGHT_INHERIT = 1<<13, + NB_FONT_WEIGHTS } ; enum CRFontStretch 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-num.c b/src/cr-num.c index 374a5da..5781ae3 100644 --- a/src/cr-num.c +++ b/src/cr-num.c @@ -3,7 +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 @@ -18,6 +17,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * + * Author: Dodji Seketeli + * See COPYRIGHTS file for copyrights information. */ /* @@ -267,16 +269,11 @@ cr_num_is_fixed_length (CRNum * a_this) g_return_val_if_fail (a_this, FALSE); - switch (a_this->type) { - case NUM_LENGTH_EM...NUM_LENGTH_PC: - result = TRUE; - break; - default: - result = FALSE; - break; + if (a_this->type >= NUM_LENGTH_EM + && a_this->type <= NUM_LENGTH_PC) { + result = TRUE ; } - - return result; + return result ; } /** diff --git a/src/cr-om-parser.c b/src/cr-om-parser.c index d1b85e3..c4f9d69 100644 --- a/src/cr-om-parser.c +++ b/src/cr-om-parser.c @@ -3,7 +3,7 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> + * Copyright (C) 2002-2004 Dodji Seketeli * * 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 @@ -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 @@ -463,7 +476,9 @@ end_media (CRDocHandler * a_this, GList * a_media_list) ctxt->stylesheet->statements = stmts; stmts = NULL; - a_media_list = NULL; /*compiler happy */ + ctxt->cur_stmt = NULL ; + ctxt->cur_media_stmt = NULL ; + a_media_list = NULL; } static void @@ -475,11 +490,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 +555,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 +576,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 +630,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 +732,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 +750,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 +852,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 +937,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..73f6a40 100644 --- a/src/cr-parser.c +++ b/src/cr-parser.c @@ -355,15 +355,9 @@ 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); -static enum CRStatus cr_parser_parse_term (CRParser * a_this, - CRTerm ** a_term); - static enum CRStatus cr_parser_parse_function (CRParser * a_this, GString ** a_func_name, CRTerm ** a_expr); @@ -1091,10 +1085,11 @@ cr_parser_parse_atrule_core (CRParser * a_this) } else if (token->type == SEMICOLON_TK) { goto done; } else { + status = CR_PARSING_ERROR ; goto error; } - done: + done: if (token) { cr_token_destroy (token); token = NULL; @@ -1102,7 +1097,7 @@ cr_parser_parse_atrule_core (CRParser * a_this) return CR_OK; - error: + error: if (token) { cr_token_destroy (token); token = NULL; @@ -1491,7 +1486,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 +1750,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); @@ -1784,7 +1775,7 @@ cr_parser_parse_property (CRParser * a_this, GString ** a_property) *@param a_term out parameter. The successfully parsed term. *@return CR_OK upon successfull completion, an error code otherwise. */ -static enum CRStatus +enum CRStatus cr_parser_parse_term (CRParser * a_this, CRTerm ** a_term) { enum CRStatus status = CR_PARSING_ERROR; @@ -2010,7 +2001,7 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel) (add_sel_list, add_sel); found_sel = TRUE; } else { - status = CR_OK; + status = CR_PARSING_ERROR; goto error; } } else if (token && token->type == BO_TK) { @@ -2202,12 +2193,12 @@ cr_parser_parse_simple_sels (CRParser * a_this, CRSimpleSel ** a_sel) if (status != CR_OK) break; - if (comb) { + if (comb && sel) { sel->combinator = comb; comb = 0; } - - *a_sel = cr_simple_sel_append_simple_sel (*a_sel, sel); + if (sel) + *a_sel = cr_simple_sel_append_simple_sel (*a_sel, sel); } cr_parser_clear_errors (a_this); @@ -2495,35 +2486,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]* ]* @@ -2690,8 +2652,10 @@ cr_parser_parse_stylesheet (CRParser * a_this) (PRIVATE (a_this)-> sac_handler); } - status = cr_parser_parse_atrule_core (a_this); + CHECK_PARSING_STATUS (status, TRUE) ; + } else { + goto error ; } /* @@ -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..f67b682 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 * @@ -110,6 +110,9 @@ enum CRStatus cr_parser_set_default_sac_handler (CRParser *a_this) ; enum CRStatus +cr_parser_parse_term (CRParser *a_this, CRTerm **a_term) ; + +enum CRStatus cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) ; enum CRStatus diff --git a/src/cr-rgb.c b/src/cr-rgb.c index 5cacb3e..c125675 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,15 +16,16 @@ * 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> #include "cr-rgb.h" +#include "cr-term.h" +#include "cr-parser.h" static CRRgb gv_standard_colors[] = { {"aliceblue", 240, 248, 255, 0}, @@ -378,7 +377,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; } @@ -437,6 +436,42 @@ cr_rgb_set_from_hex_str (CRRgb * a_this, const guchar * a_hex) } /** + *Set the rgb from a terminal symbol + *@param a_this the instance of #CRRgb to set + *@param a_value the terminal from which to set + */ +enum CRStatus +cr_rgb_set_from_term (CRRgb *a_this, const struct _CRTerm *a_value) +{ + enum CRStatus status = CR_OK ; + g_return_val_if_fail (a_this && a_value, + CR_BAD_PARAM_ERROR) ; + + switch(a_value->type) { + case TERM_RGB: + if (a_value->content.rgb) { + cr_rgb_set_from_rgb + (a_this, a_value->content.rgb) ; + } + break ; + case TERM_IDENT: + status = cr_rgb_set_from_name + (a_this, + a_value->content.str->str) ; + break ; + case TERM_HASH: + status = cr_rgb_set_from_hex_str + (a_this, + a_value->content.str->str) ; + break ; + default: + status = CR_UNKNOWN_TYPE_ERROR ; + } + + return status ; +} + +/** *Destructor of #CRRgb. *@param a_this the "this pointer" of the *current instance of #CRRgb. @@ -448,3 +483,56 @@ cr_rgb_destroy (CRRgb * a_this) g_free (a_this); } + +/** + *Parses a text buffer that contains a rgb color + * + *@param a_str a string that contains a color description + *@param a_enc the encoding of a_str + *@return the parsed color, or NULL in case of error + */ +CRRgb *cr_rgb_parse_from_buf (const guchar *a_str, + enum CREncoding a_enc) +{ + enum CRStatus status = CR_OK ; + CRTerm *value = NULL ; + CRParser * parser = NULL; + CRRgb *result = NULL; + + g_return_val_if_fail (a_str, NULL); + + 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) ; + if (status != CR_OK) + goto cleanup; + + status = cr_parser_parse_term (parser, &value); + if (status != CR_OK) + goto cleanup; + + result = cr_rgb_new (); + if (!result) + goto cleanup; + + status = cr_rgb_set_from_term (result, value); + +cleanup: + if (parser) { + cr_parser_destroy (parser); + parser = NULL; + } + if (value) { + cr_term_destroy(value); + value = NULL; + } + return result ; +} + + + + + diff --git a/src/cr-rgb.h b/src/cr-rgb.h index 9a11e6c..2918a4c 100644 --- a/src/cr-rgb.h +++ b/src/cr-rgb.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,19 +16,17 @@ * 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_RGB_H__ +#define __CR_RGB_H__ #include <stdio.h> #include <glib.h> #include "cr-utils.h" -#ifndef __CR_RGB_H__ -#define __CR_RGB_H__ - G_BEGIN_DECLS @@ -54,6 +50,9 @@ CRRgb * cr_rgb_new (void) ; CRRgb * cr_rgb_new_with_vals (gulong a_red, gulong a_green, gulong a_blue, gboolean a_is_percentage) ; +CRRgb *cr_rgb_parse_from_buf(const guchar *a_str, + enum CREncoding a_enc); + enum CRStatus cr_rgb_compute_from_percentage (CRRgb *a_this) ; enum CRStatus cr_rgb_set (CRRgb *a_this, gulong a_red, @@ -66,6 +65,10 @@ enum CRStatus cr_rgb_set_from_name (CRRgb *a_this, const guchar *a_color_name) ; enum CRStatus cr_rgb_set_from_hex_str (CRRgb *a_this, const guchar * a_hex_value) ; +struct _CRTerm; + +enum CRStatus cr_rgb_set_from_term (CRRgb *a_this, const struct _CRTerm *a_value); + guchar * cr_rgb_to_string (CRRgb *a_this) ; void cr_rgb_dump (CRRgb *a_this, FILE *a_fp) ; diff --git a/src/cr-sel-eng.c b/src/cr-sel-eng.c index 3161adc..82d70c4 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 ; } } @@ -1609,7 +1614,7 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, if (!stmts_tab) { cr_utils_trace_info ("Out of memory"); status = CR_ERROR; - goto error; + goto cleanup; } tab_size += stmts_chunck_size; /* @@ -1627,7 +1632,7 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, if (!stmts_tab) { cr_utils_trace_info ("Out of memory"); status = CR_ERROR; - goto error; + goto cleanup; } tab_size += stmts_chunck_size; index += tab_len; @@ -1640,7 +1645,7 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, if (status != CR_OK) { cr_utils_trace_info ("Error while running " "selector engine"); - goto error; + goto cleanup; } index += tab_len; tab_len = tab_size - index; @@ -1669,14 +1674,11 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, } } - - return CR_OK; - error: - + status = CR_OK ; + cleanup: if (stmts_tab) { g_free (stmts_tab); stmts_tab = NULL; - } return status; @@ -1757,14 +1759,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..1a5f823 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_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 cr_statement_clear (CRStatement * a_this); -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_list_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,246 @@ 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 ; +} + +gchar* +cr_statement_list_to_string (CRStatement *a_this, gulong a_indent) +{ + CRStatement *cur_stmt = NULL ; + GString *stringue = NULL ; + gchar *str = NULL ; + + g_return_val_if_fail (a_this, NULL) ; + + stringue = g_string_new (NULL) ; + if (!stringue) { + cr_utils_trace_info ("Out of memory") ; + return NULL ; + } + for (cur_stmt = a_this ; cur_stmt; + cur_stmt = cur_stmt->next) { + str = cr_statement_to_string (cur_stmt, a_indent) ; + if (str) { + if (!cur_stmt->prev) { + g_string_append (stringue, str) ; + } else { + g_string_append_printf + (stringue, "\n%s", str) ; + } + g_free (str) ; + str = NULL ; + } + } + str = stringue->str ; + g_string_free (stringue, FALSE) ; + 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..87e57d2 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,41 @@ 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) ; + +gchar* +cr_statement_list_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-style.c b/src/cr-style.c index 20859d7..04557eb 100644 --- a/src/cr-style.c +++ b/src/cr-style.c @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - *see COPYRIGTHS file for information + * see COPYRIGTHS file for copyright information */ /* @@ -998,73 +998,30 @@ set_prop_width (CRStyle * a_style, CRTerm * a_value) return CR_OK; } -static enum CRStatus +static enum CRStatus set_prop_color (CRStyle * a_style, CRTerm * a_value) { - enum CRStatus status = CR_OK; + enum CRStatus status = CR_OK; + CRRgb *a_rgb = &a_style->rgb_props[RGB_PROP_COLOR].sv; - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - switch (a_value->type) { - case TERM_RGB: - if (a_value->content.rgb) { - cr_rgb_set_from_rgb - (&a_style->rgb_props[RGB_PROP_COLOR].sv, - a_value->content.rgb); - } - break; - case TERM_IDENT: - status = cr_rgb_set_from_name - (&a_style->rgb_props[RGB_PROP_COLOR].sv, - a_value->content.str->str); - break; - case TERM_HASH: - status = cr_rgb_set_from_hex_str - (&a_style->rgb_props[RGB_PROP_COLOR].sv, - a_value->content.str->str); - break; - default: - status = CR_UNKNOWN_TYPE_ERROR; - } + status = cr_rgb_set_from_term (a_rgb, a_value); - return status; + return status; } static enum CRStatus set_prop_background_color (CRStyle * a_style, CRTerm * a_value) { - enum CRStatus status = CR_OK; + enum CRStatus status = CR_OK; + CRRgb *a_rgb = &a_style->rgb_props[RGB_PROP_BACKGROUND_COLOR].sv; - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - switch (a_value->type) { - case TERM_RGB: - if (a_value->content.rgb) { - status = cr_rgb_set_from_rgb - (&a_style-> - rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, - a_value->content.rgb); - } - break; - - case TERM_IDENT: - status = cr_rgb_set_from_name - (&a_style->rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, - a_value->content.str->str); - break; - - case TERM_HASH: - status = cr_rgb_set_from_hex_str - (&a_style->rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, - a_value->content.str->str); - break; - - default: - status = CR_UNKNOWN_TYPE_ERROR; - break; - } + status = cr_rgb_set_from_term (a_rgb, a_value); - return status; + return status; } /** @@ -1715,7 +1672,10 @@ cr_style_set_props_to_defaults (CRStyle * a_this) a_this->position = POSITION_STATIC; a_this->float_type = FLOAT_NONE; a_this->parent_style = NULL; - + a_this->font_style = FONT_STYLE_NORMAL; + a_this->font_variant = FONT_VARIANT_NORMAL; + a_this->font_weight = FONT_WEIGHT_NORMAL; + a_this->font_stretch = FONT_STRETCH_NORMAL; return CR_OK; } diff --git a/src/cr-stylesheet.c b/src/cr-stylesheet.c index 3f3665a..97ae79e 100644 --- a/src/cr-stylesheet.c +++ b/src/cr-stylesheet.c @@ -3,7 +3,7 @@ /* * This file is part of The Croco Library * - * Copyright (C) 2002-2003 Dodji Seketeli <dodji seketeli.org> + * Copyright (C) 2002-2004 Dodji Seketeli * * 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 @@ -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/tests/Makefile.am b/tests/Makefile.am index e17e2fa..aecadba 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 valgrind-version.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/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-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/test4.2.css.out b/tests/test-output-refs/test4.2.css.out index ae12244..64fe087 100644 --- a/tests/test-output-refs/test4.2.css.out +++ b/tests/test-output-refs/test4.2.css.out @@ -17,4 +17,8 @@ H1 { font-family : "Robson Celtic", serif } + P { + background : black; + foreground : white + } }
\ No newline at end of file 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/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..88dba5e 100755 --- a/tests/testctl +++ b/tests/testctl @@ -12,6 +12,7 @@ #the directory that contains the tests HERE=`dirname $0` + #the list of tests to be run TEST_PROG_LIST= @@ -27,7 +28,17 @@ 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 +if test "x$CHECKER" = "x" ; then + CHECKER="valgrind --tool=memcheck" +fi + +VALGRIND_LOGS_DIR=valgrind-logs +VALGRIND= TEST_PROG= EGREP=`which egrep` if test "empty$EGREP" = "empty" ; then @@ -53,8 +64,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 +98,7 @@ parse_command_line () exit 0 ;; - run|mkref|mkcleanup) + run|ref|cleanup) COMMAND_LIST=$arg REMAINING_ARGS=$@ echo "REMAINING_ARGS=$REMAINING_ARGS" @@ -106,8 +117,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 +135,53 @@ 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 + if ! test -x $HERE/valgrind-version.sh ; then + echo "Argh! Could not find file $HERE/valgrind-version.sh" + exit -1 ; + fi + version=`$HERE/valgrind-version.sh` + if ! test "x$version" = "xokay" ; then + echo "You must install a valgrind versin greater than 2.1.1" + echo "version=$version" + exit -1 + fi + if test "x$CHECKER" = "x" ; then + 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 + else + VALGRIND="$CHECKER $VALGRIND_OPTIONS" + echo "Gonna run the tests with valgrind, using the cmd line: $VALGRIND" + 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 +200,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 +253,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 +273,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 +380,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 +392,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 ;; *) |