X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fmlminidom%2Fml_minidom.c;h=52a53f2024f4eb7100d79beed5ffc63e55e9a459;hb=a4df9661e15509e5da6ed9c57e3ab6a27a440c3f;hp=7e304ccb5d188b0a0b6570c799f6d48ec9f59833;hpb=95382c071236ad4bf8e42041839493dec191f921;p=helm.git diff --git a/helm/DEVEL/mlminidom/ml_minidom.c b/helm/DEVEL/mlminidom/ml_minidom.c index 7e304ccb5..52a53f202 100644 --- a/helm/DEVEL/mlminidom/ml_minidom.c +++ b/helm/DEVEL/mlminidom/ml_minidom.c @@ -22,13 +22,28 @@ #include #include #include +#include #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)) +#define mDOMDocRef_val(r) (*((mDOMDocRef *)Data_custom_val(r))) + +static value +Val_mDOMConstString(mDOMConstStringRef s) +{ + return copy_string((char *) s); +} + +static value +Val_mDOMString(mDOMStringRef s) +{ + value r = copy_string((char *) s); + mdom_string_free(s); + return r; +} static value ml_some(value v) @@ -53,27 +68,36 @@ ml_mDOMString_of_string(value s) CAMLreturn(s); } +static void +ml_doc_free(value doc) +{ + mdom_doc_free(mDOMDocRef_val(doc)); +} + +static struct custom_operations ops = + {"it.unibo.cs.helm.gtkmathview.mDOMDocRef", + ml_doc_free, + custom_compare_default, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default + }; + value ml_doc_load(value file_name) { mDOMDocRef doc_ref; CAMLparam1(file_name); + CAMLlocal1(val_doc_ref); doc_ref = mdom_load(String_val(file_name), FALSE, NULL); if (doc_ref == NULL) failwith("minidom: could not load document"); + val_doc_ref = alloc_custom(&ops, sizeof(mDOMDocRef), 1, 1); - CAMLreturn((value) doc_ref); -} - -value -ml_doc_unload(value doc) -{ - CAMLparam1(doc); - - mdom_unload((mDOMDocRef) doc); + *((mDOMDocRef *)Data_custom_val(val_doc_ref)) = doc_ref; - CAMLreturn(Val_unit); + CAMLreturn(val_doc_ref); } value @@ -82,11 +106,15 @@ ml_doc_new(value s) mDOMDocRef doc_ref; CAMLparam1(s); + CAMLlocal1(val_doc_ref); doc_ref = mdom_doc_new(mDOMString_val(s)); if (doc_ref == NULL) failwith("minidom: could not create new document"); + val_doc_ref = alloc_custom(&ops, sizeof(mDOMDocRef), 1, 1); - CAMLreturn((value) doc_ref); + *((mDOMDocRef *)Data_custom_val(val_doc_ref)) = doc_ref; + + CAMLreturn(val_doc_ref); } @@ -96,7 +124,7 @@ ml_doc_get_root_node(value doc) mDOMNodeRef root; CAMLparam1(doc); - root = mdom_doc_get_root_node((mDOMDocRef) doc); + root = mdom_doc_get_root_node(mDOMDocRef_val(doc)); if (root == NULL) failwith("minidom: document has no root node!"); CAMLreturn((value) root); @@ -108,7 +136,7 @@ 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)); + ent = mdom_doc_add_entity(mDOMDocRef_val(doc), mDOMString_val(name), mDOMString_val(content)); if (ent == NULL) failwith("minidom: could not add entity"); CAMLreturn((value) ent); @@ -120,7 +148,7 @@ ml_doc_get_entity(value doc, value name) mDOMEntityRef ent; CAMLparam2(doc, name); - ent = mdom_doc_get_entity((mDOMDocRef) doc, mDOMString_val(name)); + ent = mdom_doc_get_entity(mDOMDocRef_val(doc), mDOMString_val(name)); CAMLreturn(Val_option(ent, Val_ptr)); } @@ -140,7 +168,7 @@ value ml_entity_get_content(value ent) { CAMLparam1(ent); - CAMLreturn(Val_mDOMString(mdom_entity_get_content((mDOMEntityRef) ent))); + CAMLreturn(Val_mDOMConstString(mdom_entity_get_content((mDOMEntityRef) ent))); } value @@ -182,7 +210,21 @@ value ml_node_get_name(value node) { CAMLparam1(node); - CAMLreturn(Val_option(mdom_node_get_name((mDOMNodeRef) node), Val_mDOMString)); + CAMLreturn(Val_option(mdom_node_get_name((mDOMNodeRef) node), Val_mDOMConstString)); +} + +value +ml_node_has_attribute(value node, value name) +{ + CAMLparam2(node,name); + CAMLreturn(Val_bool(mdom_node_has_attribute((mDOMNodeRef) node, String_val(name)))); +} + +value +ml_node_has_attribute_ns(value node, value name, value uri) +{ + CAMLparam3(node,name,uri); + CAMLreturn(Val_bool(mdom_node_has_attribute_ns((mDOMNodeRef) node, String_val(name), String_val(uri)))); } value @@ -196,7 +238,7 @@ value ml_node_get_ns_uri(value node) { CAMLparam1(node); - CAMLreturn(Val_option(mdom_node_get_ns_uri((mDOMNodeRef) node), Val_mDOMString)); + CAMLreturn(Val_option(mdom_node_get_ns_uri((mDOMNodeRef) node), Val_mDOMConstString)); } value @@ -268,14 +310,14 @@ value ml_attr_get_name(value attr) { CAMLparam1(attr); - CAMLreturn(Val_option(mdom_attr_get_name((mDOMAttrRef) attr), Val_mDOMString)); + CAMLreturn(Val_option(mdom_attr_get_name((mDOMAttrRef) attr), Val_mDOMConstString)); } value ml_attr_get_ns_uri(value attr) { CAMLparam1(attr); - CAMLreturn(Val_option(mdom_attr_get_ns_uri((mDOMAttrRef) attr), Val_mDOMString)); + CAMLreturn(Val_option(mdom_attr_get_ns_uri((mDOMAttrRef) attr), Val_mDOMConstString)); } value