static uim_lisp rk_find_partial_seq(uim_lisp seq, uim_lisp rules) { for (; !uim_scm_nullp(rules); rules = uim_scm_cdr(rules)) { uim_lisp rule = uim_scm_car(rules); uim_lisp key = uim_scm_car(uim_scm_car(rule)); if (TRUEP(str_seq_partial(seq, key))) { return rule; } } return uim_scm_f(); }
static uim_lisp file_stat_mode(uim_lisp filename, mode_t mode) { struct stat st; int err; err = stat(REFER_C_STR(filename), &st); if (err) return uim_scm_f(); /* intentionally returns #f instead of error */ return MAKE_BOOL((st.st_mode & mode) == mode); }
static uim_lisp intl_bind_textdomain_codeset(uim_lisp domainname, uim_lisp codeset) { const char *c_current_codeset, *c_codeset; uim_lisp current_codeset; if (!STRP(domainname) || !(STRP(codeset) || FALSEP(codeset))) return uim_scm_f(); c_codeset = (FALSEP(codeset)) ? NULL : REFER_C_STR(codeset); c_current_codeset = bind_textdomain_codeset(REFER_C_STR(domainname), c_codeset); if (c_current_codeset) { current_codeset = MAKE_STR(c_current_codeset); } else { current_codeset = uim_scm_f(); } return current_codeset; }
static uim_lisp c_process_waitpid(uim_lisp pid_, uim_lisp options_) { uim_lisp ret_ = uim_scm_null(); int status; ret_ = MAKE_INT(waitpid(C_INT(pid_), &status, C_INT(options_))); if (WIFEXITED(status)) return LIST5(ret_, uim_scm_t(), uim_scm_f(), uim_scm_f(), MAKE_INT(WEXITSTATUS(status))); else if (WIFSIGNALED(status)) return LIST5(ret_, uim_scm_f(), uim_scm_t(), uim_scm_f(), MAKE_INT(WTERMSIG(status))); #ifdef WIFSTOPPED else if (WIFSTOPPED(status)) return LIST5(ret_, uim_scm_f(), uim_scm_f(), uim_scm_t(), MAKE_INT(WSTOPSIG(status))); #endif return LIST5(ret_, uim_scm_f(), uim_scm_f(), uim_scm_f(), MAKE_INT(status)); }
static uim_lisp resize_segment(uim_lisp ac_, uim_lisp seg_, uim_lisp delta_) { anthy_context_t ac; int seg, delta; ac = get_anthy_context(ac_); seg = C_INT(seg_); delta = C_INT(delta_); anthy_resize_segment(ac, seg, delta); return uim_scm_f(); }
static uim_lisp im_set_encoding(uim_lisp uc_, uim_lisp enc_) { uim_context uc; const char *enc; uc = retrieve_uim_context(uc_); enc = REFER_C_STR(enc_); uim_set_encoding(uc, enc); return uim_scm_f(); }
static uim_lisp commit_segment(uim_lisp ac_, uim_lisp seg_, uim_lisp nth_) { anthy_context_t ac; int seg, nth; ac = get_anthy_context(ac_); seg = C_INT(seg_); nth = C_INT(nth_); anthy_commit_segment(ac, seg, nth); return uim_scm_f(); }
static uim_lisp c_dlopen(uim_lisp path_, uim_lisp mode_) { const char *s; void *handle = dlopen(REFER_C_STR(path_), C_INT(mode_)); if ((s = dlerror()) != NULL) { ffi_strerr_ = s; return uim_scm_f(); } ffi_strerr_ = NULL; return MAKE_PTR(handle); }
static void * uim_curl_url_escape_internal(void *url_) { uim_lisp escaped_url_; const char *unescaped_url = REFER_C_STR((uim_lisp)url_); char *escaped_url; CURL *curl; curl = curl_easy_init(); if(curl == NULL) return uim_scm_f(); escaped_url = curl_easy_escape(curl, unescaped_url, strlen(unescaped_url)); escaped_url_ = (escaped_url != NULL) ? MAKE_STR(escaped_url) : uim_scm_f(); curl_free(escaped_url); curl_easy_cleanup(curl); curl_global_cleanup(); return (void *)escaped_url_; }
static uim_lisp intl_dgettext(uim_lisp domainname, uim_lisp msgid) { const char *translated; if (!STRP(domainname) || !STRP(msgid)) return uim_scm_f(); translated = dgettext(REFER_C_STR(domainname), REFER_C_STR(msgid)); return MAKE_STR(translated); }
static uim_lisp release_context(uim_lisp ac_) { anthy_context_t ac; context_list = uim_scm_callf("delete!", "oo", ac_, context_list); ac = get_anthy_context(ac_); anthy_release_context(ac); uim_scm_nullify_c_ptr(ac_); return uim_scm_f(); }
static uim_lisp uim_ext_iconv_open(uim_lisp tocode_, uim_lisp fromcode_) { const char *tocode = REFER_C_STR(tocode_); const char *fromcode = REFER_C_STR(fromcode_); iconv_t ic; ic = uim_iconv_create(tocode, fromcode); if (!ic) return uim_scm_f(); return MAKE_PTR(ic); }
/* * returns #t if key is expected * (rk-lib-expect-seq-for-key '("k" "y") ja-rk-rule "o") -> #t * (rk-lib-expect-seq-for-key '("k" "y") ja-rk-rule "y") -> #f */ static uim_lisp rk_expect_key_for_seq(uim_lisp seq, uim_lisp rules, uim_lisp key) { uim_lisp cur; for (cur = rules; !uim_scm_nullp(cur); cur = uim_scm_cdr(cur)) { uim_lisp rule = uim_scm_car(cur); uim_lisp seq_in_rule = CAR(CAR(rule)); uim_lisp e = str_seq_partial(seq, seq_in_rule); if (TRUEP(e) && string_equalp(e, key)) { return uim_scm_t(); } } return uim_scm_f(); }
static uim_lisp c_dlsym(uim_lisp handle_, uim_lisp symbol_) { const char *s; void *fun; fun = dlsym(C_PTR(handle_), REFER_C_STR(symbol_)); if ((s = dlerror()) != NULL) { ffi_strerr_ = s; return uim_scm_f(); } ffi_strerr_ = NULL; return MAKE_PTR(fun); }
static uim_lisp set_prediction_src_string(uim_lisp ac_, uim_lisp str_) { #ifdef HAS_ANTHY_PREDICTION anthy_context_t ac; const char *str; ac = get_anthy_context(ac_); str = REFER_C_STR(str_); anthy_set_prediction_string(ac, str); #endif return uim_scm_f(); }
/* My naming sense seems bad... */ static uim_lisp im_shift_page_candidate(uim_lisp uc_, uim_lisp dir_) { uim_context uc; int dir; uc = retrieve_uim_context(uc_); dir = (C_BOOL(dir_)) ? 1 : 0; if (uc->candidate_selector_shift_page_cb) uc->candidate_selector_shift_page_cb(uc->ptr, dir); return uim_scm_f(); }
static uim_lisp im_select_candidate(uim_lisp uc_, uim_lisp idx_) { uim_context uc; int idx; uc = retrieve_uim_context(uc_); idx = C_INT(idx_); if (uc->candidate_selector_select_cb) uc->candidate_selector_select_cb(uc->ptr, idx); return uim_scm_f(); }
static uim_lisp im_delay_activate_candidate_selector(uim_lisp uc_, uim_lisp delay_) { uim_context uc; int delay; uc = retrieve_uim_context(uc_); delay = C_INT(delay_); if (uc->candidate_selector_delay_activate_cb) uc->candidate_selector_delay_activate_cb(uc->ptr, delay); return uim_scm_f(); }
static uim_lisp mana_init(void) { char buf[100]; int fd; int fl; if (mana_pid == 0) mana_pid = uim_ipc_open_command(0, &mana_r, &mana_w, MANA_COMMAND); if (mana_pid == 0) return uim_scm_f(); fd = fileno(mana_r); fl = fcntl(fd, F_GETFL); fcntl(fd, F_SETFL, fl | O_NONBLOCK); fgets(buf, sizeof(buf), mana_r); fcntl(fd, F_SETFL, fl); if (feof(mana_r)) { mana_pid = 0; fclose(mana_r); fclose(mana_w); mana_r = mana_w = NULL; uim_notify_fatal(N_("uim-mana: Command 'mana' not found.")); return uim_scm_f(); } if (ferror(mana_r)) clearerr(mana_r); #ifdef DEBUG log = fopen("mana.log", "w"); #endif return uim_scm_t(); }
static uim_lisp c_execve(uim_lisp file_, uim_lisp argv_, uim_lisp envp_) { char **argv; char **envp; int i; int argv_len = uim_scm_length(argv_); int envp_len; uim_lisp ret_; if (argv_len < 1) return uim_scm_f(); argv = uim_malloc(sizeof(char *) * (argv_len + 1)); for (i = 0; i < argv_len; i++) { argv[i] = uim_strdup(REFER_C_STR(CAR(argv_))); argv_ = CDR(argv_); } argv[argv_len] = NULL; if (FALSEP(envp_) || NULLP(envp_)) { envp_len = 0; envp = NULL; } else { envp_len = uim_scm_length(envp_); envp = uim_malloc(sizeof(char *) * (envp_len + 1)); for (i = 0; i < envp_len; i++) { uim_lisp env_ = CAR(envp_); uim_asprintf(&envp[i], "%s=%s", REFER_C_STR(CAR(env_)), REFER_C_STR(CDR(env_))); envp_ = CDR(envp_); } envp[envp_len] = NULL; } ret_ = MAKE_INT(execve(REFER_C_STR(file_), argv, envp)); for (i = 0; i < argv_len; i++) free(argv[i]); free(argv); for (i = 0; i < envp_len; i++) free(envp[i]); free(envp); return ret_; }
static void * uim_curl_url_unescape_internal(void *url_) { uim_lisp unescaped_url_; const char *escaped_url = REFER_C_STR((uim_lisp)url_); char *unescaped_url; int len; /* curl_easy_unescape uses int, not size_t */ CURL *curl; curl = curl_easy_init(); if(curl == NULL) return uim_scm_f(); unescaped_url = curl_easy_unescape(curl, escaped_url, strlen(escaped_url), &len); unescaped_url_ = (len > 0) ? MAKE_STR(unescaped_url) : uim_scm_f(); curl_free(unescaped_url); curl_easy_cleanup(curl); curl_global_cleanup(); return (void *)unescaped_url_; }
/* * Partial -> first string of remaining sequence * eg. ("a" "b") ("a" "b" "c") -> "c" * Not partial -> #f * */ static uim_lisp str_seq_partial(uim_lisp seq, uim_lisp rule) { int sl = uim_scm_length(seq); int rl = uim_scm_length(rule); int i; if (sl >= rl) { return uim_scm_f(); } /* Obviously. sl < rl */ for (i = 0; i < sl; i++) { if (!string_equalp(uim_scm_car(seq), uim_scm_car(rule))) { return uim_scm_f(); } seq = uim_scm_cdr(seq); rule = uim_scm_cdr(rule); } if (rule && uim_scm_car(rule)) { return uim_scm_car(rule); } /* never reach here */ return uim_scm_f(); }
static uim_lisp im_pushback_mode_list(uim_lisp uc_, uim_lisp str_) { uim_context uc; const char *str; uc = retrieve_uim_context(uc_); str = REFER_C_STR(str_); uc->modes = uim_realloc(uc->modes, sizeof(char *) * (uc->nr_modes + 1)); uc->modes[uc->nr_modes] = uc->conv_if->convert(uc->outbound_conv, str); uc->nr_modes++; return uim_scm_f(); }
static uim_lisp im_update_mode(uim_lisp uc_, uim_lisp mode_) { uim_context uc; int mode; uc = retrieve_uim_context(uc_); mode = C_INT(mode_); uc->mode = mode; if (uc->mode_update_cb) uc->mode_update_cb(uc->ptr, mode); return uim_scm_f(); }
static uim_lisp im_activate_candidate_selector(uim_lisp uc_, uim_lisp nr_, uim_lisp display_limit_) { uim_context uc; int nr, display_limit; uc = retrieve_uim_context(uc_); nr = C_INT(nr_); display_limit = C_INT(display_limit_); if (uc->candidate_selector_activate_cb) uc->candidate_selector_activate_cb(uc->ptr, nr, display_limit); return uim_scm_f(); }
static uim_lisp commit_nth_prediction(uim_lisp ac_, uim_lisp nth_) { #ifdef HAS_ANTHY_COMMIT_PREDICTION anthy_context_t ac; int nth, err; ac = get_anthy_context(ac_); nth = C_INT(nth_); err = anthy_commit_prediction(ac, nth); return MAKE_BOOL(!err); #else return uim_scm_f(); #endif }
static uim_lisp im_commit(uim_lisp uc_, uim_lisp str_) { uim_context uc; const char *str; char *converted_str; uc = retrieve_uim_context(uc_); str = REFER_C_STR(str_); converted_str = uc->conv_if->convert(uc->outbound_conv, str); if (uc->commit_cb) uc->commit_cb(uc->ptr, converted_str); free(converted_str); return uim_scm_f(); }
static uim_lisp im_update_prop_list(uim_lisp uc_, uim_lisp prop_) { uim_context uc; const char *prop; uc = retrieve_uim_context(uc_); prop = REFER_C_STR(prop_); free(uc->propstr); uc->propstr = uc->conv_if->convert(uc->outbound_conv, prop); if (uc->prop_list_update_cb) uc->prop_list_update_cb(uc->ptr, uc->propstr); return uim_scm_f(); }
static uim_lisp get_input_method_lang(uim_lisp nth_) { int nth; const char *lang; nth = C_INT(nth_); if (nth < nr_input_methods) { lang = im_array[nth].lang; /* "*" is wildcard language. See langgroup-covers? and * find-im-for-locale. */ return MAKE_STR((strcmp(lang, "t") == 0) ? "*" : lang); } return uim_scm_f(); }
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 }