[seed] Implement a skeleton XMLDocument class and xml.parseFile
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] Implement a skeleton XMLDocument class and xml.parseFile
- Date: Mon, 11 May 2009 23:59:00 -0400 (EDT)
commit 35574121acf7e15190004b78bc51ff78f8e75c94
Author: Robert Carr <racarr svn gnome org>
Date: Mon May 11 23:22:48 2009 -0400
Implement a skeleton XMLDocument class and xml.parseFile
---
modules/libxml/Makefile.am | 4 ++-
modules/libxml/libxml.c | 84 ++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 84 insertions(+), 4 deletions(-)
diff --git a/modules/libxml/Makefile.am b/modules/libxml/Makefile.am
index ba7902b..20c5e8f 100644
--- a/modules/libxml/Makefile.am
+++ b/modules/libxml/Makefile.am
@@ -11,11 +11,13 @@ liblibxml_la_SOURCES = \
AM_CPPFLAGS = \
-I top_srcdir@/libseed/ \
- $(GOBJECT_INTROSPECTION_CFLAGS)
+ $(LIBXML_CFLAGS) \
+ $(GOBJECT_INTROSPECTION_CFLAGS)
$(SEED_DEBUG_CFLAGS) \
$(SEED_PROFILE_CFLAGS)
liblibxml_la_LDFLAGS = \
+ $(LIBXML_LDFLAGS) \
$(GOBJECT_INTROSPECTION_LDFLAGS) \
$(SEED_PROFILE_LIBS)
diff --git a/modules/libxml/libxml.c b/modules/libxml/libxml.c
index 97c2d36..ce838e0 100644
--- a/modules/libxml/libxml.c
+++ b/modules/libxml/libxml.c
@@ -1,8 +1,86 @@
#include <seed.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>
+
+SeedObject namespace_ref;
+SeedEngine *eng;
+SeedClass xml_doc_class;
+
+seed_static_function doc_funcs[] = {
+ {0, 0, 0}
+};
+
+seed_static_value doc_values[] = {
+ {0, 0, 0, 0}
+};
+
+#define XML_DOC_PRIV(obj) ((xmlDocPtr)seed_object_get_private(obj))
+
+static SeedValue
+seed_xml_parse_file (SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException * exception)
+{
+ SeedObject ret;
+ xmlDocPtr doc;
+ gchar *path;
+ if (argument_count != 1)
+ {
+ seed_make_exception (ctx, exception, "ArgumentError",
+ "parseFile expected 1 argument, got %d",
+ argument_count);
+ return seed_make_null (ctx);
+ }
+ path = seed_value_to_string (ctx, arguments[0], exception);
+ doc = xmlParseFile (path);
+ if (!doc)
+ {
+ seed_make_exception (ctx, exception, "XMLError",
+ "Document not parsed successfully");
+ g_free (path);
+ return seed_make_null (ctx);
+ }
+ ret = seed_make_object (ctx, xml_doc_class, doc);
+
+ g_free (path);
+ return ret;
+}
+
+static void
+seed_xml_doc_finalize (SeedObject object)
+{
+ xmlDocPtr ptr = XML_DOC_PRIV (object);
+ xmlFreeDoc (ptr);
+}
+
+static void
+seed_libxml_define_stuff ()
+{
+ seed_class_definition xml_doc_class_def = seed_empty_class;
+
+ xml_doc_class_def.class_name="XMLDocument";
+ xml_doc_class_def.static_functions = doc_funcs;
+ xml_doc_class_def.static_values = doc_values;
+ xml_doc_class = seed_create_class (&xml_doc_class_def);
+
+ seed_create_function (eng->context, "parseFile",
+ (SeedFunctionCallback) seed_xml_parse_file,
+ namespace_ref);
+}
SeedObject
-seed_module_init(SeedEngine * eng)
+seed_module_init(SeedEngine *local_eng)
{
- g_printf("Hello Seed Module World \n");
- return seed_make_object (eng->context, NULL, NULL);
+ eng = local_eng;
+ namespace_ref = seed_make_object (eng->context, NULL, NULL);
+
+ seed_libxml_define_stuff();
+
+ return namespace_ref;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]