Beispiel #1
0
Datei: net.c Projekt: bauman/pmtr
/* report to all configured destinations */
void report_status(pmtr_t *cfg) {
  int rc;
  time_t now = time(NULL);

  /* construct msg */
  utstring_clear(cfg->s);
  utstring_printf(cfg->s, "report %s\n", cfg->report_id);
  job_t *j = NULL;
  while ( (j=(job_t*)utarray_next(cfg->jobs,j))) {
    if (j->respawn == 0) continue; /* don't advertise one-time jobs */
    utstring_printf(cfg->s, "%s %c %u %d %s\n", j->name, j->disabled?'d':'e',
                    (unsigned)(now - j->start_ts), (int)j->pid,
                    *((char**)utarray_front(&j->cmdv)));
  }

  /* send to all dests */
  int *fd=NULL;
  while ( (fd=(int*)utarray_next(cfg->report,fd))) {
    rc = write(*fd,utstring_body(cfg->s),utstring_len(cfg->s));
    if (rc < 0 && errno != ECONNREFUSED) 
      syslog(LOG_INFO,"write error: %s", strerror(errno));
    if (rc >= 0 && rc < utstring_len(cfg->s)) {
      syslog(LOG_INFO,"incomplete write %d/%d", rc, utstring_len(cfg->s));
    }
  }
}
Beispiel #2
0
int do_attrition(void) {
  int rc = -1, nfiles=0;
  UT_array *files;
  UT_array *stats; 
  utarray_new(files,&ut_str_icd);
  utarray_new(stats,&stats_icd);
  if (get_files(files,stats) == -1) goto done;

  /* tally up their sizes */
  int64_t total_sz=0;
  file_stat_t *fs=NULL;
  while ( (fs=(file_stat_t*)utarray_next(stats,fs))) total_sz += fs->sb.st_size;
  if (total_sz < cf.sz_bytes) { rc = 0; goto done; }

  /* we're oversize. sort the files oldest first and delete til under max size*/
  utarray_sort(stats,attrition_sort);
  fs=NULL;
  while ( (fs=(file_stat_t*)utarray_next(stats,fs))) {
    char *file = *(char**)utarray_eltptr(files, fs->file_idx);
    if (cf.verbose) syslog(LOG_INFO,"removing %s (size %ld)", file, (long)fs->sb.st_size);
    if (cf.dry_run || (unlink(file) == 0)) {
      total_sz -= fs->sb.st_size;
      nfiles++;
      if (total_sz < cf.sz_bytes) { rc = 0; goto done; }
    } else {
      syslog(LOG_ERR,"can't unlink %s: %s", file, strerror(errno));
    }
  }

 done:
  if (cf.verbose) syslog(LOG_INFO,"%d files removed", nfiles);
  utarray_free(files);
  utarray_free(stats);
  return rc;
}
Beispiel #3
0
void append_to_client_buf(UT_string *f) {
  assert(utarray_len(cfg.outbufs) > 0);
  UT_string **s=NULL;
  size_t l,least,c;
  char *b;
  int i=0,lx;

  b = utstring_body(f);
  l = utstring_len(f);

  switch(cfg.mode) {
    case fan:          // send to ALL clients
      while ( (s=(UT_string**)utarray_next(cfg.outbufs,s))) {
        utstring_bincpy(*s,b,l);
      }
      break;
    case round_robin:  // send to ONE client 
      while ( (s=(UT_string**)utarray_next(cfg.outbufs,s))) {
        c = utstring_len(*s);
        if ((i==0) || (c < least)) {least=c; lx=i;}
        i++;
      }
      s = (UT_string**)utarray_eltptr(cfg.outbufs,lx);
      utstring_bincpy(*s,b,l);
      break;
  }
}
Beispiel #4
0
Datei: net.c Projekt: bauman/pmtr
void close_sockets(pmtr_t *cfg) {
  int *fd;
  fd=NULL; while( (fd=(int*)utarray_next(cfg->listen,fd))) close(*fd);
  fd=NULL; while( (fd=(int*)utarray_next(cfg->report,fd))) close(*fd);
  utarray_clear(cfg->listen);
  utarray_clear(cfg->report);
}
Beispiel #5
0
FCITX_EXPORT_API
char* fcitx_utils_join_string_list(UT_array* list, char delm)
{
    if (!list)
        return NULL;

    if (utarray_len(list) == 0)
        return strdup("");

    size_t len = 0;
    char** str;
    for (str = (char**) utarray_front(list);
         str != NULL;
         str = (char**) utarray_next(list, str))
    {
        len += strlen(*str) + 1;
    }

    char* result = (char*)malloc(sizeof(char) * len);
    char* p = result;
    for (str = (char**) utarray_front(list);
         str != NULL;
         str = (char**) utarray_next(list, str))
    {
        size_t strl = strlen(*str);
        memcpy(p, *str, strl);
        p += strl;
        *p = delm;
        p++;
    }
    result[len - 1] = '\0';

    return result;
}
Beispiel #6
0
void FcitxXkbDBusGetLayouts(FcitxXkbDBus* xkbdbus, DBusMessage* message)
{
    DBusMessageIter iter, sub;
    dbus_message_iter_init_append(message, &iter);

    dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ssss)", &sub);

    FcitxXkbRules* rules = xkbdbus->rules;
    FcitxIsoCodes* isocodes = xkbdbus->isocodes;
    char* lang = NULL;
#define GET_LANG \
    do { \
        char** plang = NULL; \
        plang = (char**) utarray_front(layoutInfo->languages); \
        lang = NULL; \
        if (plang) { \
            FcitxIsoCodes639Entry* entry = FcitxIsoCodesGetEntry(isocodes, *plang); \
            if (entry) { \
                lang = entry->iso_639_1_code; \
            } \
        } \
    } while (0)

    if (rules) {
        FcitxXkbLayoutInfo* layoutInfo;
        for (layoutInfo = (FcitxXkbLayoutInfo*) utarray_front(rules->layoutInfos);
            layoutInfo != NULL;
            layoutInfo = (FcitxXkbLayoutInfo*) utarray_next(rules->layoutInfos, layoutInfo))
        {
            char* description = dgettext("xkeyboard-config",
                                         layoutInfo->description);
            GET_LANG;
            FcitxXkbDBusAppendLayout(&sub, layoutInfo->name, "",
                                     description, lang);
            FcitxXkbVariantInfo* variantInfo;
            for (variantInfo = (FcitxXkbVariantInfo*) utarray_front(layoutInfo->variantInfos);
                variantInfo != NULL;
                variantInfo = (FcitxXkbVariantInfo*) utarray_next(layoutInfo->variantInfos, variantInfo))
            {
                char *description;
                fcitx_utils_alloc_cat_str(
                    description,
                    dgettext("xkeyboard-config", layoutInfo->description),
                    " - ",
                    dgettext("xkeyboard-config", variantInfo->description));
                GET_LANG;
                FcitxXkbDBusAppendLayout(&sub, layoutInfo->name,
                                         variantInfo->name, description, lang);
                free(description);
            }
        }
    }
    else {
        char *description = dgettext("xkeyboard-config", "English (US)");
        FcitxXkbDBusAppendLayout(&sub, "us", "", description, "en");
    }
    dbus_message_iter_close_container(&iter, &sub);
}
Beispiel #7
0
void mark_writable() {
  /* mark writability-interest for any clients with pending output */
  int *fd=NULL, *i=NULL;
  UT_string **s=NULL;
  while ( (fd=(int*)utarray_next(cfg.clients,fd))) {
    s=(UT_string**)utarray_next(cfg.outbufs,s); assert(s);
    i=(int*)utarray_next(cfg.outidxs,i);        assert(i);
    if (utstring_len(*s) > *i) mod_epoll(EPOLLIN|EPOLLOUT, *fd);
  }
}
Beispiel #8
0
int main() {
  UT_array *a;
  int i, *p;
  utarray_new(a, &ut_int_icd);
  for(i=0;i<10;i++) utarray_push_back(a,&i);
  for(p=(int*)utarray_front(a); p; p=(int*)utarray_next(a,p)) printf("%d ",*p);
  printf("\n");
  utarray_sort(a,reverse);
  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
  printf("\n");
  utarray_erase(a,3,3);
  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
  printf("\n");
  utarray_erase(a,1,2);
  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
  printf("\n");
  utarray_erase(a,0,1);
  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
  printf("\n");
  utarray_erase(a,3,1);
  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
  printf("\n");
  utarray_resize(a,5);
  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
  printf("\n");
  utarray_resize(a,3);
  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
  printf("\n");
  utarray_erase(a,0,3);
  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p);
  printf("\n");
  utarray_free(a);
  return 0;
}
Beispiel #9
0
FCITX_EXPORT_API
void FcitxInstanceEnd(FcitxInstance* instance)
{
    FcitxInstanceSaveAllIM(instance);
    
    if (instance->uinormal && instance->uinormal->ui->Destroy)
        instance->uinormal->ui->Destroy(instance->uinormal->addonInstance);
    
    if (instance->uifallback && instance->uifallback->ui->Destroy)
        instance->uifallback->ui->Destroy(instance->uifallback->addonInstance);
    
    instance->uifallback = NULL;
    instance->ui = NULL;
    instance->uinormal = NULL;

    /* handle exit */
    FcitxAddon** pimclass;
    FcitxAddon** pfrontend;
    FcitxFrontend* frontend;
    FcitxInputContext* rec = NULL;

    for (pimclass = (FcitxAddon**) utarray_front(&instance->imeclasses);
            pimclass != NULL;
            pimclass = (FcitxAddon**) utarray_next(&instance->imeclasses, pimclass)
        ) {
        if ((*pimclass)->imclass->Destroy)
            (*pimclass)->imclass->Destroy((*pimclass)->addonInstance);
    }

    for (rec = instance->ic_list; rec != NULL; rec = rec->next) {
        pfrontend = (FcitxAddon**) utarray_eltptr(&instance->frontends, rec->frontendid);
        frontend = (*pfrontend)->frontend;
        frontend->CloseIM((*pfrontend)->addonInstance, rec);
    }

    for (rec = instance->ic_list; rec != NULL; rec = rec->next) {
        pfrontend = (FcitxAddon**) utarray_eltptr(&instance->frontends, rec->frontendid);
        frontend = (*pfrontend)->frontend;
        frontend->DestroyIC((*pfrontend)->addonInstance, rec);
    }

    int frontendid = 0;
    for (pfrontend = (FcitxAddon**) utarray_front(&instance->frontends);
            pfrontend != NULL;
            pfrontend = (FcitxAddon**) utarray_next(&instance->frontends, pfrontend)
        ) {
        if (pfrontend == NULL)
            return;
        FcitxFrontend* frontend = (*pfrontend)->frontend;
        frontend->Destroy((*pfrontend)->addonInstance);
        frontendid++;
    }

    sem_post(instance->sem);
}
const float euclidean_distance_custom(const char *str1, const char *str2, std_tokenizer_t *tokenizer) {

	UT_array *t1 = tokenizer->tok_utarr_func(str1, tokenizer->delimiters);
	UT_array *t2 = tokenizer->tok_utarr_func(str2, tokenizer->delimiters);

	hash_token_t *h1 = tokenizer->tok_uq_hash_func(str1, tokenizer->delimiters);
	hash_token_t *h2 = tokenizer->tok_uq_hash_func(str2, tokenizer->delimiters);

	hash_token_t *all = merge_tokens(h1, h2);
	hash_token_t *s;

	int cs1, cs2;
	float td = 0;

	char **tmp;

	for(s = all; s != NULL; s = s->hh.next) {

		cs1 = 0;
		cs2 = 0;

		while((tmp = (char **) utarray_next(t1, tmp))) {

			if(strcmp(*tmp, s->value) == 0)
				cs1++;

		}

		while((tmp = (char **) utarray_next(t2, tmp))) {

			if(strcmp(*tmp, s->value) == 0)
				cs2++;

		}

		td += (float)(((float)cs1 - (float)cs2) * ((float)cs1 - (float)cs2));

	}

	utarray_free(t1);
	utarray_free(t2);

	hash_token_free(h1);
	hash_token_free(h2);
	hash_token_free(all);

	return sqrtf(td);

}
Beispiel #11
0
int set_sample_tainted( dba_context* ctx ) {
    
    const char* img;

    UT_array* fblocks;

    TSK_DADDR_T  st_haddr, 
                 ed_haddr;

    TSK_DADDR_T* haddr_tuple; 

    UT_array* fnames; 
    char**    fname;

    img     = get_device_image( "ide0-hd0" );
    fblocks = tsk_find_haddr_by_filename( img, ctx->sample_gpath );

    qemu_mutex_lock( &qemu_global_mutex );

    for( haddr_tuple  = (TSK_DADDR_T*)utarray_front(fblocks);
         haddr_tuple != NULL;
         haddr_tuple  = (TSK_DADDR_T*)utarray_next(fblocks, haddr_tuple) ) {
        st_haddr = haddr_tuple[0];
        ed_haddr = haddr_tuple[1];

        fnames = tsk_get_filename_by_haddr( img, st_haddr );

        if( fnames == NULL )
            continue;

        for( fname  = (char**)utarray_front(fnames);
             fname != NULL;
             fname  = (char**)utarray_next(fnames, fname) ) {

            if( strcasecmp(*fname, ctx->sample_gpath) != 0 ) 
                continue;

            dift_contaminate_disk_or( st_haddr, ed_haddr - st_haddr + 1, ctx->taint.tag );
            break;
        }
        utarray_free( fnames );
    }
    utarray_free( fblocks );

    qemu_mutex_unlock( &qemu_global_mutex );

    return 0;
}
Beispiel #12
0
void cmdline_req_run(Cmdstr *caller, Cmdline *cmdline)
{
  if (!cmdline->cmds || cmdline->err)
    return;

  if (utarray_len(cmdline->cmds) == 1) {
    Cmdstr *single = cmdline_getcmd(cmdline);
    single->caller = caller;
    return cmd_run(single, cmdline);
  }

  char *full_line = cmdline->line;
  int len = strlen(full_line);
  char *last = &full_line[len+1];

  bool waspipe = false;
  Cmdstr *cmd = NULL;
  while ((cmd = (Cmdstr*)utarray_next(cmdline->cmds, cmd))) {

    char *line = &full_line[cmd->st];
    if (line < last && waspipe)
      line++;
    if (cmd->bar)
      full_line[cmd->ed] = '\0';

    cmd_eval(NULL, line);
    waspipe = cmd->bar;
  }
}
Beispiel #13
0
void MergeRules(FcitxXkbRules* rules, FcitxXkbRules* rulesextra)
{
    utarray_concat(rules->modelInfos, rulesextra->modelInfos);
    utarray_concat(rules->optionGroupInfos, rulesextra->optionGroupInfos);

    FcitxXkbLayoutInfo* layoutInfo;
    UT_array toAdd;
    utarray_init(&toAdd, fcitx_ptr_icd);
    for (layoutInfo = (FcitxXkbLayoutInfo*) utarray_front(rulesextra->layoutInfos);
         layoutInfo != NULL;
         layoutInfo = (FcitxXkbLayoutInfo*) utarray_next(rulesextra->layoutInfos, layoutInfo))
    {
        FcitxXkbLayoutInfo* l = FindByName(rules, layoutInfo->name);
        if (l) {
            utarray_concat(l->languages, layoutInfo->languages);
            utarray_concat(l->variantInfos, layoutInfo->variantInfos);
        }
        else
            utarray_push_back(&toAdd, &layoutInfo);
    }

    unsigned int i;
    for(i = 0;i < utarray_len(&toAdd);i++) {
        FcitxXkbLayoutInfo* p = *(FcitxXkbLayoutInfo**)utarray_eltptr(&toAdd, i);
        utarray_push_back(rules->layoutInfos, p);
    }

    utarray_done(&toAdd);
    FcitxXkbRulesFree(rulesextra);
}
Beispiel #14
0
boolean IsMouseInOtherMenu(XlibMenu *xlibMenu, int x, int y)
{
    FcitxClassicUI *classicui = xlibMenu->parent.owner;
    FcitxInstance* instance = classicui->owner;
    FcitxUIMenu** menupp;
    UT_array* uimenus = FcitxInstanceGetUIMenus(instance);
    for (menupp = (FcitxUIMenu **) utarray_front(uimenus);
            menupp != NULL;
            menupp = (FcitxUIMenu **) utarray_next(uimenus, menupp)
        ) {

        XlibMenu* otherXlibMenu = (XlibMenu*)(*menupp)->uipriv[classicui->isfallback];
        if (otherXlibMenu == xlibMenu)
            continue;
        XWindowAttributes attr;
        XGetWindowAttributes(classicui->dpy, otherXlibMenu->parent.wId, &attr);
        if (attr.map_state != IsUnmapped &&
                FcitxUIIsInBox(x, y, attr.x, attr.y, attr.width, attr.height)) {
            return true;
        }
    }

    XlibMenu* otherXlibMenu = classicui->mainMenuWindow;
    if (otherXlibMenu == xlibMenu)
        return false;
    XWindowAttributes attr;
    XGetWindowAttributes(classicui->dpy, otherXlibMenu->parent.wId, &attr);
    if (attr.map_state != IsUnmapped &&
            FcitxUIIsInBox(x, y, attr.x, attr.y, attr.width, attr.height)) {
        return true;
    }
    return false;
}
Beispiel #15
0
void ex_cmdinvert()
{
  int st = compl_root_pos();
  int ed = st;
  while (ex.line[ed++] == ' ');

  //FIXME: find compl_root_pos for curs position
  Token *cur = cmdline_tokbtwn(&ex.cmd, st, ed);
  Token *tok = (Token*)utarray_next(ex.cmd.tokens, cur);
  char *symb = token_val(tok, VAR_STRING);
  if (!cur)
    return;

  if (symb && *symb == '!') {
    str_ins(ex.line, "", tok->start, 1);
    ex.curofs--, ex.curpos--;
  }
  else {
    str_ins(ex.line, "!", cur->end, 0);
    ex.curofs++, ex.curpos++;
  }

  int old = ex.curofs;
  ex.curofs = 0;
  menu_rebuild(ex.menu);
  ex.curofs = old;
}
void ParsePlacement(UT_array* sps, char* placment)
{
    UT_array* array = SplitString(placment, ';');
    char** str;
    utarray_clear(sps);
    for(str = (char**) utarray_front(array);
        str != NULL;
        str = (char**) utarray_next(array, str))
    {
        char* s = *str;
        char* p = strchr(s, ':');
        if (p == NULL)
            continue;
        if ((strchr(s, ':') - s) > MAX_STATUS_NAME)
            continue;
        
        int len = p - s;
        SkinPlacement sp;
        strncpy(sp.name, s, len);
        sp.name[len] = '\0';
        int ret = sscanf(p+1, "%d,%d", &sp.x, &sp.y);
        if (ret != 2)
            continue;
        utarray_push_back(sps, &sp);
    }
    
    utarray_free(array);
}
Beispiel #17
0
boolean IsMouseInOtherMenu(XlibMenu *xlibMenu, int x, int y)
{
    FcitxLightUI *lightui = xlibMenu->owner;
    FcitxInstance* instance = lightui->owner;
    FcitxUIMenu** menupp;
    for (menupp = (FcitxUIMenu **) utarray_front(&instance->uimenus);
            menupp != NULL;
            menupp = (FcitxUIMenu **) utarray_next(&instance->uimenus, menupp)
        )
    {

        XlibMenu* otherXlibMenu = (XlibMenu*) (*menupp)->uipriv;
        if (otherXlibMenu == xlibMenu)
            continue;
        XWindowAttributes attr;
        XGetWindowAttributes(lightui->dpy, otherXlibMenu->menuWindow, &attr);
        if (attr.map_state != IsUnmapped &&
                IsInBox(x, y, attr.x, attr.y, attr.width, attr.height))
        {
            return true;
        }
    }

    XlibMenu* otherXlibMenu = lightui->mainMenuWindow;
    if (otherXlibMenu == xlibMenu)
        return false;
    XWindowAttributes attr;
    XGetWindowAttributes(lightui->dpy, otherXlibMenu->menuWindow, &attr);
    if (attr.map_state != IsUnmapped &&
            IsInBox(x, y, attr.x, attr.y, attr.width, attr.height))
    {
        return true;
    }
    return false;
}
Beispiel #18
0
/*
 * Here we initialize the arguments indexing
 */
YAP_Int
p_udi_args_init(Term spec, int arity, UdiInfo blk)
{
	int i;
	Term arg;
	Atom idxtype;
	UdiControlBlock *cb;
	struct udi_p_args p_arg;

	for (i = 1; i <= arity; i++) {
		arg = ArgOfTerm(i,spec);
		if (IsAtomTerm(arg)) {
			idxtype = AtomOfTerm(arg);
			if (idxtype == AtomMinus) //skip this argument
				continue;
			p_arg.control = NULL;
			cb = NULL;
			while ((cb = (UdiControlBlock *) utarray_next(indexing_structures, cb))) {
				if (idxtype == (*cb)->decl){
					p_arg.arg = i;
					p_arg.control = *cb;
					p_arg.idxstr = (*cb)->init(spec, i, arity);
					utarray_push_back(blk->args, &p_arg);
				}
			}
			if (p_arg.control == NULL){ /* not "-" and not found */
				fprintf(stderr, "Invalid Spec (%s)\n", AtomName(idxtype));
				return FALSE;
			}
		}
	}
	return TRUE;
}
Beispiel #19
0
/**
 * Locate the modified parameter structure for a parameter, if it exists.
 *
 * @param param			The parameter being searched.
 * @return			The structure holding the modified value, or
 *				NULL if the parameter has not been modified.
 */
static struct param_wbuf_s *
param_find_changed(param_t param)
{
	struct param_wbuf_s	*s = NULL;

	param_assert_locked();

	if (param_values != NULL) {
#if 0	/* utarray_find requires bsearch, not available */
		struct param_wbuf_s key;
		key.param = param;
		s = utarray_find(param_values, &key, param_compare_values);
#else

		while ((s = (struct param_wbuf_s *)utarray_next(param_values, s)) != NULL) {
			if (s->param == param) {
				break;
			}
		}

#endif
	}

	return s;
}
Beispiel #20
0
OMX_PTR
tiz_vector_find (const tiz_vector_t * p_vec, const OMX_PTR ap_data)
{
  OMX_PTR p_next = NULL, p_cur = NULL;

  assert (p_vec);
  assert (ap_data);

  for (;;)
    {
      p_next = utarray_next (p_vec->p_uta, p_cur);

      if (NULL == p_next)
        {
          return NULL;
        }

      if (0 == memcmp (ap_data, p_next, p_vec->p_icd->sz))
        {
          return p_next;
        }

      p_cur = p_next;
    }
}
Beispiel #21
0
int main() {
  UT_array *a;
  int i, *p;
  utarray_new(a, &ut_int_icd);
  for(i=0;i<10;i++) utarray_push_back(a,&i);
  for(p=(int*)utarray_front(a); p; p=(int*)utarray_next(a,p)) printf("%d ",*p); 
  printf("\n");
  printf("len: %u\n\n", utarray_len(a));
  
  i=10; utarray_insert(a, &i, 10);
  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n");
  printf("len: %u\n\n", utarray_len(a));

  utarray_free(a);
  return 0;
}
Beispiel #22
0
static void* LuaCallCommand(void* arg, FcitxModuleFunctionArg args) {
    LuaModule *luamodule = (LuaModule *)arg;
    UT_array *result = InputCommand(luamodule, (const char *)args.args[0]);
    if (result) {
        FcitxInputState* input = FcitxInstanceGetInputState(GetFcitx(luamodule));
        LuaResultItem *p = NULL;
        while ((p = (LuaResultItem *)utarray_next(result, p))) {
            FcitxCandidateWord candWord;
            if (args.args[1] && args.args[2]) {
                candWord.callback = args.args[1];
                candWord.owner = args.args[2];
            }
            else {
                candWord.callback = LuaGetCandWord;
                candWord.owner = luamodule;
            }
            candWord.priv = p->help ? strdup(p->help) : NULL;
            if (p->help || p->tip) {
                asprintf(&candWord.strExtra, "%s%s%s", p->help ? p->help : "", p->help && p->tip ? " " : "", p->tip ? p->tip : "");
            } else {
                candWord.strExtra = NULL;
            }
            candWord.strWord = strdup(p->result);
            candWord.wordType = MSG_TIPS;
            candWord.extraType = MSG_CODE;
            FcitxCandidateWordAppend(FcitxInputStateGetCandidateList(input), &candWord);
        }
        utarray_free(result);
    }
    return NULL;
}
Beispiel #23
0
void drain_clients() {
  int rc, *fd, pos;
  char buf[1024];

  fd=NULL;
  while ( (fd=(int*)utarray_next(cfg.fds,fd))) {
    do {
      rc = read(*fd, buf, sizeof(buf));
      switch(rc) { 
        default: fprintf(stderr,"received %d bytes\n", rc);         break;
        case  0: fprintf(stderr,"fd %d closed\n", *fd);             break;
        case -1: if (errno == EWOULDBLOCK || errno == EAGAIN)       break;
                 fprintf(stderr, "recv: %s\n", strerror(errno));    break;
      }
    } while(rc > 0);

    if (rc==0) {
      fprintf(stderr,"client %d has closed\n", *fd);
      close(*fd);
      *fd = -1; /* mark for cleanup after forward iteration */
    }
  }

  /* cleanup any sockets that we closed, reverse iteration */
  fd=NULL;
  while ( (fd=(int*)utarray_prev(cfg.fds,fd))) {
    pos = utarray_eltidx(cfg.fds,fd);
    if (*fd == -1) utarray_erase(cfg.fds,pos,1);
  }

}
Beispiel #24
0
FCITX_EXPORT_API
void FcitxUILoad(FcitxInstance* instance)
{
    UT_array* addons = &instance->addons;
    FcitxAddon *addon;

    for (addon = (FcitxAddon *) utarray_front(addons);
            addon != NULL;
            addon = (FcitxAddon *) utarray_next(addons, addon)) {
        if (addon->bEnabled && addon->category == AC_UI) {
            if (FcitxUILoadInternal(instance, addon))
                instance->uinormal = addon;

            if (instance->uinormal != NULL)
                break;
        }
    }

    instance->ui = instance->uinormal;

    if (instance->ui == NULL) {
        FcitxLog(ERROR, "no usable user interface.");
        return;
    }

    if (addon->uifallback)
        instance->fallbackuiName = strdup(addon->uifallback);
}
Beispiel #25
0
// periodically we shift the output buffers down
// to reclaim the already written output regions
void shift_buffers() {
  int *fd=NULL, *i=NULL;
  UT_string **s=NULL;
  size_t len;

  while ( (fd=(int*)utarray_next(cfg.clients,fd))) {
    s=(UT_string**)utarray_next(cfg.outbufs,s); assert(s);
    i=(int*)utarray_next(cfg.outidxs,i);        assert(i);
    len = utstring_len(*s);
    if (*i == 0) continue; // nothing to shift 

    assert(*i > 0);
    memmove((*s)->d, (*s)->d + *i, len-*i);
    (*s)->i -= *i;
    *i = 0;
  }
}
Beispiel #26
0
/* used to stop reading the spool when internal buffers are 90% full */
int have_capacity() {
  size_t max = utarray_len(cfg.outbufs) * cfg.mb_per_client * (1024*1024);
  size_t used=0;
  UT_string **s=NULL;
  while ( (s=(UT_string**)utarray_next(cfg.outbufs,s))) used += utstring_len(*s);
  double pct_full = max ? (used*100.0/max) : 100;
  return (pct_full > 90) ? 0 : 1;
}
Beispiel #27
0
void* LightUICreate(FcitxInstance* instance)
{
    FcitxModuleFunctionArg arg;
    FcitxLightUI* lightui = fcitx_utils_malloc0(sizeof(FcitxLightUI));
    FcitxAddon* lightuiaddon = FcitxAddonsGetAddonByName(FcitxInstanceGetAddons(instance), FCITX_LIGHT_UI_NAME);
    lightui->owner = instance;
    if (!LoadLightUIConfig(lightui))
    {
        free(lightui);
        return NULL;
    }
    lightui->dpy = InvokeFunction(instance, FCITX_X11, GETDISPLAY, arg);
    if (lightui->dpy == NULL)
    {
        free(lightui);
        return NULL;
    }
    lightui->isfallback = FcitxUIIsFallback(instance, lightuiaddon);

    lightui->iScreen = DefaultScreen(lightui->dpy);
    CreateFont(lightui);

    lightui->protocolAtom = XInternAtom (lightui->dpy, "WM_PROTOCOLS", False);
    lightui->killAtom = XInternAtom (lightui->dpy, "WM_DELETE_WINDOW", False);

    /* Main Menu Initial */
    FcitxMenuInit(&lightui->mainMenu);

    FcitxUIMenu **menupp;
    UT_array* uimenus = FcitxInstanceGetUIMenus(instance);
    for (menupp = (FcitxUIMenu **) utarray_front(uimenus);
            menupp != NULL;
            menupp = (FcitxUIMenu **) utarray_next(uimenus, menupp)
        )
    {
        FcitxUIMenu * menup = *menupp;
        if (!menup->isSubMenu)
            FcitxMenuAddMenuItem(&lightui->mainMenu, menup->name, MENUTYPE_SUBMENU, menup);
    }
    FcitxMenuAddMenuItem(&lightui->mainMenu, NULL, MENUTYPE_DIVLINE, NULL);
    FcitxMenuAddMenuItem(&lightui->mainMenu, _("Configure"), MENUTYPE_SIMPLE, NULL);
    FcitxMenuAddMenuItem(&lightui->mainMenu, _("Exit"), MENUTYPE_SIMPLE, NULL);
    lightui->mainMenu.MenuAction = MainMenuAction;
    lightui->mainMenu.priv = lightui;
    lightui->mainMenu.mark = -1;


    lightui->inputWindow = CreateInputWindow(lightui);
    lightui->mainWindow = CreateMainWindow(lightui);
    lightui->trayWindow = CreateTrayWindow(lightui);
    lightui->mainMenuWindow = CreateMainMenuWindow(lightui);

    FcitxIMEventHook resethk;
    resethk.arg = lightui;
    resethk.func = LightUIInputReset;
    FcitxInstanceRegisterResetInputHook(instance, resethk);
    return lightui;
}
Beispiel #28
0
Token* cmdline_tokbtwn(Cmdline *cmdline, int st, int ed)
{
  Token *word = NULL;
  while ((word = (Token*)utarray_next(cmdline->tokens, word))) {
    if (MAX(0, MIN(ed, word->end) - MAX(st, word->start)) > 0)
      return word;
  }
  return NULL;
}
Beispiel #29
0
static int lines_count(UT_array *lines, const char *type)
{
    line_t *line = NULL;
    int ret = 0;
    while( (line = (line_t*)utarray_next(lines, line))) {
        if (strncmp(line->type, type, 2) == 0)
            ret++;
    }
    return ret;
}
Beispiel #30
0
void dicom_import(const char *dirpath)
{
    DIR *dir;
    struct dirent *dirent;
    dicom_t dicom, *dptr;
    static UT_icd dicom_icd = {sizeof(dicom_t), NULL, NULL, NULL};
    UT_array *all_files;
    int w, h, d;    // Dimensions of the full data cube.
    int i;
    uint16_t *data;
    uvec4b_t *cube;

    // First we parse all the dicom images into a sorted array.
    // XXX: how to propery iter a directory?
    utarray_new(all_files, &dicom_icd);
    dir = opendir(dirpath);
    while ((dirent = readdir(dir))) {
        if (dirent->d_name[0] == '.') continue;
        asprintf(&dicom.path, "%s/%s", dirpath, dirent->d_name);
        dicom_load(dicom.path, &dicom, NULL, 0);
        CHECK(dicom.rows && dicom.columns);
        utarray_push_back(all_files, &dicom);
    }
    closedir(dir);
    utarray_sort(all_files, dicom_sort);

    // Read all the file data one by one into the data cube.
    w = dicom.columns;
    h = dicom.rows;
    d = utarray_len(all_files);
    data = calloc(w * h * d, 2);

    dptr = NULL;
    while( (dptr = (dicom_t*)utarray_next(all_files, dptr))) {
        i = utarray_eltidx(all_files, dptr);
        dicom_load(dptr->path, &dicom,
                   (char*)&data[w * h * i], w * h * 2);
        free(dptr->path);
    }
    utarray_free(all_files);

    // Generate 4 * 8bit RGBA values.
    // XXX: we should maybe support voxel data in 2 bytes monochrome.
    cube = malloc(w * h * d * sizeof(*cube));
    for (i = 0; i < w * h * d; i++) {
        cube[i] = uvec4b(255, 255, 255, clamp(data[i], 0, 255));
    }
    free(data);

    // This could belong to the caller function.
    mesh_blit(goxel()->image->active_layer->mesh, cube,
              -w / 2, -h / 2, -d / 2, w, h, d);

    free(cube);
}