Пример #1
0
static uim_lisp
get_nth_prediction(uim_lisp ac_, uim_lisp nth_)
{
#ifdef HAS_ANTHY_PREDICTION
  anthy_context_t ac;
  int nth, buflen;
  char *buf;
  uim_lisp buf_;

  ac = get_anthy_context(ac_);
  nth = C_INT(nth_); 

  buflen = anthy_get_prediction(ac, nth, NULL, 0);
  if (buflen == -1)
    uim_fatal_error("anthy_get_prediction() failed");

  buf = uim_malloc(buflen + 1);
  buflen = anthy_get_prediction(ac, nth, buf, buflen + 1);
  if (buflen == -1) {
    free(buf);
    uim_fatal_error("anthy_get_prediction() failed");
  }
  buf_ = MAKE_STR_DIRECTLY(buf);

  return buf_;
#else
  return uim_scm_f();
#endif
}
Пример #2
0
static uim_lisp
get_nth_candidate(uim_lisp ac_, uim_lisp seg_, uim_lisp nth_)
{
  anthy_context_t ac;
  int seg, nth, buflen;
  char *buf;
  uim_lisp buf_;
  
  ac = get_anthy_context(ac_);
  seg = C_INT(seg_);
  nth  = C_INT(nth_);

  buflen = anthy_get_segment(ac, seg, nth, NULL, 0);
  if (buflen == -1)
    uim_fatal_error("anthy_get_segment() failed");

  buf = uim_malloc(buflen + 1);
  buflen = anthy_get_segment(ac, seg, nth, buf, buflen + 1);
  if (buflen == -1) {
    free(buf);
    uim_fatal_error("anthy_get_segment() failed");
  }
  buf_ = MAKE_STR_DIRECTLY(buf);

  return buf_;
}
Пример #3
0
static uim_lisp
create_context(uim_lisp encoding_)
{
  anthy_context_t ac;
  uim_lisp ac_;
  int encoding;

  /* 0: compiled, 1: EUC-JP, 2: UTF-8 */
  encoding = C_INT(encoding_);

  if (!iconv_cd_e2u)
    iconv_cd_e2u = uim_iconv->create("UTF-8", "EUC-JP");

  if (!iconv_cd_u2e)
    iconv_cd_u2e = uim_iconv->create("EUC-JP", "UTF-8");

  ac = anthy_create_context();
  if (!ac)
    uim_fatal_error("anthy_create_context() failed");

  anthy_context_set_encoding(ac, encoding);
  ac_ = MAKE_PTR(ac);
  context_list = uim_scm_callf("cons", "oo", ac_, context_list);

  return ac_;
}
Пример #4
0
void
uim_helper_send_message(int fd, const char *message)
{
  int res;
  int out_len;
  sig_t old_sigpipe;
  char *buf, *bufp;

  if (UIM_CATCH_ERROR_BEGIN())
    return;

#if 0
  if (fd < 0)
    uim_fatal_error("uim_helper_send_message(): invaid fd");
  if (!message)
    uim_fatal_error("uim_helper_send_message(): NULL message");
#else
  /* The condition fd < 0 ordinarily occurs. */
  if (fd < 0 || !message)
    return;
#endif

  uim_asprintf(&buf, "%s\n", message);

  old_sigpipe = signal(SIGPIPE, SIG_IGN);

  out_len = strlen(buf);
  bufp = buf;
  while (out_len > 0) {
    if ((res = write(fd, bufp, out_len)) < 0) {
      if (errno == EAGAIN || errno == EINTR)
	continue;
      perror("uim_helper_send_message(): unhandled error");
      break;
    }

    bufp += res;
    out_len -= res;
  }
  free(buf);
  signal(SIGPIPE, old_sigpipe);

  UIM_CATCH_ERROR_END();

  return;
}
Пример #5
0
char *
uim_strdup(const char *s)
{
  char *copied;

  copied = strdup(s);
  if (!copied)
    uim_fatal_error("strdup() failed");

  return copied;
}
Пример #6
0
void *
uim_calloc(size_t nmemb, size_t size)
{
  void *p;

  p = calloc(nmemb, size);
  if (!p)
    uim_fatal_error("calloc() failed");

  return p;
}
Пример #7
0
void *
uim_malloc(size_t size)
{
  void *p;

  p = malloc(size);
  if (!p)
    uim_fatal_error("malloc() failed");

  return p;
}
Пример #8
0
static anthy_context_t
get_anthy_context(uim_lisp ac_)
{
  anthy_context_t ac;

  ac = C_PTR(ac_);
  if (!ac)
    uim_fatal_error("NULL anthy_context_t");

  return ac;
}
Пример #9
0
static uim_lisp
init_anthy_lib(void)
{
  if (!initialized) {
    if (anthy_init() == -1)
      uim_fatal_error("anthy_init() failed");

    initialized = UIM_TRUE;
  }

  return uim_scm_t();
}
Пример #10
0
static void
validate_segment_index(anthy_context_t ac, int i)
{
  int err;
  struct anthy_conv_stat cs;

  err = anthy_get_stat(ac, &cs);
  if (err)
    uim_fatal_error("anthy_get_stat() failed");
  if (!(0 <= i && i < cs.nr_segment))
    ERROR_OBJ("invalid segment index", MAKE_INT(i));
}
Пример #11
0
void *
uim_realloc(void *p, size_t size)
{
  void *newp;

  newp = realloc(p, size);
  if (!newp) {
    free(p);
    uim_fatal_error("realloc() failed");
  }

  return newp;
}
Пример #12
0
static uim_lisp
get_nr_segments(uim_lisp ac_)
{
  anthy_context_t ac;
  struct anthy_conv_stat cs;
  int err;

  ac = get_anthy_context(ac_);
  err = anthy_get_stat(ac, &cs);
  if (err)
    uim_fatal_error("anthy_get_stat() failed");

  return MAKE_INT(cs.nr_segment);
}
Пример #13
0
int
uim_asprintf(char **ret, const char *fmt, ...)
{
  va_list ap;
  int i;

  va_start(ap, fmt);
  i = vasprintf(ret, fmt, ap);
  va_end(ap);

  if (i < 0 || *ret == NULL)
    uim_fatal_error("asprintf() failed");

  return i;
}
Пример #14
0
static uim_lisp
get_nr_predictions(uim_lisp ac_)
{
#ifdef HAS_ANTHY_PREDICTION
  anthy_context_t ac;
  struct anthy_prediction_stat ps;
  int err;

  ac = get_anthy_context(ac_);

  err = anthy_get_prediction_stat(ac, &ps);
  if (err)
    uim_fatal_error("anthy_get_prediction_stat() failed");
  return MAKE_INT(ps.nr_prediction);
#else
  return uim_scm_f();
#endif
}
Пример #15
0
static uim_lisp
get_segment_length(uim_lisp ac_, uim_lisp seg_)
{
  anthy_context_t ac;
  int seg, err;
  struct anthy_segment_stat ss;

  ac = get_anthy_context(ac_);
  seg = C_INT(seg_);

  validate_segment_index(ac, seg);

  err = anthy_get_segment_stat(ac, seg, &ss);
  if (err)
    uim_fatal_error("anthy_get_segment_stat() failed");

  return MAKE_INT(ss.seg_len);
}
Пример #16
0
static uim_lisp
uim_look_look(uim_lisp isdict_, uim_lisp iscase_, uim_lisp words_, uim_lisp dict_, uim_lisp str_)
{
  const char *dict = REFER_C_STR(dict_);
  const char *str = REFER_C_STR(str_);
  uim_look_ctx *ctx;
  char *dict_str;
  uim_lisp ret_ = uim_scm_f();
  int words = -1;

  ctx = uim_look_init();

  uim_look_set_option_dictionary_order(C_BOOL(isdict_), ctx);
  uim_look_set_option_ignore_case(C_BOOL(iscase_), ctx);

  if (!ctx)
    uim_fatal_error("uim_look_init() failed");

  if (!uim_look_open_dict(dict, ctx))
    return ret_;

  dict_str = uim_strdup(str);

  if (INTP(words_))
    words = C_INT(words_);

  ret_ = uim_scm_null();
  if (uim_look(dict_str, ctx) != 0) {
    struct uim_look_look_internal_args args;

    uim_look_set(ctx);

    args.ctx = ctx;
    args.dict_str = dict_str;
    args.words = words;
    ret_ = (uim_lisp)uim_scm_call_with_gc_ready_stack((uim_gc_gate_func_ptr)uim_look_look_internal,
						      (void *)&args);
  }

  uim_look_finish(ctx);
  free(dict_str);

  return uim_scm_callf("reverse", "o", ret_);
}