--- /dev/null
+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
--- /dev/null
+requires=""
+version="@VERSION@"
+archive(byte)="mlminidom.cma ml_minidom.o"
+archive(native)="mlminidom.cmxa ml_minidom.o"
+linkopts=""
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)
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
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
AC_OUTPUT([
Makefile
mlminidom.spec
+ META
])
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"
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"
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"
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"
#include <assert.h>
#include <mlvalues.h>
#include <memory.h>
+#include <custom.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))
+#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)
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
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);
}
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);
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);
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));
}
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
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
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
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
#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)
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)
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
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"
;;
print_node 0 root;;
-