1 /**************************************
4 * A Test Ocaml Driver which calls the C++ methods and
5 * adds a C wrapper interface with OCaml code.
11 /* OCaml memory managment */
13 #include <caml/mlvalues.h>
14 #include <caml/alloc.h>
15 #include <caml/memory.h>
16 #include <caml/callback.h>
17 #include <caml/fail.h>
20 #include "XMLDocShredder.h"
22 #include "TextCollection/TextCollection.h"
25 #define CAMLRAISECPP(e) (caml_failwith( ((e).what())))
26 #define NOT_IMPLEMENTED(s) (caml_failwith(s))
27 #define XMLTREE(x) ((XMLTree *)(x))
28 #define TEXTCOLLECTION(x)
29 #define TREENODEVAL(i) ((treeNode) (Int_val(i)))
31 extern "C" CAMLprim value caml_call_shredder_uri(value uri){
34 char *fn = String_val(uri);
36 XMLDocShredder shredder(fn);
37 shredder.processStartDocument(fn);
39 shredder.processEndDocument();
40 doc = (value) shredder.storageIfc_->returnDocument();
44 catch (const std::exception& e){
50 extern "C" CAMLprim value caml_call_shredder_string(value data){
53 unsigned int ln = string_length(data);
54 unsigned char *fn = (unsigned char*) String_val(data);
57 XMLDocShredder shredder(fn,ln);
58 shredder.processStartDocument("");
60 shredder.processEndDocument();
61 doc = (value) shredder.storageIfc_->returnDocument();
65 catch (const std::exception& e) {
70 extern "C" CAMLprim value caml_text_collection_get_text(value tc, value id){
73 const char* txt = (const char*) ((TextCollection*) tc)->GetText((DocID) Int_val(id));
74 CAMLreturn (caml_copy_string(txt));
77 extern "C" CAMLprim value caml_xml_tree_root(value tree){
79 CAMLreturn (TREENODEVAL(XMLTREE(tree)->Root()));
81 extern "C" CAMLprim value caml_xml_tree_text_collection(value tree){
83 CAMLreturn((value) XMLTREE(tree)->GetTextCollection());
86 extern "C" CAMLprim value caml_xml_tree_first_child(value tree, value id){
89 CAMLreturn(Val_int (XMLTREE(tree)->FirstChild(TREENODEVAL(id))));
91 extern "C" CAMLprim value caml_xml_tree_next_sibling(value tree, value id){
93 CAMLreturn(Val_int (XMLTREE(tree)->NextSibling(TREENODEVAL(id))));
96 extern "C" CAMLprim value caml_xml_tree_prev_text(value tree, value id){
99 CAMLreturn(Val_int((XMLTREE(tree)->PrevText(TREENODEVAL(id)))));
102 extern "C" CAMLprim value caml_xml_tree_next_text(value tree, value id){
104 CAMLreturn(Val_int((XMLTREE(tree)->NextText(TREENODEVAL(id)))));
106 extern "C" CAMLprim value caml_xml_tree_my_text(value tree, value id){
108 CAMLreturn(Val_int((XMLTREE(tree)->MyText(TREENODEVAL(id)))));
111 extern "C" CAMLprim value caml_xml_tree_text_xml_id(value tree, value id){
114 NOT_IMPLEMENTED("caml_xml_tree_text_xml_id");
115 CAMLreturn (Val_unit);
117 extern "C" CAMLprim value caml_xml_tree_node_xml_id(value tree, value id){
120 NOT_IMPLEMENTED("caml_xml_tree_node_xml_id");
121 CAMLreturn (Val_unit);
123 extern "C" CAMLprim value caml_xml_tree_tag(value tree, value id){
126 tag =(const char*) XMLTREE(tree)->GetTagName(XMLTREE(tree)->Tag(TREENODEVAL(id)));
128 CAMLreturn (caml_copy_string(tag));
130 extern "C" CAMLprim value caml_xml_tree_nullt(value unit){