From 133ffec00f2a97ac6851072e4c3083766f17ab52 Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Tue, 13 Nov 2001 18:02:19 +0000 Subject: [PATCH] mlminidom 0.0.2 for minidom 0.1.3 --- helm/DEVEL/mlminidom/.depend | 7 ++ helm/DEVEL/mlminidom/META.in | 5 ++ helm/DEVEL/mlminidom/Makefile.in | 106 ++++++++++++++++++------------ helm/DEVEL/mlminidom/configure.in | 3 +- helm/DEVEL/mlminidom/minidom.ml | 4 +- helm/DEVEL/mlminidom/minidom.mli | 4 +- helm/DEVEL/mlminidom/ml_minidom.c | 82 +++++++++++++++++------ helm/DEVEL/mlminidom/ml_minidom.h | 1 - helm/DEVEL/mlminidom/ominidom.ml | 4 ++ helm/DEVEL/mlminidom/ominidom.mli | 2 + helm/DEVEL/mlminidom/test.ml | 12 ++-- 11 files changed, 158 insertions(+), 72 deletions(-) create mode 100644 helm/DEVEL/mlminidom/.depend create mode 100644 helm/DEVEL/mlminidom/META.in diff --git a/helm/DEVEL/mlminidom/.depend b/helm/DEVEL/mlminidom/.depend new file mode 100644 index 000000000..df1b3a2eb --- /dev/null +++ b/helm/DEVEL/mlminidom/.depend @@ -0,0 +1,7 @@ +minidom.cmo: minidom.cmi +minidom.cmx: minidom.cmi +ominidom.cmo: minidom.cmi ominidom.cmi +ominidom.cmx: minidom.cmx ominidom.cmi +test.cmo: minidom.cmi +test.cmx: minidom.cmx +ominidom.cmi: minidom.cmi diff --git a/helm/DEVEL/mlminidom/META.in b/helm/DEVEL/mlminidom/META.in new file mode 100644 index 000000000..42d999a5b --- /dev/null +++ b/helm/DEVEL/mlminidom/META.in @@ -0,0 +1,5 @@ +requires="" +version="@VERSION@" +archive(byte)="mlminidom.cma ml_minidom.o" +archive(native)="mlminidom.cmxa ml_minidom.o" +linkopts="" diff --git a/helm/DEVEL/mlminidom/Makefile.in b/helm/DEVEL/mlminidom/Makefile.in index 0418faba2..e82872538 100644 --- a/helm/DEVEL/mlminidom/Makefile.in +++ b/helm/DEVEL/mlminidom/Makefile.in @@ -3,17 +3,29 @@ VERSION = @VERSION@ INCLUDEDIR = @OCAML_INCLUDE_DIR@ LIBDIR = @OCAML_LIB_DIR@ PREFIX = -INSTALLDIR = $(PREFIX)$(LIBDIR)/mlminidom -OBJECTS = minidom.cmi minidom.cmo ml_minidom.o ominidom.cmi ominidom.cmo +INSTALLDIR = $(PREFIX)$(LIBDIR)/$(PACKAGE) +OBJECTS_C = ml_minidom.o +OBJECTS = minidom.cmo ominidom.cmo OBJECTS_OPT = minidom.cmx ominidom.cmx -INST = ml_minidom.h minidom.mli ml_minidom.h -INST_OPT = minidom.o ominidom.o -DIST_FILES = Makefile.in configure.in configure *.ml *.mli test.xml ml_minidom.c ml_minidom.h +INST = ml_minidom.h minidom.mli minidom.cmi ominidom.mli ominidom.cmi META +DIST_FILES = Makefile.in configure.in configure *.ml *.mli test.xml ml_minidom.c ml_minidom.h META.in mlminidom.spec.in .depend DOC_FILES = AUTHORS COPYING ChangeLog NEWS README +REQUIRES = +PREDICATES = +OCAMLC = ocamlfind ocamlc +OCAMLOPT = ocamlfind ocamlopt +OCAMLDEP = ocamldep -all: $(OBJECTS) test +ARCHIVE = $(PACKAGE).cma +ARCHIVE_C = $(PACKAGE).a +ARCHIVE_OPT = $(PACKAGE).cmxa -opt: $(OBJECTS_OPT) test.opt +TMPDIR = .test +TMPPKGDIR = $(TMPDIR)/$(PACKAGE) + +all: $(OBJECTS_C) $(ARCHIVE) test + +opt: $(OBJECTS_C) $(ARCHIVE_OPT) test.opt dist: rm -rf $(PACKAGE)-$(VERSION) @@ -25,49 +37,61 @@ dist: ml_minidom.o: ml_minidom.c gcc -c -I$(INCLUDEDIR) `glib-config --cflags` `minidom-config --cflags` $< -minidom.cmi: minidom.mli - ocamlc -c $< - -minidom.cmo: minidom.ml minidom.cmi - ocamlc -c $< - -minidom.cmx: minidom.ml minidom.cmi - ocamlopt -c $< - -ominidom.cmi: ominidom.mli - ocamlc -c $< - -ominidom.cmo: ominidom.ml - ocamlc -c $< - -ominidom.cmx: ominidom.ml - ocamlopt -c $< - -test.cmo: test.ml minidom.cmo - ocamlc -c test.ml - -test.cmx: test.ml minidom.cmx - ocamlopt -c test.ml - -test: test.cmo minidom.cmo ml_minidom.o - ocamlc -custom -o test minidom.cmo test.cmo ml_minidom.o \ +.SUFFIXES: .cmo .cmi .cmx .ml .mli + +.ml.cmo: + $(OCAMLC) -package "$(REQUIRES)" -predicates "$(PREDICATES)" \ + -c $< +.mli.cmi: + $(OCAMLC) -package "$(REQUIRES)" -predicates "$(PREDICATES)" \ + -c $< +.ml.cmx: + $(OCAMLOPT) -package "$(REQUIRES)" -predicates "$(PREDICATES)" \ + -c $< + +depend: *.ml *.mli + $(OCAMLDEP) *.ml *.mli >.depend +include .depend + +$(ARCHIVE): $(OBJECTS) + $(OCAMLC) -a -custom -package "$(REQUIRES)" -linkpkg \ + -predicates "$(PREDICATES)" -o $@ $< \ -cclib "`glib-config --libs` `minidom-config --libs`" -test.opt: test.cmx minidom.cmx ml_minidom.o - ocamlopt -o test.opt minidom.cmx test.cmx ml_minidom.o \ +$(ARCHIVE_OPT): $(OBJECTS_OPT) + $(OCAMLOPT) -a -package "$(REQUIRES)" -linkpkg \ + -predicates "$(PREDICATES)" -o $@ $< \ -cclib "`glib-config --libs` `minidom-config --libs`" +test: test.ml $(OBJECTS_C) $(ARCHIVE) + mkdir -p $(TMPPKGDIR) + cp $(OBJECTS_C) $(ARCHIVE) $(INST) $(TMPPKGDIR) + cp test.ml $(TMPDIR) + cd $(TMPDIR) ; export OCAMLPATH=. ; \ + $(OCAMLC) -package "$(PACKAGE)" -linkpkg -predicates "" -o $@ test.ml + mv $(TMPDIR)/$@ . + rm -r $(TMPDIR) + +test.opt: test.ml $(OBJECTS_C) $(ARCHIVE_C) $(ARCHIVE_OPT) + mkdir -p $(TMPPKGDIR) + cp $(OBJECTS_C) $(ARCHIVE_C) $(ARCHIVE_OPT) $(INST) $(TMPPKGDIR) + cp test.ml $(TMPDIR) + cd $(TMPDIR) ; export OCAMLPATH=. ; \ + $(OCAMLOPT) -package "$(PACKAGE)" -linkpkg -predicates "" -o $@ test.ml + mv $(TMPDIR)/$@ . + rm -r $(TMPDIR) + install: - if test -d $(INSTALLDIR); then : ; else mkdir -p $(INSTALLDIR); fi - cp $(OBJECTS) $(INST) $(INSTALLDIR) - -test -x /usr/bin/ocamlopt && cp $(OBJECTS_OPT) $(INST_OPT) $(INSTALLDIR) + test ! -f $(ARCHIVE_OPT) || extra="$(ARCHIVE_C) $(ARCHIVE_OPT)" ; \ + ocamlfind install $(PACKAGE) $(OBJECTS_C) $(ARCHIVE) $(INST) $$extra uninstall: - rm -rf $(INSTALLDIR) + ocamlfind remove $(PACKAGE) clean: - rm -f *.o *.cm? test test.opt + rm -f *.o *.cm? test test.opt mlminidom.cma mlminidom.cmxa mlminidom.a + rm -rf $(TMPDIR) distclean: clean - rm -f config.log config.cache config.status Makefile + rm -f config.log config.cache config.status Makefile META mlminidom.spec diff --git a/helm/DEVEL/mlminidom/configure.in b/helm/DEVEL/mlminidom/configure.in index be862e256..bf6dcdcb1 100644 --- a/helm/DEVEL/mlminidom/configure.in +++ b/helm/DEVEL/mlminidom/configure.in @@ -4,7 +4,7 @@ PACKAGE=mlminidom MLMINIDOM_MAJOR_VERSION=0 MLMINIDOM_MINOR_VERSION=0 -MLMINIDOM_MICRO_VERSION=1 +MLMINIDOM_MICRO_VERSION=2 MLMINIDOM_VERSION=$MLMINIDOM_MAJOR_VERSION.$MLMINIDOM_MINOR_VERSION.$MLMINIDOM_MICRO_VERSION VERSION=$MLMINIDOM_VERSION @@ -40,4 +40,5 @@ AC_SUBST(OCAML_LIB_DIR) AC_OUTPUT([ Makefile mlminidom.spec + META ]) diff --git a/helm/DEVEL/mlminidom/minidom.ml b/helm/DEVEL/mlminidom/minidom.ml index 118b0d070..1c8e2f7b8 100644 --- a/helm/DEVEL/mlminidom/minidom.ml +++ b/helm/DEVEL/mlminidom/minidom.ml @@ -30,8 +30,6 @@ external mDOMString_of_string : string -> mDOMString = "ml_mDOMString_of_string" external mDOMString_eq : string -> string -> bool = "ml_mDOMString_eq" external doc_load : string -> mDOMDoc = "ml_doc_load" -external doc_unload : mDOMDoc -> unit = "ml_doc_unload" - external doc_new : mDOMString -> mDOMDoc = "ml_doc_new" external doc_get_root_node : mDOMDoc -> mDOMNode = "ml_doc_get_root_node" @@ -49,6 +47,8 @@ external node_get_name : mDOMNode -> mDOMString option = "ml_node_get_name" external node_get_ns_uri : mDOMNode -> mDOMString option = "ml_node_get_ns_uri" external node_get_attribute : mDOMNode -> mDOMString -> mDOMString option = "ml_node_get_attribute" external node_get_attribute_ns : mDOMNode -> mDOMString -> mDOMString -> mDOMString option = "ml_node_get_attribute_ns" +external node_has_attribute : mDOMNode -> mDOMString -> bool = "ml_node_has_attribute" +external node_has_attribute_ns : mDOMNode -> mDOMString -> mDOMString -> bool = "ml_node_has_attribute_ns" external node_get_content : mDOMNode -> mDOMString option = "ml_node_get_content" external node_get_parent : mDOMNode -> mDOMNode option = "ml_node_get_parent" external node_get_prev_sibling : mDOMNode -> mDOMNode option = "ml_node_get_prev_sibling" diff --git a/helm/DEVEL/mlminidom/minidom.mli b/helm/DEVEL/mlminidom/minidom.mli index 36355af31..4e82b73c6 100644 --- a/helm/DEVEL/mlminidom/minidom.mli +++ b/helm/DEVEL/mlminidom/minidom.mli @@ -30,8 +30,6 @@ external mDOMString_of_string : string -> mDOMString = "ml_mDOMString_of_string" external mDOMString_eq : string -> string -> bool = "ml_mDOMString_eq" external doc_load : string -> mDOMDoc = "ml_doc_load" -external doc_unload : mDOMDoc -> unit = "ml_doc_unload" - external doc_new : mDOMString -> mDOMDoc = "ml_doc_new" external doc_get_root_node : mDOMDoc -> mDOMNode = "ml_doc_get_root_node" @@ -49,6 +47,8 @@ external node_get_name : mDOMNode -> mDOMString option = "ml_node_get_name" external node_get_ns_uri : mDOMNode -> mDOMString option = "ml_node_get_ns_uri" external node_get_attribute : node:mDOMNode -> name:mDOMString -> mDOMString option = "ml_node_get_attribute" external node_get_attribute_ns : node:mDOMNode -> name:mDOMString -> ns_uri:mDOMString -> mDOMString option = "ml_node_get_attribute_ns" +external node_has_attribute : node:mDOMNode -> name:mDOMString -> bool = "ml_node_has_attribute" +external node_has_attribute_ns : node:mDOMNode -> name:mDOMString -> ns_uri:mDOMString -> bool = "ml_node_has_attribute_ns" external node_get_content : mDOMNode -> mDOMString option = "ml_node_get_content" external node_get_parent : mDOMNode -> mDOMNode option = "ml_node_get_parent" external node_get_prev_sibling : mDOMNode -> mDOMNode option = "ml_node_get_prev_sibling" 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 diff --git a/helm/DEVEL/mlminidom/ml_minidom.h b/helm/DEVEL/mlminidom/ml_minidom.h index 4b92566b9..f32e8c6f1 100644 --- a/helm/DEVEL/mlminidom/ml_minidom.h +++ b/helm/DEVEL/mlminidom/ml_minidom.h @@ -26,7 +26,6 @@ #ifndef Val_option #define Val_option(p,f) ((p != NULL) ? ml_some(f(p)) : Val_unit) #endif /* Val_option */ -#define Val_mDOMString(s) (copy_string((char*) (s))) #define mDOMString_val(v) ((mDOMStringRef) String_val(v)) #define mDOMNode_val(v) ((mDOMNodeRef) v) diff --git a/helm/DEVEL/mlminidom/ominidom.ml b/helm/DEVEL/mlminidom/ominidom.ml index 343dfa3be..5f408f7d3 100644 --- a/helm/DEVEL/mlminidom/ominidom.ml +++ b/helm/DEVEL/mlminidom/ominidom.ml @@ -99,6 +99,10 @@ and o_mDOMNode (node : Minidom.mDOMNode) = with | Some x -> Some (new o_mDOMString x) | None -> None + method has_attribute (name : o_mDOMString) = + Minidom.node_has_attribute node (name#get_dom_string) + method has_attribute_ns (name : o_mDOMString) (uri : o_mDOMString) = + Minidom.node_has_attribute_ns node (name#get_dom_string) (uri#get_dom_string) method get_content = match Minidom.node_get_content node with | Some x -> Some (new o_mDOMString x) diff --git a/helm/DEVEL/mlminidom/ominidom.mli b/helm/DEVEL/mlminidom/ominidom.mli index 42b7d67ea..e555a860c 100644 --- a/helm/DEVEL/mlminidom/ominidom.mli +++ b/helm/DEVEL/mlminidom/ominidom.mli @@ -54,6 +54,8 @@ and o_mDOMNode : Minidom.mDOMNode -> method get_attribute : o_mDOMString -> o_mDOMString option method get_attribute_ns : o_mDOMString -> o_mDOMString -> o_mDOMString option + method has_attribute : o_mDOMString -> bool + method has_attribute_ns : o_mDOMString -> o_mDOMString -> bool method get_attributes : o_mDOMAttr list method get_children : o_mDOMNode list method get_content : o_mDOMString option diff --git a/helm/DEVEL/mlminidom/test.ml b/helm/DEVEL/mlminidom/test.ml index 1a239f8f6..a906c0552 100644 --- a/helm/DEVEL/mlminidom/test.ml +++ b/helm/DEVEL/mlminidom/test.ml @@ -32,14 +32,17 @@ let check_attribute_ns attr = in match parent,ns_uri,attr_name,attr_value with Some parent_node,Some uri,Some attribute_name,Some attribute_value -> - let attr_value = Minidom.node_get_attribute_ns parent_node attribute_name uri + let attr_info = + (Minidom.node_get_attribute_ns parent_node attribute_name uri, + Minidom.node_has_attribute_ns parent_node attribute_name uri) in begin - match attr_value with - Some attr1 -> + match attr_info with + Some attr1, true -> Printf.printf "found the attribute with ns %s (was %s)\n" (Minidom.string_of_mDOMString attr1) (Minidom.string_of_mDOMString attribute_value) - | None -> + | None, false -> Printf.printf "attribute not found (uri was %s)!!!!\n" (Minidom.string_of_mDOMString uri) + | _,_ -> assert false end | _ -> Printf.printf "parent_node == NULL || uri == NULL || attribute_name == NULL || attribute_value == NULL\n" @@ -101,4 +104,3 @@ let rec print_node n node = ;; print_node 0 root;; - -- 2.39.2