-#include "common_stub.hpp"
+#include "utils_stub.hpp"
+
+extern "C" {
+#define CAML_NAME_SPACE
+
+#include <caml/mlvalues.h>
+#include <caml/alloc.h>
+#include <caml/memory.h>
+#include <caml/callback.h>
+#include <caml/fail.h>
+#include <caml/custom.h>
+#include <caml/bigarray.h>
+}
+#include <ctype.h>
extern "C" value caml_clz(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<xml_tree::tag_t*>(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<xml_tree::tag_t*>();
+ 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;
+}