Пример #1
0
static uim_lisp
c_file_poll(uim_lisp fds_, uim_lisp timeout_)
{
  struct pollfd *fds;
  int timeout = C_INT(timeout_);
  int nfds = uim_scm_length(fds_);
  uim_lisp fd_ = uim_scm_f();
  int i;
  int ret;
  uim_lisp ret_;
  struct c_file_poll_args args;

  fds = uim_calloc(nfds, sizeof(struct pollfd));

  for (i = 0; i < nfds; i++) {
    fd_ = CAR(fds_);
    fds[i].fd = C_INT(CAR(fd_));
    fds[i].events = C_INT(CDR(fd_));
    fds_ = CDR(fds_);
  }

  ret = poll(fds, nfds, timeout);
  if (ret == -1)
    return uim_scm_f();
  else if (ret == 0)
    return uim_scm_null();

  args.fds = fds;
  args.nfds = nfds;
  ret_ = (uim_lisp)uim_scm_call_with_gc_ready_stack((uim_gc_gate_func_ptr)c_file_poll_internal,
						    (void *)&args);
  free(fds);
  return uim_scm_callf("reverse", "o", ret_);
}
Пример #2
0
static uim_lisp
uim_xml_parser_create(uim_lisp encoding_)
{
  uim_xml_ctx *ctx;
  const XML_Char *encoding = REFER_C_STR(encoding_);
  XML_Parser parser;

  parser = XML_ParserCreate(encoding);

  if (parser) {
    XML_SetElementHandler(parser, xml_start_element_handler, xml_end_element_handler);
    XML_SetCharacterDataHandler(parser, xml_characterdata_handler);
  }

  ctx = uim_calloc(1, sizeof(uim_xml_ctx *));
  ctx->parser = parser;

  ctx->data = uim_malloc(sizeof(uim_xml_userdata *));
  ctx->data->start_ = NULL;
  ctx->data->end_ = NULL;
  ctx->data->characterdata_ = NULL;

  return MAKE_PTR(ctx);
}