X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2FOCamlDriver.cpp;h=cd7fed45e69d59b02f5ee0058b9844dc76b0954a;hb=7166a99542af5ad2f5b53fe9fa9e5164dff7cfe5;hp=bb007a8ec7a8429c5e7a56c8d16d3c89784cfb09;hpb=813b239795aac1844eb233dab7f8f98d8dba845e;p=SXSI%2Fxpathcomp.git diff --git a/src/OCamlDriver.cpp b/src/OCamlDriver.cpp index bb007a8..cd7fed4 100644 --- a/src/OCamlDriver.cpp +++ b/src/OCamlDriver.cpp @@ -20,6 +20,7 @@ #include "XMLTree.h" #include "XMLTreeBuilder.h" +#include "Grammar.h" #include "Utils.h" #include "common_stub.hpp" @@ -31,6 +32,8 @@ #define XMLTREEBUILDER(x) (Obj_val(x)) +#define GRAMMAR(x) (Obj_val(x)) + #define TREENODEVAL(i) ((treeNode) (Int_val(i))) #define TAGVAL(i) ((TagType) (Int_val(i))) @@ -40,6 +43,7 @@ extern "C" { #include #include +#include } @@ -152,16 +156,13 @@ extern "C" value caml_xml_tree_save(value tree,value fd, value name){ extern "C" value caml_xml_tree_load(value fd, value name, value load_tc,value sf){ CAMLparam4(fd, name, load_tc, sf); - CAMLlocal2(result,tmp); + CAMLlocal1(result); XMLTree * tree; try { tree = XMLTree::Load(Int_val(fd),Bool_val(load_tc),Int_val(sf), String_val(name)); result = sxsi_alloc_custom(); - Obj_val(result) = tree; - tmp = sxsi_alloc_custom(); - Obj_val(tmp) = 3l; CAMLreturn(result); } catch (const std::exception& e){ CAMLRAISEMSG(e.what()); } @@ -281,6 +282,10 @@ NoAlloc extern "C" value caml_xml_tree_next_element(value tree, value node){ return (Val_int(XMLTREE(tree)->NextElement(TREENODEVAL(node)))); } +NoAlloc extern "C" value caml_xml_tree_next_node_before(value tree, value node, value ctx){ + return (Val_int(XMLTREE(tree)->NextNodeBefore(TREENODEVAL(node), TREENODEVAL(ctx)))); +} + NoAlloc extern "C" value caml_xml_tree_prev_sibling(value tree, value node){ return (Val_int(XMLTREE(tree)->PrevSibling(TREENODEVAL(node)))); } @@ -889,3 +894,25 @@ BV_QUERY(suffix, Suffix) BV_QUERY(equals, Equals) BV_QUERY(contains, Contains) BV_QUERY(lessthan, LessThan) + + + +//////////////////////////////////////////// Grammar stuff + +extern "C" value caml_grammar_load(value file, value load_bp) +{ + CAMLparam2(file, load_bp); + CAMLlocal1(result); + Grammar *grammar; + int f1 = Int_val(file); + int f2 = dup(f1); + FILE * fd = fdopen(f2, "r"); + if (fd == NULL) + CAMLRAISEMSG("Error opening grammar file"); + grammar = Grammar::load(fd, Bool_val(load_bp)); + fclose(fd); + result = sxsi_alloc_custom(); + Obj_val(result) = grammar; + CAMLreturn(result); +} +