X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Futils_stub.cpp;h=2ea3feb54d2b6392ed8fa559d7420c84712cbeaa;hb=refs%2Fheads%2Fmaster;hp=dc3688af639e9b514d587ca992d3a5b9ac73c8a5;hpb=83e9f9d8f219fece86afbedd1332d5ad97971d1c;p=SXSI%2Fxpathcomp.git diff --git a/src/utils_stub.cpp b/src/utils_stub.cpp index dc3688a..2ea3feb 100644 --- a/src/utils_stub.cpp +++ b/src/utils_stub.cpp @@ -1,4 +1,17 @@ -#include "common_stub.hpp" +#include "utils_stub.hpp" + +extern "C" { +#define CAML_NAME_SPACE + +#include +#include +#include +#include +#include +#include +#include +} +#include extern "C" value caml_clz(value i) { @@ -9,3 +22,68 @@ extern "C" value caml_leading_bit(value i) { return Val_long( ( 1 << (sizeof(unsigned long)*8 - __builtin_clzl(Long_val(i)) - 1))); } + + +static char * rtrim(char *str) +{ + char *ptr; + int len; + + len = strlen(str); + for (ptr = str + len - 1; ptr >= str && isspace((int)*ptr ); --ptr); + ptr[1] = '\0'; + + return str; +} + +static char * ltrim(char *str) +{ + char *ptr; + int len; + + for (ptr = str; *ptr && isspace((int)*ptr); ++ptr); + + len = strlen(ptr); + memmove(str, ptr, len + 1); + + return str; +} +extern "C" value caml_trim(value s) +{ + CAMLparam1(s); + CAMLlocal1(res); + char * ptr; + char * str = String_val(s); + ptr = rtrim(str); + str = ltrim(ptr); + res = caml_copy_string(str); + CAMLreturn(res); +} + +xml_tree::tag_t*& TAGLIST(value x) +{ + return Obj_val(x); +} + + + +static void finalize_tag_list(value x) +{ + xml_tree::tag_t * t = TAGLIST(x); + delete [] t; +} + +extern "C" value caml_tag_list_alloc(value length) +{ + CAMLparam1(length); + CAMLlocal1(tlist); + tlist = sxsi_alloc_custom(); + TAGLIST(tlist) = new xml_tree::tag_t[Int_val(length)]; + CAMLreturn (tlist); +} + +NoAlloc extern "C" value caml_tag_list_set(value tl, value i, value v) +{ + TAGLIST(tl)[Int_val(i)] = Int_val(v); + return Val_unit; +}