diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | croco-config.in | 4 | ||||
-rw-r--r-- | docs/examples/cssom-example-1.c | 10 | ||||
-rw-r--r-- | docs/examples/sac-example-1.c | 5 | ||||
-rw-r--r-- | docs/examples/sac-example-2.c | 16 | ||||
-rw-r--r-- | docs/examples/selection-example-1.c | 267 | ||||
-rw-r--r-- | src/cr-sel-eng.c | 13 | ||||
-rw-r--r-- | tests/test7-main.c | 193 |
8 files changed, 179 insertions, 339 deletions
@@ -1,3 +1,13 @@ +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 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/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-sel-eng.c b/src/cr-sel-eng.c index 2e23442..82d70c4 100644 --- a/src/cr-sel-eng.c +++ b/src/cr-sel-eng.c @@ -1614,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; /* @@ -1632,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; @@ -1645,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; @@ -1674,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; diff --git a/tests/test7-main.c b/tests/test7-main.c deleted file mode 100644 index e55467a..0000000 --- a/tests/test7-main.c +++ /dev/null @@ -1,193 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset:8 -*- */ - -/* - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the - * GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - *$Id$ - */ - -#include <string.h> -#include "libcroco.h" -#include "cr-test-utils.h" - -const guchar *gv_xmlbuf = - "<?xml version=\"1.0\"?>" - "<rss version=\"0.91\">" - "<channel>" - "<title>scottandrew.com JavaScript and DHTML Channel</title>" - "<link>http://www.scottandrew.com</link>" - "<description>DHTML, DOM and JavaScript snippets from scottandrew.com</description>" - "<language>en-us</language>" - "<item>" - "<title>DHTML Animation Array Generator</title>" - "<description>Robert points us to the first third-party tool for the DomAPI: The Animation Array Generator, a visual tool for creating...</description>" - "<link>http://www.scottandrew.com/weblog/2002_06#a000395</link>" - "</item>" - "<item>" - "<title>DOM and Extended Entries</title>" - "<description>Aarondot: A Better Way To Display Extended Entries. Very cool, and uses the DOM and JavaScript to reveal the extended...</description>" - "<link>http://www.scottandrew.com/weblog/2002_06#a000373</link>" - "</item>" - "<item>" - "<title>cellspacing and the DOM</title>" - "<description>By the way, if you're using the DOM to generate TABLE elements, you have to use setAttribute() to set the...</description>" - "<link>http://www.scottandrew.com/weblog/2002_05#a000365</link>" - "</item>" - "<item>" - "<title>contenteditable for Mozilla</title>" - "<description>The folks art Q42, creator of Quek (cute little avatar/chat) and Xopus (browser-based WYSIWYG XML-editor) have released code that ,simulates...</description>" - "<link>http://www.scottandrew.com/weblog/2002_05#a000361</link>" - "</item>" "</channel>" "</rss>"; - -const char *gv_cssbuf = - "rss " - "{ " - " display:block; " - " margin:10px; " - "} " - " " - "channel " - "{ " - " display:block; " - " /*height:300px;*/ " - " width:200px; " - " border:1px solid #000; " - " overflow:auto; " - " background-color:#eee; " - " /*font: 12px verdana;*/ " - " font-style: font-family ; " - " font-style: normal; " - "} " - " " - "item " - "{ " - " width: 100%; " - " display: block; " - " padding:10px; " - " margin-bottom:10px; " - " border:1px solid #ccc; " - " /*border-top:1px solid #ccc; " - " border-bottom:1px solid #ccc; " - " border-left:1px solid #ccc; " - " border-right:1px solid #ccc; " - " */ " - " background-color:#fff; " - "} " - " " - " " - "channel>title, channel>description " - "{ " - " display: block; " - " width: 100%; " - " /*margin-left:10px;*/ " - " /*margin-top:10px;*/ " - " background-color:#eee; " - " font-weight:bold; " - " font-size: 12px; " - "} " - " " - "channel>title " - "{ " - " font-size:16px; " - "} " - " " - "channel>description " - "{ " - " display: block ; " - " font-size:10px; " - " margin-bottom:10px; " - "} " - " " - "item>title " - "{ " - " font-weight:bold; " - "} " - " " - "item>link, channel>link, channel>language " - "{ " - " display: none; " - "} " - " "; - -static enum CRStatus - test_layout_box (void); - -static gboolean -delete_event_cb (GtkWidget * a_widget, GdkEvent * a_event, - gpointer * a_user_data); - -static gboolean -delete_event_cb (GtkWidget * a_widget, GdkEvent * a_event, - gpointer * a_user_data) -{ - gtk_main_quit (); - return FALSE; -} - -static enum CRStatus -test_layout_box (void) -{ - CRBoxView *box_view = NULL; - GtkWidget *window = NULL, - *scroll = NULL; - - box_view = cr_box_view_new_from_xml_css_bufs (gv_xmlbuf, gv_cssbuf); - g_return_val_if_fail (box_view, CR_BAD_PARAM_ERROR); - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_return_val_if_fail (window, CR_BAD_PARAM_ERROR); - - gtk_window_set_title (GTK_WINDOW (window), "Croco Renderer Test"); - gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, TRUE); - gtk_widget_set_size_request (window, 800, 600); - - g_signal_connect (G_OBJECT (window), - "delete-event", G_CALLBACK (delete_event_cb), NULL); - - scroll = gtk_scrolled_window_new (NULL, NULL); - g_return_val_if_fail (scroll, CR_BAD_PARAM_ERROR); - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS); - gtk_container_add (GTK_CONTAINER (window), scroll); - gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (box_view)); - gtk_widget_show_all (window); - gtk_main (); - - return CR_OK; -} - -int -main (int argc, char **argv) -{ - enum CRStatus status = CR_OK; - - cr_lay_eng_init (argc, argv); - - status = test_layout_box (); - - if (status != CR_OK) { - g_print ("\nKO\n"); - } - return 0; -} |