]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mlminidom/ml_minidom.c
This commit was manufactured by cvs2svn to create branch 'start'.
[helm.git] / helm / DEVEL / mlminidom / ml_minidom.c
diff --git a/helm/DEVEL/mlminidom/ml_minidom.c b/helm/DEVEL/mlminidom/ml_minidom.c
new file mode 100644 (file)
index 0000000..7e304cc
--- /dev/null
@@ -0,0 +1,308 @@
+/* Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
+ *
+ * This file is part of mlminidom, the Ocaml binding for minidom.
+ * 
+ * mlminidom 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; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * mlminidom 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 mlminidom; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * 
+ * For details, send a mail to the author.
+ */
+
+#include <assert.h>
+#include <mlvalues.h>
+#include <memory.h>
+
+#include "minidom.h"
+
+#define Val_ptr(p)        ((value) (p))
+#define Val_option(p,f)   ((p != NULL) ? ml_some(f(p)) : Val_unit)
+#define Val_mDOMString(s) (copy_string((char*) (s)))
+#define mDOMString_val(v) ((mDOMStringRef) String_val(v))
+
+static value
+ml_some(value v)
+{
+  CAMLparam1(v);
+  value ret = alloc_small(1,0);
+  Field(ret,0) = v;
+  CAMLreturn(ret);
+}
+
+value
+ml_string_of_mDOMString(value s)
+{
+  CAMLparam1(s);
+  CAMLreturn(s);
+}
+
+value
+ml_mDOMString_of_string(value s)
+{
+  CAMLparam1(s);
+  CAMLreturn(s);
+}
+
+value
+ml_doc_load(value file_name)
+{
+  mDOMDocRef doc_ref;
+
+  CAMLparam1(file_name);
+
+  doc_ref = mdom_load(String_val(file_name), FALSE, NULL);
+  if (doc_ref == NULL) failwith("minidom: could not load document");
+
+  CAMLreturn((value) doc_ref);
+}
+
+value
+ml_doc_unload(value doc)
+{
+  CAMLparam1(doc);
+
+  mdom_unload((mDOMDocRef) doc);
+
+  CAMLreturn(Val_unit);
+}
+
+value
+ml_doc_new(value s)
+{
+  mDOMDocRef doc_ref;
+
+  CAMLparam1(s);
+
+  doc_ref = mdom_doc_new(mDOMString_val(s));
+  if (doc_ref == NULL) failwith("minidom: could not create new document");
+
+  CAMLreturn((value) doc_ref);
+}
+
+
+value
+ml_doc_get_root_node(value doc)
+{
+  mDOMNodeRef root;
+
+  CAMLparam1(doc);
+  root = mdom_doc_get_root_node((mDOMDocRef) doc);
+  if (root == NULL) failwith("minidom: document has no root node!");
+
+  CAMLreturn((value) root);
+}
+
+value
+ml_doc_add_entity(value doc, value name, value content)
+{
+  mDOMEntityRef ent;
+
+  CAMLparam3(doc, name, content);
+  ent = mdom_doc_add_entity((mDOMDocRef) doc, mDOMString_val(name), mDOMString_val(content));
+  if (ent == NULL) failwith("minidom: could not add entity");
+
+  CAMLreturn((value) ent);
+}
+
+value
+ml_doc_get_entity(value doc, value name)
+{
+  mDOMEntityRef ent;
+
+  CAMLparam2(doc, name);
+  ent = mdom_doc_get_entity((mDOMDocRef) doc, mDOMString_val(name));
+
+  CAMLreturn(Val_option(ent, Val_ptr));
+}
+
+value
+ml_doc_get_predefined_entity(value name)
+{
+  mDOMEntityRef ent;
+
+  CAMLparam1(name);
+  ent = mdom_get_predefined_entity(mDOMString_val(name));
+
+  CAMLreturn(Val_option(ent, Val_ptr));
+}
+
+value
+ml_entity_get_content(value ent)
+{
+  CAMLparam1(ent);
+  CAMLreturn(Val_mDOMString(mdom_entity_get_content((mDOMEntityRef) ent)));
+}
+
+value
+ml_node_is_text(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_bool(mdom_node_is_text((mDOMNodeRef) node)));
+}
+
+value
+ml_node_is_element(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_bool(mdom_node_is_element((mDOMNodeRef) node)));
+}
+
+value
+ml_node_is_blank(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_bool(mdom_node_is_blank((mDOMNodeRef) node)));
+}
+
+value
+ml_node_is_entity_ref(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_bool(mdom_node_is_entity_ref((mDOMNodeRef) node)));
+}
+
+value
+ml_node_get_type(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_int(mdom_node_get_type((mDOMNodeRef) node)));
+}
+
+value
+ml_node_get_name(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_option(mdom_node_get_name((mDOMNodeRef) node), Val_mDOMString));
+}
+
+value
+ml_node_get_content(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_option(mdom_node_get_content((mDOMNodeRef) node), Val_mDOMString));
+}
+
+value
+ml_node_get_ns_uri(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_option(mdom_node_get_ns_uri((mDOMNodeRef) node), Val_mDOMString));
+}
+
+value
+ml_node_get_attribute(value node, value name)
+{
+  CAMLparam2(node,name);
+  CAMLreturn(Val_option(mdom_node_get_attribute((mDOMNodeRef) node, String_val(name)), Val_mDOMString));
+}
+
+value
+ml_node_get_attribute_ns(value node, value name, value ns_uri)
+{
+  CAMLparam2(node,name);
+  CAMLreturn(Val_option(mdom_node_get_attribute_ns((mDOMNodeRef) node,
+                                                  String_val(name),
+                                                  String_val(ns_uri)), Val_mDOMString));
+}
+
+value
+ml_node_get_parent(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_option(mdom_node_get_parent((mDOMNodeRef) node), Val_ptr));
+}
+
+value
+ml_node_get_prev_sibling(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_option(mdom_node_get_prev_sibling((mDOMNodeRef) node), Val_ptr));
+}
+
+value
+ml_node_get_next_sibling(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_option(mdom_node_get_next_sibling((mDOMNodeRef) node), Val_ptr));
+}
+
+value
+ml_node_get_first_child(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_option(mdom_node_get_first_child((mDOMNodeRef) node), Val_ptr));
+}
+
+value
+ml_node_get_first_attribute(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_option(mdom_node_get_first_attribute((mDOMNodeRef) node), Val_ptr));
+}
+
+value
+ml_node_is_first(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_bool(mdom_node_is_first((mDOMNodeRef) node)));
+}
+
+value
+ml_node_is_last(value node)
+{
+  CAMLparam1(node);
+  CAMLreturn(Val_bool(mdom_node_is_last((mDOMNodeRef) node)));
+}
+
+value
+ml_attr_get_name(value attr)
+{
+  CAMLparam1(attr);
+  CAMLreturn(Val_option(mdom_attr_get_name((mDOMAttrRef) attr), Val_mDOMString));
+}
+
+value
+ml_attr_get_ns_uri(value attr)
+{
+  CAMLparam1(attr);
+  CAMLreturn(Val_option(mdom_attr_get_ns_uri((mDOMAttrRef) attr), Val_mDOMString));
+}
+
+value
+ml_attr_get_value(value attr)
+{
+  CAMLparam1(attr);
+  CAMLreturn(Val_option(mdom_attr_get_value((mDOMAttrRef) attr), Val_mDOMString));
+}
+
+value
+ml_attr_get_prev_sibling(value attr)
+{
+  CAMLparam1(attr);
+  CAMLreturn(Val_option(mdom_attr_get_prev_sibling((mDOMAttrRef) attr), Val_ptr));
+}
+
+value
+ml_attr_get_next_sibling(value attr)
+{
+  CAMLparam1(attr);
+  CAMLreturn(Val_option(mdom_attr_get_next_sibling((mDOMAttrRef) attr), Val_ptr));
+}
+
+value
+ml_attr_get_parent(value attr)
+{
+  CAMLparam1(attr);
+  CAMLreturn(Val_option(mdom_attr_get_parent((mDOMAttrRef) attr), Val_ptr));
+}
+