抱歉给你添了这么大麻烦
cnhl-thulac.cpp:
#include <iostream>
#include <emacs-module.h>
#include "thulac/include/thulac.h"
using namespace std;
int plugin_is_GPL_compatible;
THULAC t;
bool initialized = false;
static char *
retrieve_string (emacs_env *env, emacs_value str)
{
char *buf = NULL;
ptrdiff_t size = 0;
env->copy_string_contents (env, str, NULL, &size);
buf = (char *) malloc (size);
if (buf == NULL) return NULL;
env->copy_string_contents (env, str, buf, &size);
return buf;
}
static emacs_value
Fcnhl_thulac_module_init(emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data) noexcept
{
if (initialized)
{
t.deinit();
}
string module_path = retrieve_string(env, args[0]);
t.init(module_path.data(), NULL, 0, 0, 0, '_');
cout << "THULAC initialized!" << endl;
initialized = true;
return env->intern(env, "t");
}
static emacs_value
Fcnhl_thulac_string(emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data) noexcept
{
if (initialized != true)
{
cout << "THULAC module hasn't initialized!" << endl;
return env->intern(env, "");
}
string s = retrieve_string(env, args[0]);
THULAC_result r = t.cut(s);
s = t.toString(r);
return env->make_string(env, s.data(), s.length());
}
static void
provide (emacs_env *env, const char *feature)
{
emacs_value Qfeat = env->intern (env, feature);
emacs_value Qprovide = env->intern (env, "provide");
emacs_value args[] = { Qfeat };
env->funcall (env, Qprovide, 1, args);
}
static void
bind_function (emacs_env *env, const char *name, emacs_value Sfun)
{
emacs_value Qfset = env->intern (env, "fset");
emacs_value Qsym = env->intern (env, name);
emacs_value args[] = { Qsym, Sfun };
env->funcall (env, Qfset, 2, args);
}
int
emacs_module_init(struct emacs_runtime *ert) noexcept
{
emacs_env *env = ert->get_environment (ert);
#define DEFUN(lsym, csym, amin, amax, doc, data) \
bind_function (env, lsym, \
env->make_function (env, amin, amax, csym, doc, data))
DEFUN("cnhl-thulac-string", Fcnhl_thulac_string, 1, 1, "Send string to THULAC and return the result.", NULL);
DEFUN("cnhl-thulac-module-init", Fcnhl_thulac_module_init, 1, 1, "Load THULAC module.", NULL);
#undef DEFUN
provide(env, "cnhl-thulac");
return 0;
}
其实cnhl的安装是这样的:找一个目录,把这个目录添加到load-path里,然后把cnhl.el、cnhl-thulac.cpp放在这个文件夹里,再把thulac文件夹克隆到这个目录下,然后在这个目录下执行那条编译命令得到cnhl-thulac.so就算安装好了,之后require一下cnhl就可以使用了
这次发布前我会在termux上好好做测试的