Пример #1
0
void place( int /* item index */ pos,
            UT_array /*of int */*hashv,
            UT_array /*of int */*xv,
            UT_array /*of int */*yv) {
  int x=0, y=0, e, p;
  if (pos == 0) goto done; // place first one at origin

  /*prefer to attach this hexagon to predecessor edge based on
    this one's hashcode%6, but if that's occupied, increment
    through successive edges looking for an open neighbor. If
    none are found, look backward from predecessor to origin
    hexagon, scanning their edges in the same way, until an 
    open neighbor is found. it is certain to find an open one. */
  unsigned my_hash = *(unsigned*)utarray_eltptr(hashv,pos);
  for (p = pos-1; p >= 0; p--) { // hunt through predecessor chain
    for(e=0; e < 6; e++) {       // hunt through predecessor edges
      unsigned bond_edge = (my_hash + e) % EDGES;
      fprintf(stderr," +trying %d/%d\n",p,bond_edge);
      if (available(p,bond_edge,xv,yv,&x,&y)) goto done;
      fprintf(stderr," -taken, edge scanning\n");
    }
  }
  assert(0); // not reached. it's a math thing.

 done:
  utarray_push_back(xv, &x);
  utarray_push_back(yv, &y);
}
Пример #2
0
static void pop(QUEUE *stack, Cmdline *cmdline, int *idx)
{
  Token token = stack_pop(stack);
  Token *parent = stack_head(stack);
  Token *p;

  if (parent->var.v_type == VAR_LIST) {
    if (token.symb)
      return cmdline_push_var(cmdline, &token);

    utarray_push_back(parent->var.vval.v_list->items, &token);
    parent->end = token.end;
  }
  else if ((p = stack_prevprev(stack))->var.v_type == VAR_PAIR) {

    Token key = stack_pop(stack);
    p->var.vval.v_pair->key = key;
    p->var.vval.v_pair->value = token;
    p->end = token.end;
    token = stack_pop(stack);

    if (key.symb)
      return cmdline_push_var(cmdline, &token);

    Token *pt = stack_head(stack);
    utarray_push_back(pt->var.vval.v_list->items, &token);
  }
  (*idx)++;
}
Пример #3
0
void update_timer(char *key, double value)
{
    DPRINTF("update_timer ( %s, %f )\n", key, value);
    statsd_timer_t *t;
    DPRINTF("HASH_FIND_STR '%s'\n", key);
    HASH_FIND_STR( timers, key, t );
    DPRINTF("after HASH_FIND_STR '%s'\n", key);
    if (t)
    {
        DPRINTF("Updating old timer entry\n");
        utarray_push_back(t->values, &value);
        t->count++;
    }
    else
    {
        DPRINTF("Adding new timer entry\n");
        t = malloc(sizeof(statsd_timer_t));

        strcpy(t->key, key);
        t->count = 0;
        utarray_new(t->values, &timers_icd);
        utarray_push_back(t->values, &value);
        t->count++;

        HASH_ADD_STR( timers, key, t );
    }
}
Пример #4
0
int parse_config(char *config_file) {
  char line[100];
  FILE *file;
  int rc=-1;
  int type,t;
  char *sp,*nl,*def;
  if ( (file = fopen(config_file,"r")) == NULL) {
    fprintf(stderr,"can't open %s: %s\n", config_file, strerror(errno));
    goto done;
  }
  while (fgets(line,sizeof(line),file) != NULL) {
    sp = strchr(line,' '); if (!sp) continue;
    nl = strchr(line,'\n'); if (nl) *nl='\0';
    for(t=0; t<adim(supported_types_str); t++) {
      if(!strncmp(supported_types_str[t],line,sp-line)) break;
    }
    if (t >= adim(supported_types_str)){
      fprintf(stderr,"unknown type %s\n",line); 
      goto done;
    }
    char *id = sp+1;
    sp = strchr(id,' ');
    if (sp) *sp = '\0';
    def = sp ? sp+1 : NULL;
    utarray_push_back(output_types,&t);
    utarray_push_back(output_keys,&id);
    utarray_push_back(output_defaults,&def);
  }
  rc = 0;
 done:
  if (file) fclose(file);
  return rc;
}
Пример #5
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);
}
Пример #6
0
/* Add a cvar to an existing or new category
 * IN: cat_name, name of the category
 * IN: cvar_index, index of the cvar as defined by MPI_T_cvar_handle_alloc()
 * If cat_name is NULL or a empty string, nothing happpens.
 */
int MPIR_T_cat_add_cvar(const char *cat_name, int cvar_index)
{
    int mpi_errno = MPI_SUCCESS;
    name2index_hash_t *hash_entry;
    cat_table_entry_t *cat;

    /* NULL or empty string are allowed */
    if (cat_name == NULL || *cat_name == '\0')
        goto fn_exit;

    HASH_FIND_STR(cat_hash, cat_name, hash_entry);

    if (hash_entry != NULL) {
        /* Found it, i.e., category already exists */
        int cat_idx = hash_entry->idx;
        cat = (cat_table_entry_t *)utarray_eltptr(cat_table, cat_idx);
        /* FIXME: Is it worth checking duplicated vars? Probably not */
        utarray_push_back(cat->cvar_indices, &cvar_index);
    } else {
        /* Not found, so create a new category */
        cat = MPIR_T_cat_create(cat_name);
        utarray_push_back(cat->cvar_indices, &cvar_index);
        /* Notify categories have been changed */
        cat_stamp++;
    }

fn_exit:
    return mpi_errno;

fn_fail:
    goto fn_exit;
}
Пример #7
0
void update_timer( char *key, double value ) {
  syslog(LOG_DEBUG, "update_timer ( %s, %f )\n", key, value);
  statsd_timer_t *t;
  syslog(LOG_DEBUG, "HASH_FIND_STR '%s'\n", key);
  HASH_FIND_STR( timers, key, t );
  syslog(LOG_DEBUG, "after HASH_FIND_STR '%s'\n", key);
  if (t) {
    syslog(LOG_DEBUG, "Updating old timer entry");
    wait_for_timers_lock();
    utarray_push_back(t->values, &value);
    t->count++;
    remove_timers_lock();
  } else {
    syslog(LOG_DEBUG, "Adding new timer entry");
    t = malloc(sizeof(statsd_timer_t));

    strcpy(t->key, key);
    t->count = 0;
    utarray_new(t->values, &timers_icd);
    utarray_push_back(t->values, &value);
    t->count++;

    wait_for_timers_lock();
    HASH_ADD_STR( timers, key, t );
    remove_timers_lock();
  }
}
Пример #8
0
int main() {
  UT_array *nums;
  long l, *p;
  UT_icd long_icd = {sizeof(long), NULL, NULL, NULL };
  utarray_new(nums, &long_icd);

  l=1; utarray_push_back(nums, &l);
  l=2; utarray_push_back(nums, &l);

  p=NULL;
  while( (p=(long*)utarray_next(nums,p)) != NULL ) printf("%ld\n", *p);

  utarray_free(nums);
  return 0;
}
Пример #9
0
/* Connect basic blocks with a directed edge.  */
static edge
link_blocks (struct control_flow_graph *cfg, basic_block src, basic_block dest)
{
  edge new_edge = (edge) malloc (sizeof (struct edge_def));
  memset (new_edge, 0, sizeof (struct edge_def));
  new_edge->src = src;
  new_edge->dest = dest;
  /* Add an edge to the source basic block.  */
  utarray_push_back (src->succs, &new_edge);
  /* Add an edge to the destination basic block.  */
  utarray_push_back (dest->preds, &new_edge);
  /* Add an edge to a list with all edges for CFG of current function.  */
  utarray_push_back (cfg->edge_list, &new_edge);
  return new_edge;
}
Пример #10
0
/* This function copies the tree present in shared_region into the my_tree data structure for rank.
 * Doesn't perform any direct allocation, but utarray_new is called to allocate space for children
 * in my_tree.
 * */
void MPIDI_SHM_copy_tree(int *shared_region, int num_ranks, int rank,
                         MPIR_Treealgo_tree_t * my_tree, int *topotree_fail)
{
    int c;
    int *parent_ptr = shared_region;
    int *child_ctr = &shared_region[num_ranks];
    int *children = &shared_region[num_ranks + num_ranks + 1];
    int parent = parent_ptr[rank];
    int num_children = child_ctr[rank + 1] - child_ctr[rank];
    int *my_children = &children[child_ctr[rank]];

    my_tree->parent = parent;
    my_tree->num_children = 0;
    my_tree->rank = rank;
    my_tree->nranks = num_ranks;
    utarray_new(my_tree->children, &ut_int_icd, MPL_MEM_COLL);
    utarray_reserve(my_tree->children, num_children, MPL_MEM_COLL);
    char str[1024], tmp[128];
    sprintf(str, "----**Rank %d, Parent, %d, Child(%d)[", rank, parent, num_children);
    for (c = 0; c < num_children; ++c) {
        utarray_push_back(my_tree->children, &my_children[c], MPL_MEM_COLL);
        if (my_children[c] == 0) {
            *topotree_fail = 1;
        }
        sprintf(tmp, "%d, ", my_children[c]);
        strcat(str, tmp);
        my_tree->num_children++;
    }
    if (MPIDI_SHM_TOPOTREE_DEBUG)
        fprintf(stderr, "%s]\n", str);
}
Пример #11
0
Файл: udi.c Проект: jfmc/yap-6.3
/* called from cdmgr.c
 *
 * for each assert of a udipredicate
 * to pass info to user structure
 */
int
Yap_new_udi_clause(PredEntry *p, yamop *cl, Term t)
{
	int i;
	UdiPArg parg;
	UdiInfo info;
	YAP_Int index;

	/* try to find our structure */
	HASH_FIND_UdiInfo(UdiControlBlocks,p,info);
	if (!info)
		return FALSE;

	/* insert into clauselist */
	utarray_push_back(info->clauselist, &cl);

	for (i = 0; i < utarray_len(info->args) ; i++) {
		parg = (UdiPArg) utarray_eltptr(info->args,i);
		index = (YAP_Int) utarray_len(info->clauselist);
		parg->idxstr = parg->control->insert(parg->idxstr, t,
											 parg->arg,
											 (void *) index);
	}
	return TRUE;
}
Пример #12
0
/**
 * Load uint16 array.
 * @param[in] option Configuration option.
 * @param[in,out] array Resulting array.
 * @return <0 - error. 0 - success. >0 - not found.
 */
static int zcfg_load_uint16_array(const config_setting_t *option, UT_array *array)
{
    utarray_init(array, &ut_uint16_icd);

    if (!option) {
        return 1;
    }

    if (CONFIG_TYPE_ARRAY != option->type) {
        return -1;
    }

    int count = config_setting_length(option);

    for (int i = 0; i < count; i++) {
        int item = config_setting_get_int_elem(option, i);

        if ((item < 0) || (item > UINT16_MAX)) {
            ZLOG(LOG_ERR, "config:%s:%s: invalid port: %d", option->parent->name, option->name, item);
            utarray_done(array);
            return -1;
        }

        uint16_t port = (uint16_t) item;
        utarray_push_back(array, &port);
    }

    if (utarray_len(array)) {
        utarray_sort(array, uint16_cmp);
    }

    return 0;
}
Пример #13
0
static void
fxaddon_load_numbered_entries(UT_array *ret, FcitxDesktopGroup *grp,
                              const char *prefix, boolean stop_at_empty)
{
    utarray_init(ret, fcitx_ptr_icd);
    size_t prefix_len = strlen(prefix);
    char *buff = malloc(prefix_len + FCITX_INT_LEN + 1);
    memcpy(buff, prefix, prefix_len);
    char *num_start = buff + prefix_len;
    int i;
    FcitxDesktopEntry *tmp_ety;
    for (i = 0;;i++) {
        sprintf(num_start, "%d", i);
        tmp_ety = fcitx_desktop_group_find_entry(grp, buff);
        if (!tmp_ety)
            break;
        if (!(tmp_ety->value && *tmp_ety->value)) {
            if (stop_at_empty) {
                break;
            } else {
                continue;
            }
        }
        utarray_push_back(ret, &tmp_ety->value);
    }
    free(buff);
}
Пример #14
0
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);
}
void postorderRecursive(struct TreeNode* node, UT_array* v) {
    if (node != NULL) {
        postorderRecursive(node->left, v);
        postorderRecursive(node->right, v);
        utarray_push_back(v, &node->val);
    }
}
Пример #16
0
static TSK_WALK_RET_ENUM
find_file_act(TSK_FS_FILE * fs_file, const char *a_path, void *ptr)
{
    char* filename= NULL;
    int path_len = 0;
    MBA_FFIND_DATA *data = (MBA_FFIND_DATA *) ptr;
    /* We found it! */
    if (fs_file->name->meta_addr == data->inode) {
        data->found = 1;


        path_len = strlen(a_path)+strlen(fs_file->name->name)+3;
        filename = (char*)malloc(path_len);
        if(filename==NULL)
        {
            printf("Can not allocate memory!\n");
            return TSK_WALK_CONT;
        }
        snprintf(filename, path_len-1, "/%s%s", a_path, fs_file->name->name);
        utarray_push_back(data->filenames, &filename);

        if (!(data->flags & TSK_FS_FFIND_ALL)) {
            return TSK_WALK_STOP;
        }
    }
    return TSK_WALK_CONT;
}
Пример #17
0
int main(int argc, char *argv[]) {
  char *prog = argv[0];
  int opt, rc=-1;
  hex_t h;

  utarray_new(cfg.hexv, &hex_icd);

  while ( (opt = getopt(argc, argv, "v+i:o:h")) != -1) {
    switch (opt) {
      case 'v': cfg.verbose++; break;
      case 'i': cfg.infile = strdup(optarg); break;
      case 'o': cfg.outfile = strdup(optarg); break;
      case 'h': default: usage(prog); break;
    }
  }

  if (!cfg.outfile || !cfg.infile) usage(prog);

  /* read input file */
  tpl_node *tn = tpl_map("A(sii)", &h.id, &h.x, &h.y);
  if (tpl_load(tn, TPL_FILE, cfg.infile)) goto done;
  while(tpl_unpack(tn,1) > 0) utarray_push_back(cfg.hexv, &h);
  tpl_free(tn);

  find_bounds();
  draw_image();
  rc = 0;

 done:
  utarray_free(cfg.hexv);
  return rc;

}
Пример #18
0
void hook_add_intl(int id, Plugin *host, Plugin *caller, hook_cb fn, int ev)
{
  log_msg("HOOK", "ADD_INTL");
  EventHandler *evh = get_event(ev);

  Hook hook = { id, HK_INTL, NULL, caller, host, NULL, .data.fn = fn };
  utarray_push_back(evh->hooks, &hook);
}

static void hook_rm_container(UT_array *ary, Plugin *host, Plugin *caller)
{
  for (int i = 0; i < utarray_len(ary); i++) {
    Hook *it = (Hook*)utarray_eltptr(ary, i);
    if (it->host == host && it->caller == caller) {
      log_err("HOOK", "RM_INTL");
      utarray_erase(ary, i, 1);
    }
  }
}

void hook_rm_intl(Plugin *host, Plugin *caller, hook_cb fn, int ev)
{
  log_msg("HOOK", "RM_INTL");
  EventHandler *evh = get_event(ev);
  if (!evh)
    return;
  hook_rm_container(evh->hooks, host, caller);
}
Пример #19
0
Файл: ui.c Проект: pkg-ime/fcitx
FCITX_EXPORT_API
void FcitxUIRegisterStatus(
    struct _FcitxInstance* instance,
    void* arg,
    const char* name,
    const char* shortDesc,
    const char* longDesc,
    void (*toggleStatus)(void *arg),
    boolean(*getStatus)(void *arg)
)
{
    FcitxUIStatus status;

    memset(&status, 0 , sizeof(FcitxUIStatus));

    status.name = strdup(name);

    status.shortDescription = strdup(shortDesc);

    status.longDescription = strdup(longDesc);

    status.getCurrentStatus = getStatus;

    status.toggleStatus = toggleStatus;

    status.arg = arg;
    
    status.visible = true;

    UT_array* uistats = &instance->uistats;

    utarray_push_back(uistats, &status);
}
Пример #20
0
FCITX_EXPORT_API
void FcitxUIRegisterComplexStatus(
    struct _FcitxInstance* instance,
    void* arg,
    const char* name,
    const char* shortDesc,
    const char* longDesc,
    void (*toggleStatus)(void *arg),
    const char*(*getIconName)(void *arg)
)
{
    FcitxUIComplexStatus compstatus;

    memset(&compstatus, 0 , sizeof(FcitxUIComplexStatus));
    compstatus.name = strdup(name);
    compstatus.shortDescription = strdup(shortDesc);
    compstatus.longDescription = strdup(longDesc);
    compstatus.getIconName = getIconName;
    compstatus.toggleStatus = toggleStatus;
    compstatus.arg = arg;
    compstatus.visible = true;

    UT_array* uicompstats = &instance->uicompstats;

    utarray_push_back(uicompstats, &compstatus);
    if (UI_FUNC_IS_VALID(RegisterComplexStatus))
        instance->ui->ui->RegisterComplexStatus(instance->ui->addonInstance, (FcitxUIComplexStatus*) utarray_back(uicompstats));
    if (UI_FUNC_IS_VALID_FALLBACK(RegisterComplexStatus))
        instance->uifallback->ui->RegisterComplexStatus(instance->uifallback->addonInstance, (FcitxUIComplexStatus*) utarray_back(uicompstats));
}
Пример #21
0
UT_array* memfrs_scan_virmem( CPUState *cpu, uint64_t start_addr, uint64_t end_addr, const char* pattern, int length ) {
    uint64_t i;

    if(start_addr >= end_addr) {
        printf("end_addr is not less than start_addr\n");
        return NULL;
    }

    uint8_t* buf = (uint8_t*)malloc(length);
    UT_array *match_addr;

    memset(buf, 0, length);

    if(buf == NULL) {
        printf("Cannot allocate memory for do_show_memory_taint_map()\n");
        return NULL;
    }

    utarray_new( match_addr, &adr_icd);

    printf("Scan for pattern %s\n", pattern);

    for(i = start_addr; i < end_addr-length+1; i++)
    {
        cpu_memory_rw_debug(cpu, i, buf, length, 0);
        if(memcmp(buf, pattern, length)==0)
        {
            printf("pattern found %lx\n", i);
            utarray_push_back(match_addr, &i);
        }
    }
    return match_addr;
}
Пример #22
0
Файл: udi.c Проект: jfmc/yap-6.3
/*
 * 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;
}
Пример #23
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;
}
Пример #24
0
/*******************************************************************
UT_array* memfrs_scan_phymem( uint64_t start_addr, uint64_t end_addr, const char* pattern )

Scan for specific pattern in the VM's physical memory

INPUT:    uint64_t start_addr,  The start address
          uint64_t end_addr,    the end address
          const char* pattern   pattern to search, support only ascii string
OUTPUT:   UT_array*,            An UT_array that contains the address of found pattern

*******************************************************************/
UT_array* memfrs_scan_phymem( uint64_t start_addr, uint64_t end_addr, const char* pattern , int length ) {
    uint64_t i;
    UT_array *match_addr;
    if(start_addr >= end_addr) {
        printf("end_addr is not less than start_addr\n");
        return NULL;
    }

    uint8_t* buf = (uint8_t*)malloc(length);
    if(buf == NULL) {
        printf("Cannot allocate memory for memfrs_scan_phymem()\n");
        return NULL;
    }

    utarray_new( match_addr, &adr_icd);

    printf("Scan for pattern %s\n", pattern);
    for(i = start_addr; i < end_addr-length+1; i++)
    {
        cpu_physical_memory_read(i, buf, length);
        if(memcmp(buf, pattern, length)==0)
        {
            printf("pattern found %lx\n", i);
            utarray_push_back(match_addr, &i);
        }
    }
    return match_addr;
}
Пример #25
0
void LoadAutoEng(FcitxAutoEngState* autoEngState)
{
    FILE    *fp;
    char    *buf = NULL;
    size_t   length = 0;

    LoadAutoEngConfig(&autoEngState->config);
    fp = FcitxXDGGetFileWithPrefix("data", "AutoEng.dat", "r", NULL);
    if (!fp)
        return;

    utarray_new(autoEngState->autoEng, &autoeng_icd);
    AUTO_ENG autoeng;

    while (getline(&buf, &length, fp) != -1) {
        char* line = fcitx_utils_trim(buf);
        if (strlen(line) > MAX_AUTO_TO_ENG)
            FcitxLog(WARNING, _("Too long item for AutoEng"));
        strncpy(autoeng.str, line, MAX_AUTO_TO_ENG);
        free(line);
        autoeng.str[MAX_AUTO_TO_ENG] = '\0';
        utarray_push_back(autoEngState->autoEng, &autoeng);
    }

    free(buf);

    fclose(fp);
}
Пример #26
0
/*-----------------------------------------------------------------------------
*   process a file
*----------------------------------------------------------------------------*/
static void process_file( char *filename )
{
	char *line;

    strip( filename );

    switch ( filename[0] )
    {
    case '-':		/* Illegal source file name */
        error_illegal_src_filename( filename );
        break;

    case '\0':		/* no file */
        break;

	case '@':		/* file list */
		filename++;						/* point to after '@' */
		strip( filename );

		/* loop on file to read each line and recurse */
		src_push();
		{
			if (src_open(filename, NULL))
			{
				while ((line = src_getline()) != NULL)
					process_file(line);
			}
		}
		src_pop();
		break;

    default:
		utarray_push_back(opts.files, &filename);
    }
}
Пример #27
0
void XimPendingCall(FcitxXimFrontend* xim, XimCallType type, XPointer ptr)
{
    XimQueue item;
    item.type = type;
    item.ptr = ptr;
    utarray_push_back(xim->queue, &item);
}
Пример #28
0
/* accept a new client connection to the listening socket */
int accept_client() {
  int fd, fl;
  struct sockaddr_in in;
  socklen_t sz = sizeof(in);

  fd = accept(cfg.fd,(struct sockaddr*)&in, &sz);
  if (fd == -1) {
    if (errno == EWOULDBLOCK || errno == EAGAIN) goto done;
    fprintf(stderr,"accept: %s\n", strerror(errno)); goto done;
  }

  if (cfg.verbose && (sizeof(in)==sz)) {
    fprintf(stderr,"connection fd %d from %s:%d\n", fd,
    inet_ntoa(in.sin_addr), (int)ntohs(in.sin_port));
  }

  /* request signal whenever input from client is available */
  fl = fcntl(fd, F_GETFL);
  fl |= O_ASYNC|O_NONBLOCK;        /* want a signal on fd ready */
  fcntl(fd, F_SETFL, fl);
  fcntl(fd, F_SETSIG, SIGIO);
  fcntl(fd, F_SETOWN, cfg.pid);    /* send it to our pid */

 done:
  if (fd != -1) utarray_push_back(cfg.fds,&fd);
  return fd;
}
Пример #29
0
/*-----------------------------------------------------------------------------
*   String pool for the current statement
*----------------------------------------------------------------------------*/
static char *token_strings_add(ParseCtx *ctx, char *str)
{
	if (!str)		/* NULL string */
		return NULL;

	utarray_push_back(ctx->token_strings, &str);
	return *((char **)utarray_back(ctx->token_strings));
}
Пример #30
0
static int lines_add(UT_array *lines, const line_t *line)
{
    int i;
    i = lines_find(lines, line);
    if (i) return i;
    utarray_push_back(lines, line);
    return lines_find(lines, line);
}