Beispiel #1
0
static uim_lisp
intl_ngettext(uim_lisp msgid1, uim_lisp msgid2, uim_lisp n)
{
    return MAKE_STR(ngettext(REFER_C_STR(msgid1),
                             REFER_C_STR(msgid2),
                             C_INT(n)));
}
Beispiel #2
0
static void *
dynlib_bind_internal(uim_lisp name)
{
  void *library;
  void (*dynlib_instance_init)(void);
  void (*dynlib_instance_quit)(void);

  DPRINTFN(UIM_VLEVEL_DYNLIB, (stderr, "Loading %s", REFER_C_STR(name)));
  library = dlopen(REFER_C_STR(name), RTLD_NOW);

  if (library == NULL) {
    uim_notify_fatal(_("dynlib: %s: Load failed."), dlerror());
    return uim_scm_f();
  }

  dynlib_instance_init
    = (void (*)(void))dlfunc(library, "uim_dynlib_instance_init");
  dynlib_instance_quit
    = (void (*)(void))dlfunc(library, "uim_dynlib_instance_quit");
  if (!dynlib_instance_init) {
    uim_notify_fatal(_("dynlib: %s: Initialization failed."), REFER_C_STR(name));
    return uim_scm_f();
  }
	
  DPRINTFN(UIM_VLEVEL_DYNLIB, (stderr, "Calling dynlib_instance_init() for %s.\n", REFER_C_STR(name)));
  (*dynlib_instance_init)();

  return LIST3(MAKE_PTR(library),
	       MAKE_FPTR(dynlib_instance_init),
	       MAKE_FPTR(dynlib_instance_quit));
}
Beispiel #3
0
static uim_lisp
intl_dcgettext(uim_lisp domainname, uim_lisp msgid, uim_lisp category)
{
    return MAKE_STR(dcgettext(REFER_C_STR(domainname),
                              REFER_C_STR(msgid),
                              C_INT(category)));
}
Beispiel #4
0
static uim_lisp
c_execvp(uim_lisp file_, uim_lisp argv_)
{
  char **argv;
  int i;
  int len = uim_scm_length(argv_);
  uim_lisp ret_;

  if (len < 1)
    return uim_scm_f();

  argv = uim_malloc(sizeof(char *) * (len + 1));

  for (i = 0; i < len; i++) {
    argv[i] = uim_strdup(REFER_C_STR(CAR(argv_)));
    argv_ = CDR(argv_);
  }
  argv[len] = NULL;

  ret_ = MAKE_INT(execvp(REFER_C_STR(file_), argv));

  for (i = 0; i < len; i++)
    free(argv[i]);
  free(argv);

  return ret_;
}
Beispiel #5
0
static uim_lisp
intl_dngettext(uim_lisp domainname, uim_lisp msgid1, uim_lisp msgid2, uim_lisp n)
{
    return MAKE_STR(dngettext(REFER_C_STR(domainname),
                              REFER_C_STR(msgid1),
                              REFER_C_STR(msgid2),
                              C_INT(n)));
}
Beispiel #6
0
static uim_lisp
c_setenv(uim_lisp name, uim_lisp val, uim_lisp overwrite)
{
  int err;

  err = setenv(REFER_C_STR(name), REFER_C_STR(val), TRUEP(overwrite));

  return MAKE_BOOL(!err);
}
Beispiel #7
0
Datei: curl.c Projekt: NgoHuy/uim
static void *
uim_curl_post_internal(struct uim_curl_post_args *args)
{
  uim_lisp post_ = args->post;
  uim_lisp post_car_, post_cdr_;
  uim_lisp fetched_str_;
  const char *url = REFER_C_STR(args->url);
  CURL *curl;
  CURLcode res;
  struct curl_memory_struct chunk;
  struct curl_httppost* post_first = NULL;
  struct curl_httppost* post_last = NULL;

  curl = curl_easy_init();

  if(curl == NULL)
    return uim_scm_f();

  memset(&chunk, 0, sizeof(struct curl_memory_struct));

  curl_easy_setopt(curl, CURLOPT_URL, url);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, uim_curl_write_func);
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);

  for(post_cdr_ = post_;
      !NULLP(post_cdr_);
      post_cdr_ = CDR(post_cdr_)) {
      const char *name, *value;
      post_car_ = CAR(post_cdr_);

      name = REFER_C_STR(CAR(post_car_));
      value = REFER_C_STR(CDR(post_car_));

      curl_formadd(&post_first, &post_last,
		   CURLFORM_COPYNAME, name,
		   CURLFORM_COPYCONTENTS, value,
		   CURLFORM_END);
  }

  curl_easy_setopt(curl, CURLOPT_HTTPPOST, post_first);

  res = uim_curl_perform(curl);

  fetched_str_ = (chunk.str != NULL) ? MAKE_STR(chunk.str) : uim_scm_f();

  curl_easy_cleanup(curl);
  curl_formfree(post_first);
  curl_global_cleanup();
  free(chunk.str);

  return (void *)fetched_str_;
}
Beispiel #8
0
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);
}
Beispiel #9
0
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);
}
Beispiel #10
0
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_;
}
Beispiel #11
0
static uim_lisp
uim_sqlite3_bind_text(uim_lisp pStmt_, uim_lisp idx_, uim_lisp str_, uim_lisp nBytes_)
{
  if (sqlite3_bind_text(C_PTR(pStmt_), C_INT(idx_), REFER_C_STR(str_), C_INT(nBytes_), SQLITE_TRANSIENT) != SQLITE_OK)
    uim_scm_f();
  return uim_scm_t();
}
Beispiel #12
0
static uim_lisp
notify_load(uim_lisp name_)
{
  const char *name = REFER_C_STR(name_);

  return MAKE_BOOL(uim_notify_load(name));
}
Beispiel #13
0
static uim_lisp
c_getaddrinfo(uim_lisp hostname_, uim_lisp servname_, uim_lisp hint_)
{
  const char *hostname;
  char *servname = NULL;
  struct addrinfo *hints = C_PTR(hint_);
  struct addrinfo *res, *res0;
  uim_lisp ret_ = uim_scm_null();
  int error;

  if (INTP(servname_)) {
    uim_asprintf(&servname, "%d", C_INT(servname_));
  } else {
    servname = C_STR(servname_);
  }

  if (FALSEP(hostname_))
    hostname = NULL;
  else
    hostname = REFER_C_STR(hostname_);
  error = getaddrinfo(hostname, servname, hints, &res0);
  if (error) {
    const char *errstr = gai_strerror(error);
    uim_notify_fatal("getaddrinfo: %s", errstr);
    free(servname);
    return uim_scm_f();
  }

  free(servname);
  for (res = res0; res; res = res->ai_next) {
    ret_ = CONS(MAKE_PTR(res) , ret_);
  }
  return uim_scm_callf("reverse", "o", ret_);
}
Beispiel #14
0
static uim_lisp
home_directory(uim_lisp user_)
{
  int uid;
  char home[MAXPATHLEN];

  if (INTP(user_)) {
    uid = C_INT(user_);
  } else if (STRP(user_)) {
    struct passwd *pw;

    pw = getpwnam(REFER_C_STR(user_));

    if (!pw)
      return uim_scm_f();

    uid = pw->pw_uid;
    endpwent();
  } else {
    return uim_scm_f();
  }

  if (!uim_get_home_directory(home, sizeof(home), uid)) {
    char *home_env = getenv("HOME");
    if (home_env)
      return MAKE_STR(home_env);
    return uim_scm_f();
  }

  return MAKE_STR(home);
}
Beispiel #15
0
static uim_lisp
c_unsetenv(uim_lisp name)
{
  unsetenv(REFER_C_STR(name));

  return uim_scm_t();
}
Beispiel #16
0
Datei: curl.c Projekt: NgoHuy/uim
static void *
uim_curl_fetch_simple_internal(void *url_)
{
  const char *url = REFER_C_STR((uim_lisp)url_);
  CURL *curl;
  CURLcode res;
  struct curl_memory_struct chunk;
  uim_lisp fetched_str_;

  curl = curl_easy_init();

  if(curl == NULL)
    return uim_scm_f();

  memset(&chunk, 0, sizeof(struct curl_memory_struct));

  curl_easy_setopt(curl, CURLOPT_URL, url);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, uim_curl_write_func);
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);

  res = uim_curl_perform(curl);

  fetched_str_ = (chunk.str != NULL) ? MAKE_STR(chunk.str) : uim_scm_f();

  curl_easy_cleanup(curl);
  curl_global_cleanup();
  free(chunk.str);

  return (void *)fetched_str_;
}
Beispiel #17
0
static uim_lisp
mana_eval(uim_lisp buf_)
{
  const char *buf = REFER_C_STR(buf_);
  char *ret_buf;
  char *eval_buf;
  uim_lisp ret;

  if (mana_pid == 0)
    return uim_scm_f();

  ret_buf = mana_ipc_send_command(&mana_pid, &mana_r, &mana_w, buf);

  if (ret_buf == NULL)
    return uim_scm_f();

#ifdef DEBUG
  fputs(buf, log);
  fputs(ret_buf, log);
  fflush(log);
#endif

  uim_asprintf(&eval_buf, "'%s", ret_buf);
  ret = uim_scm_eval_c_string(eval_buf);
  free(ret_buf);
  free(eval_buf);

  return ret;
}
Beispiel #18
0
static uim_lisp
notify_fatal(uim_lisp msg_)
{
  const char *msg = REFER_C_STR(msg_);

  return MAKE_BOOL(uim_notify_fatal("%s", msg));
}
Beispiel #19
0
static uim_lisp
c_set_sockaddr_un_sun_path(uim_lisp sun_, uim_lisp path_)
{
  struct sockaddr_un *s_un = C_PTR(sun_);

  strlcpy(s_un->sun_path, REFER_C_STR(path_), sizeof(s_un->sun_path));
  return uim_scm_t();
}
Beispiel #20
0
static uim_lisp
c_prepare_dir(uim_lisp dir_)
{
  if (!uim_check_dir(REFER_C_STR(dir_))) {
    return uim_scm_f();
  }
  return uim_scm_t();
}
Beispiel #21
0
static uim_bool
uim_lisp_to_time_t(time_t *t, uim_lisp t_)
{
  const char *t_str = REFER_C_STR(t_);
  char *end;

  *t = (time_t)strtod(t_str, &end);
  return *end == '\0';
}
Beispiel #22
0
static uim_lisp
uim_sqlite3_open(uim_lisp filename_)
{
  sqlite3 *db;

  if (sqlite3_open(REFER_C_STR(filename_), &db) != SQLITE_OK)
    ERROR_OBJ(sqlite3_errmsg(db), filename_);
  return MAKE_PTR(db);
}
Beispiel #23
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_);
}
Beispiel #24
0
static void *
uim_xml_parse_internal(struct uim_xml_parse_args *args)
{
  uim_xml_ctx *ctx = C_PTR(args->ctx_);
  const XML_Char *s = REFER_C_STR(args->s_);
  int isFinal = C_INT(args->isFinal_);

  XML_SetUserData(ctx->parser, ctx->data);
  return MAKE_INT(XML_Parse(ctx->parser, s, strlen(s), isFinal));
}
Beispiel #25
0
static uim_lisp
uim_sqlite3_prepare(uim_lisp db_, uim_lisp zSql_, uim_lisp nBytes_)
{
  sqlite3_stmt *ppStmt;
  const char *pzTail;

  if (sqlite3_prepare(C_PTR(db_), REFER_C_STR(zSql_), C_INT(nBytes_), &ppStmt, &pzTail) != SQLITE_OK)
    ERROR_OBJ(sqlite3_errmsg(C_PTR(db_)), zSql_);
  return CONS(MAKE_PTR(ppStmt), MAKE_STR(pzTail));
}
Beispiel #26
0
static uim_lisp
intl_bindtextdomain(uim_lisp domainname, uim_lisp dirname)
{
    const char *domain, *new_dir;

    domain = REFER_C_STR(domainname);

    if (FALSEP(dirname)) {
#if ENABLE_NLS
        new_dir = bindtextdomain(domain, NULL);
#else
        new_dir = "";
#endif
    } else {
        new_dir = bindtextdomain(domain, REFER_C_STR(dirname));
    }

    return MAKE_STR(new_dir);
}
Beispiel #27
0
static uim_lisp
uim_ext_iconv_code_conv(uim_lisp ic_, uim_lisp inbuf_)
{
  char *outbuf;

  outbuf = uim_iconv_code_conv(C_PTR(ic_), REFER_C_STR(inbuf_));
  if (!outbuf)
    return uim_scm_f();

  return MAKE_STR_DIRECTLY(outbuf);
}
Beispiel #28
0
static uim_lisp
c_getenv(uim_lisp str)
{
  char *val;

  ENSURE_TYPE(str, str);

  val = getenv(REFER_C_STR(str));

  return (val) ? MAKE_STR(val) : uim_scm_f();
}
Beispiel #29
0
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);
}
Beispiel #30
0
static uim_lisp
file_mtime(uim_lisp filename)
{
  struct stat st;
  int err;

  err = stat(REFER_C_STR(filename), &st);
  if (err)
    ERROR_OBJ("stat failed for file", filename);

  return MAKE_INT(st.st_mtime);
}