Author: tlsa
Date: Thu Dec 22 04:22:51 2011
New Revision: 13321
URL:
http://source.netsurf-browser.org?rev=13321&view=rev
Log:
Update for current libdom. Has issues.
Modified:
trunk/libdom/examples/dom-structure-dump.c
trunk/libdom/examples/makefile
Modified: trunk/libdom/examples/dom-structure-dump.c
URL:
http://source.netsurf-browser.org/trunk/libdom/examples/dom-structure-dum...
==============================================================================
--- trunk/libdom/examples/dom-structure-dump.c (original)
+++ trunk/libdom/examples/dom-structure-dump.c Thu Dec 22 04:22:51 2011
@@ -3,7 +3,7 @@
* Licensed under the MIT License,
*
http://www.opensource.org/licenses/mit-license.php
*
- * Copyright 2010 Michael Drake <tlsa(a)netsurf-browser.org>
+ * Copyright 2010 - 2011 Michael Drake <tlsa(a)netsurf-browser.org>
*/
/*
@@ -39,6 +39,7 @@
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -47,13 +48,6 @@
#include <dom/bindings/hubbub/parser.h>
#define UNUSED(x) ((x)=(x))
-
-void *test_realloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
void test_msg(uint32_t severity, void *ctx, const char *msg, ...)
{
@@ -83,11 +77,10 @@
int chunk_length;
dom_hubbub_error error;
dom_document *doc;
- char buffer[buffer_size];
+ unsigned char buffer[buffer_size];
/* Create Hubbub parser */
- parser = dom_hubbub_parser_create(NULL, true, test_realloc, NULL,
- test_msg, NULL);
+ parser = dom_hubbub_parser_create(NULL, true, test_msg, NULL);
if (parser == NULL) {
printf("Can't create Hubbub Parser\n");
return NULL;
@@ -147,82 +140,67 @@
bool dump_dom_element_class(dom_node_internal *node)
{
dom_exception exc;
- lwc_error err;
dom_string *class = NULL;
dom_string *classvalue = NULL;
- lwc_string *lwcstr = NULL;
+ dom_node_type type;
+ const char *string;
+ size_t length;
+
+ /* Should only have element nodes here */
+ exc = dom_node_get_node_type(node, &type);
+ if (exc != DOM_NO_ERR) {
+ printf(" Exception raised for node_get_node_type\n");
+ return false;
+ }
+ assert(type == DOM_ELEMENT_NODE);
+
+ /* Create a dom_string containing "class". */
+ exc = dom_string_create((uint8_t *)"class", 5, &class);
+ if (exc != DOM_NO_ERR) {
+ printf(" Exception raised for dom_string_create\n");
+ return false;
+ }
+
+ /* Get class attribute's value */
+ exc = dom_element_get_attribute(node, class, &classvalue);
+ if (exc != DOM_NO_ERR) {
+ printf(" Exception raised for element_get_attribute\n");
+ return false;
+ } else if (classvalue == NULL) {
+ /* Element has no class attribute */
+ return true;
+ }
+
+ /* Get attributes's string data */
+ string = dom_string_data(classvalue);
+ length = dom_string_byte_length(classvalue);
+
+ /* Print class info */
+ printf(" class=\"%*s\"", (int)length, string);
+
+ /* Finished with the classvalue dom_string */
+ dom_string_unref(classvalue);
+
+ return true;
+}
+
+
+/**
+ * Print a line in a DOM structure dump for an element
+ *
+ * \param node The node to dump
+ * \param depth The node's depth
+ * \return true on success, or false on error
+ */
+bool dump_dom_element(dom_node_internal *node, int depth)
+{
+ dom_exception exc;
+ dom_string *node_name = NULL;
dom_node_type type;
int i;
const char *string;
size_t length;
- /* Should only have element nodes here */
- exc = dom_node_get_node_type(node, &type);
- if (exc != DOM_NO_ERR) {
- printf(" Exception raised for node_get_node_type\n");
- return false;
- }
- assert(type == DOM_ELEMENT_NODE);
-
- /* Create a dom_string constaining "class". */
- exc = dom_string_create(test_realloc, NULL, "class", 5, &class);
- if (exc != DOM_NO_ERR) {
- printf(" Exception raised for dom_string_create\n");
- return false;
- }
-
- /* Get class attribute's value */
- exc = dom_element_get_attribute(node, class, &classvalue);
- if (exc != DOM_NO_ERR) {
- printf(" Exception raised for element_get_attribute\n");
- return false;
- } else if (classvalue == NULL) {
- /* Element has no class attribute */
- return true;
- }
-
- /* Get attributes's lwc_string */
- exc = dom_string_get_intern(classvalue, &lwcstr);
- if (exc != DOM_NO_ERR) {
- printf(" Exception raised for string_get_intern\n");
- return false;
- } else if (lwcstr == NULL) {
- printf(" Broken: lwcstr == NULL\n");
- return false;
- }
-
- /* Finished with the classvalue dom_string */
- dom_string_unref(classvalue);
-
- /* Get string data and print class info */
- string = lwc_string_data(lwcstr);
- length = lwc_string_length(lwcstr);
- printf(" class=\"%*s\"", length, string);
-
- /* Print the element's class, if it has one */
- dump_dom_element_class(node);
- return true;
-}
-
-
-/**
- * Print a line in a DOM structure dump for an element
- *
- * \param node The node to dump
- * \param depth The node's depth
- * \return true on success, or false on error
- */
-bool dump_dom_element(dom_node_internal *node, int depth)
-{
- dom_exception exc;
- lwc_error err;
- dom_string *node_name = NULL;
- lwc_string *lwcstr = NULL;
- dom_node_type type;
- int i;
- const char *string;
- size_t length;
-
/* Only interested in element nodes */
exc = dom_node_get_node_type(node, &type);
if (exc != DOM_NO_ERR) {
@@ -242,16 +220,6 @@
printf("Broken: root_name == NULL\n");
return false;
}
-
- /* Get element name's lwc_string */
- exc = dom_string_get_intern(node_name, &lwcstr);
- if (exc != DOM_NO_ERR) {
- printf("Exception raised for string_get_intern\n");
- return false;
- }
-
- /* Finished with the node_name dom_string */
- dom_string_unref(node_name);
/* Print ASCII tree structure for current node */
if (depth > 0) {
@@ -262,12 +230,16 @@
}
/* Get string data and print element name */
- string = lwc_string_data(lwcstr);
- length = lwc_string_length(lwcstr);
- printf("%*s", length, string);
-
- /* PENDING FIX: Print the element's class, if it has one */
+ string = dom_string_data(node_name);
+ length = dom_string_byte_length(node_name);
+ printf("%*s", (int)length, string);
+
+ /* Finished with the node_name dom_string */
+ dom_string_unref(node_name);
+
+ /* Print the element's class, if it has one */
if (dump_dom_element_class(node) == false) {
+ printf("\n");
return false;
}
@@ -329,16 +301,8 @@
int main(int argc, char **argv)
{
dom_exception exc; /* returned by libdom functions */
- lwc_error err; /* returned by libwapacplet functions */
dom_document *doc = NULL; /* document, loaded into libdom */
dom_node_internal *root = NULL; /* root element of document */
-
- /* Initialise the DOM library */
- exc = dom_initialise(test_realloc, NULL);
- if (exc != DOM_NO_ERR) {
- printf("Failed to initialise DOM library.\n");
- return EXIT_FAILURE;
- }
/* Load up the input HTML file */
doc = create_doc_dom_from_file("files/test.html");
@@ -363,13 +327,6 @@
return EXIT_FAILURE;
}
- /* Finalise the DOM library */
- exc = dom_finalise();
- if (exc != DOM_NO_ERR) {
- printf("Failed to finalise DOM library.\n");
- return EXIT_FAILURE;
- }
-
/* Finished with the dom_document */
dom_node_unref(doc);
Modified: trunk/libdom/examples/makefile
URL:
http://source.netsurf-browser.org/trunk/libdom/examples/makefile?rev=1332...
==============================================================================
--- trunk/libdom/examples/makefile (original)
+++ trunk/libdom/examples/makefile Thu Dec 22 04:22:51 2011
@@ -1,7 +1,7 @@
CC := gcc
LD := gcc
-CFLAGS := `pkg-config --cflags libdom` `pkg-config --cflags libwapcaplet`
+CFLAGS := `pkg-config --cflags libdom` `pkg-config --cflags libwapcaplet` -Wall
LDFLAGS := `pkg-config --libs libdom` `pkg-config --libs libwapcaplet`
SRC := dom-structure-dump.c