X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2FOCamlDriver.cpp;h=cd7fed45e69d59b02f5ee0058b9844dc76b0954a;hb=7166a99542af5ad2f5b53fe9fa9e5164dff7cfe5;hp=8eb3a22ce681aaef83cfa7d9839535adb93dbea3;hpb=ff13d22656fdbdffb2d909192bd17ba135606224;p=SXSI%2Fxpathcomp.git diff --git a/src/OCamlDriver.cpp b/src/OCamlDriver.cpp index 8eb3a22..cd7fed4 100644 --- a/src/OCamlDriver.cpp +++ b/src/OCamlDriver.cpp @@ -20,20 +20,19 @@ #include "XMLTree.h" #include "XMLTreeBuilder.h" +#include "Grammar.h" #include "Utils.h" #include "common_stub.hpp" -extern "C" { -#include -} - #define CAMLRAISEMSG(msg) (sxsi_raise_msg((char*) (msg))) -#define XMLTREE(x) (Obj_val(x)) +#define XMLTREE(x) (Obj_val(x)) + +#define HSET(x) (Obj_val(x)) -#define HSET(x) (Obj_val(x)) +#define XMLTREEBUILDER(x) (Obj_val(x)) -#define XMLTREEBUILDER(x) (Obj_val(x)) +#define GRAMMAR(x) (Obj_val(x)) #define TREENODEVAL(i) ((treeNode) (Int_val(i))) @@ -44,6 +43,7 @@ extern "C" { extern "C" { #include #include +#include } @@ -56,8 +56,9 @@ extern "C" value caml_xml_tree_builder_create(value unit) { CAMLparam1(unit); CAMLlocal1(result); - result = sxsi_alloc_custom(); - Obj_val(result) = new XMLTreeBuilder(); + result = sxsi_alloc_custom(); + Obj_val(result) = new XMLTreeBuilder(); + CAMLreturn(result); } @@ -102,8 +103,8 @@ extern "C" value caml_xml_tree_builder_close_document(value vbuilder) XMLTree * tree = XMLTREEBUILDER(vbuilder)->CloseDocument(); if (tree == NULL) CAMLRAISEMSG("CloseDocument"); - result = sxsi_alloc_custom(); - Obj_val(result) = tree; + result = sxsi_alloc_custom(); + Obj_val(result) = tree; CAMLreturn (result); } @@ -158,9 +159,10 @@ extern "C" value caml_xml_tree_load(value fd, value name, value load_tc,value s 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; + result = sxsi_alloc_custom(); + Obj_val(result) = tree; CAMLreturn(result); } catch (const std::exception& e){ CAMLRAISEMSG(e.what()); } @@ -280,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)))); } @@ -416,8 +422,8 @@ NoAlloc extern "C" value caml_unordered_set_length(value hset){ extern "C" value caml_unordered_set_alloc(value unit){ CAMLparam1(unit); CAMLlocal1(hset); - hset = sxsi_alloc_custom(); - Obj_val(hset) = new TagIdSet(); + hset = sxsi_alloc_custom(); + Obj_val(hset) = new TagIdSet(); CAMLreturn (hset); } @@ -888,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); +} +