+#ifdef HAVE_LIBTHAI
+
+#include <thai/thbrk.h>
+
+static int
+init_wordseg_library (void)
+{
+ return 0;
+}
+
+static void
+fini_wordseg_library (void)
+{
+ return;
+}
+
+static MTextProperty *
+wordseg_propertize (MText *mt, int pos, int from, int to, unsigned char *tis)
+{
+ int len = to - from;
+ int *breaks = alloca ((sizeof (int)) * len);
+ int count = th_brk ((thchar_t *) tis, breaks, len);
+ MTextProperty *prop = NULL;
+
+ if (count == 0)
+ {
+ prop = mtext_property (Mthai_wordseg, Mt,
+ MTEXTPROP_VOLATILE_WEAK | MTEXTPROP_NO_MERGE);
+ mtext_attach_property (mt, from, to, prop);
+ M17N_OBJECT_UNREF (prop);
+ }
+ else
+ {
+ int last, i;
+ MTextProperty *this;
+
+ for (i = 0, last = from; i < count; i++)
+ {
+ this = mtext_property (Mthai_wordseg, Mt,
+ MTEXTPROP_VOLATILE_WEAK | MTEXTPROP_NO_MERGE);
+ mtext_attach_property (mt, last, from + breaks[i], this);
+ if (pos >= last && pos < from + breaks[i])
+ prop = this;
+ M17N_OBJECT_UNREF (this);
+ last = from + breaks[i];
+ }
+ if (last < to)
+ {
+ this = mtext_property (Mthai_wordseg, Mt,
+ MTEXTPROP_VOLATILE_WEAK | MTEXTPROP_NO_MERGE);
+ mtext_attach_property (mt, last, to, this);
+ if (pos >= last && pos < to)
+ prop = this;
+ M17N_OBJECT_UNREF (this);
+ }
+ }
+
+ if (! prop)
+ mdebug_hook ();
+ return prop;
+}
+
+#elif HAVE_WORDCUT