+Supplementary captive utilities for libxml2
authorshort <>
Fri, 18 Jul 2003 11:34:36 +0000 (11:34 +0000)
committershort <>
Fri, 18 Jul 2003 11:34:36 +0000 (11:34 +0000)
src/libcaptive/client/Makefile.am
src/libcaptive/client/libxml.c [new file with mode: 0644]
src/libcaptive/include/captive/Makefile.am
src/libcaptive/include/captive/libxml.h [new file with mode: 0644]

index 026ca07..f317617 100644 (file)
@@ -32,6 +32,7 @@ libclient_la_SOURCES= \
                leave.c \
                lib.c \
                lib.h \
+               libxml.c \
                options.c \
                options-module.c \
                result.c \
diff --git a/src/libcaptive/client/libxml.c b/src/libcaptive/client/libxml.c
new file mode 100644 (file)
index 0000000..8d3df52
--- /dev/null
@@ -0,0 +1,95 @@
+/* $Id$
+ * Supplementary captive utilities for libxml2
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * 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 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
+ */
+
+
+#include "config.h"
+
+#include "captive/libxml.h"    /* self */
+#include <glib/gmessages.h>
+#include <glib/ghook.h>
+#include <string.h>
+#include "captive/macros.h"
+
+
+struct captive_libxml_string_drop_stack {
+       GHookList g_hook_list;
+       };
+
+
+gint64 captive_libxml_sscanf_gint64(const gchar *gint64_string)
+{
+int errint;
+gint64 r;
+int gint64_string_len;
+
+       g_return_val_if_fail(gint64_string!=NULL,0);
+
+       errint=sscanf(gint64_string,"%" G_GINT64_FORMAT "%n",&r,&gint64_string_len);
+       g_assert(errint==1 || errint==2 /* %n */);
+       g_assert(gint64_string_len==(int)strlen(gint64_string));
+
+       return r;
+}
+
+
+static void captive_libxml_string_drop_hook_func(const xmlChar *xml_string /* data */)
+{
+       g_return_if_fail(xml_string!=NULL);
+
+       xmlFree((xmlChar *)xml_string);
+}
+
+const xmlChar *captive_libxml_string_drop(struct captive_libxml_string_drop_stack **drop_stackp,const xmlChar *xml_string)
+{
+GHook *g_hook;
+
+       g_return_val_if_fail(drop_stackp!=NULL,NULL);
+
+       if (!xml_string)
+               return xml_string;
+
+       if (!*drop_stackp) {
+               captive_new(*drop_stackp);
+               g_hook_list_init(&(*drop_stackp)->g_hook_list,sizeof(GHook));
+               }
+
+       g_hook=g_hook_alloc(&(*drop_stackp)->g_hook_list);
+       g_hook->func=(GHookFunc)captive_libxml_string_drop_hook_func;
+       g_hook->data=(xmlChar *)xml_string;
+       g_hook_append(&(*drop_stackp)->g_hook_list,g_hook);
+
+       return xml_string;
+}
+
+
+void captive_libxml_string_drop_flush(struct captive_libxml_string_drop_stack **drop_stackp)
+{
+struct captive_libxml_string_drop_stack *drop_stack;
+
+       g_return_if_fail(drop_stackp!=NULL);
+
+       if (!(drop_stack=*drop_stackp))
+               return;
+       *drop_stackp=NULL;
+
+       g_hook_list_invoke(&drop_stack->g_hook_list,
+                       FALSE); /* may_recurse */
+       g_hook_list_clear(&drop_stack->g_hook_list);
+
+       g_free(drop_stack);
+}
index 7e9efaa..fd98d11 100644 (file)
@@ -28,10 +28,11 @@ pkginclude_HEADERS+= \
                ldr.h \
                ldr_exports.h \
                leave.h \
+               libxml.h \
                macros.h \
                mm.h \
-               options.h \
                options-module.h \
+               options.h \
                parent-Directory.h \
                parent-File.h \
                parent-Vfs.h \
@@ -44,4 +45,4 @@ pkginclude_HEADERS+= \
                usecount.h
 
 # for 'include_test.c' handled by Makefile-head.am/.include_test_all.stamp rule by $(COMPILE)
-AM_CFLAGS=$(GNOME_VFS_MODULE_CFLAGS)
+AM_CFLAGS=$(GNOME_VFS_MODULE_CFLAGS) $(LIBXML_CFLAGS)
diff --git a/src/libcaptive/include/captive/libxml.h b/src/libcaptive/include/captive/libxml.h
new file mode 100644 (file)
index 0000000..be2adca
--- /dev/null
@@ -0,0 +1,46 @@
+/* $Id$
+ * Include file for supplementary captive utilities for libxml2
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * 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 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
+ */
+
+
+#ifndef _CAPTIVE_LIBXML_H
+#define _CAPTIVE_LIBXML_H 1
+
+
+#include <glib/gtypes.h>
+#include <libxml/tree.h>       /* for xmlChar */
+
+
+G_BEGIN_DECLS
+
+enum captive_xml_text_reader_node_type {
+       CAPTIVE_XML_TEXT_READER_NODE_TYPE_START=1,
+       CAPTIVE_XML_TEXT_READER_NODE_TYPE_TEXT=3,
+       CAPTIVE_XML_TEXT_READER_NODE_TYPE_COMMENT=8,
+       CAPTIVE_XML_TEXT_READER_NODE_TYPE_END=15,
+       };
+
+struct captive_libxml_string_drop_stack;
+
+gint64 captive_libxml_sscanf_gint64(const gchar *gint64_string);
+const xmlChar *captive_libxml_string_drop(struct captive_libxml_string_drop_stack **drop_stackp,const xmlChar *xml_string);
+void captive_libxml_string_drop_flush(struct captive_libxml_string_drop_stack **drop_stackp);
+
+G_END_DECLS
+
+
+#endif /* _CAPTIVE_LIBXML_H */