예제 #1
0
int array_append_unique(struct array *array, const void *element)
{
	void **itr = array->array;
	void **itr_end = itr + array->count;
	for (; itr < itr_end; itr++)
		if (*itr == element)
			return -EEXIST;
	return array_append(array, element);
}
예제 #2
0
void command_hook_register(command_hook_callback_t *pre,
			   command_hook_callback_t *post)
{
	struct command_hook hook;

	hook.pre = pre;
	hook.post = post;
	array_append(&command_hooks, &hook, 1);
}
예제 #3
0
void imapc_msgmap_append(struct imapc_msgmap *msgmap,
                         uint32_t rseq, uint32_t uid)
{
    i_assert(rseq == imapc_msgmap_count(msgmap) + 1);
    i_assert(uid >= msgmap->uid_next);

    msgmap->uid_next = uid + 1;
    array_append(&msgmap->uids, &uid, 1);
}
예제 #4
0
void http_client_delay_request_error(struct http_client *client,
	struct http_client_request *req)
{
	if (client->to_failing_requests == NULL) {
		client->to_failing_requests = timeout_add_short(0,
			http_client_handle_request_errors, client);
	}
	array_append(&client->delayed_failing_requests, &req, 1);
}
예제 #5
0
static void request_add_context(struct indexer_request *request, void *context)
{
	if (context == NULL)
		return;

	if (!array_is_created(&request->contexts))
		i_array_init(&request->contexts, 2);
	array_append(&request->contexts, &context, 1);
}
예제 #6
0
파일: iparse.c 프로젝트: jhawcroft/brain
int nl_input_parse(char const *in_utterance, NLInput **out_result)
{
    /* create a result */
    int err = NL_OK;
    *out_result = NULL;
    NLInput *input = brain_alloc_(sizeof(NLInput), 0);
    if (!input) return NL_EMEM;
    memset(input, 0, sizeof(NLInput));
    
    input->sentences = array_create(NULL, &nl_sentence_disposer_);
    if (!input->sentences) goto nl_input_parse_error;
    
    /* create a giant sentence */
    NLSentence *sentence = nl_sentence_create();
    if (!sentence) goto nl_input_parse_error;
    array_append(input->sentences, sentence);
    
    /* convert the utterance to a single large token */
    NLToken *token = nl_token_create(in_utterance, (int)strlen(in_utterance), NL_TOKFLG_TEXT, NULL, NULL);
    if (!token) goto nl_input_parse_error;
    nl_sentence_append_token(sentence, token);
    
    /* identify specific character patterns */
    for (int i = 0; i < g_nl_context.tokenizer_count; i++)
    {
        err = nl_tokenize(input, &(g_nl_context.tokenizers[i]));
        if (err) goto nl_input_parse_error;
    }
    
    /* split sentences */
    err = nl_split_sentences(input, g_nl_context.sentence_splitter);
    if (err) goto nl_input_parse_error;
    
    /* split the remaining input into words;
     lookup the words */
    err = nl_split_words(input, g_nl_context.word_splitter);
    if (err) goto nl_input_parse_error;
    
    err = nl_wordize(input, g_nl_context.wordizer);
    if (err) goto nl_input_parse_error;
    
    /* trim empty sentences */
    err = nl_trim_empty_sentences(input);
    if (err) goto nl_input_parse_error;
    
#if DEBUG == 1
    //nl_input_debug(input);
#endif
    
    *out_result = input;
    return NL_OK;
    
nl_input_parse_error:
    if (input) nl_input_dispose(input);
    return err;
}
예제 #7
0
int pathexec_env(char *name, char *value) {
  if (!name)
    return 0;
    
  array_trunc(&_pathexec_tmp);
  array_append(&_pathexec_tmp, name, strlen(name));
  if (value) {
    array_append(&_pathexec_tmp, "=", 1);
    array_append(&_pathexec_tmp, value, strlen(value));
  }
  array_append_null(&_pathexec_tmp);
  
  if (!array_allocated(&_pathexec_tmp))
    return 0;
    
  array_append(&_pathexec_plus, _pathexec_tmp.data, _pathexec_tmp.size);
  
  return 1;
}
예제 #8
0
static void
doveadm_print_formatted_header(const struct doveadm_print_header *hdr)
{
	struct var_expand_table entry;
	memset(&entry, 0, sizeof(entry));
	entry.key = '\0';
	entry.long_key = p_strdup(ctx.pool, hdr->key);
	entry.value = NULL;
	array_append(&ctx.headers, &entry, 1);
}
예제 #9
0
int sv_restart_log(char *path, int timeout) {
  array_t sa = ARRAY_INIT(1);
  char *path_log;
  int r;
  
  /* Create a dynamic storage array to contain the full path to the log
   * directory which MUST be freed before returning. */
  array_append(&sa, path, strlen(path));
  if (path[strlen(path) - 1] == '/')
    array_append(&sa, "/", 1);
  array_append(&sa, "log", 3);
  array_append_null(&sa);
  
  path_log = array_start(&sa);
  
  r = sv_restart(path_log, timeout);
  array_reset(&sa);
  return r;
}
void script_client_set_env
(struct script_client *sclient, const char *name, const char *value)
{
	const char *env;

	if ( !array_is_created(&sclient->envs) )
		p_array_init(&sclient->envs, sclient->pool, 16);

	env = p_strdup_printf(sclient->pool, "%s=%s", name, value);
	array_append(&sclient->envs, &env, 1);
}
예제 #11
0
void program_client_set_env
(struct program_client *pclient, const char *name, const char *value)
{
	const char *env;

	if ( !array_is_created(&pclient->envs) )
		p_array_init(&pclient->envs, pclient->pool, 16);

	env = p_strdup_printf(pclient->pool, "%s=%s", name, value);
	array_append(&pclient->envs, &env, 1);
}
예제 #12
0
DLLEXPORT void median_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char *error) {
    struct Buffer *data = (struct Buffer *) initid->ptr;

    if (NULL == args->args[0])
        return;

    if (NULL == array_append(&data->values, args->args[0])) {
        *error = 1;
        return;
    }
}
struct mail_search_result *
mailbox_search_result_save(struct mail_search_context *ctx,
			   enum mailbox_search_result_flags flags)
{
	struct mail_search_result *result;

	result = mailbox_search_result_alloc(ctx->transaction->box,
					     ctx->args, flags);
	array_append(&ctx->results, &result, 1);
	return result;
}
예제 #14
0
//use recursion
void array_insert(CArray *array,int index,int element){
    int temp;
    if (index < array->size) {
        //swap element and array[index]
        temp = array->p[index];
        array->p[index] = element;
        element = temp;
        array_insert(array,++index,element);
    }
    else array_append(array, element);
};
예제 #15
0
void command_register(const char *name, command_func_t *func)
{
	struct command cmd;

	memset(&cmd, 0, sizeof(cmd));
	cmd.name = name;
	cmd.func = func;
	array_append(&managesieve_commands, &cmd, 1);

	commands_unsorted = TRUE;
}
예제 #16
0
파일: obj.c 프로젝트: 0ctobyte/ogl
void obj_parser_vntag(obj_parser_t *p, array_t *a) {
  // vn = "vn", whitespace, float, whitespace, float, whitespace, float
  float v[3];

  for(uint64_t i = 0; i < 3; ++i) {
    obj_parser_expect(p, OBJ_FLOAT);
    v[i] = strtof(array_data(p->token.lexeme), NULL);
  }

  array_append(a, &v);
}
예제 #17
0
파일: pi.c 프로젝트: abfeldman/lydia
static array resolve_int_list_literal(array cx, array cy, int l)
{
    unsigned int posx;
    unsigned int posy;
    unsigned int ix;

    if ((search_sorted_int_list(cx, l, &posx) && search_sorted_int_list(cy, l + 1, &posy)) ||
        (search_sorted_int_list(cx, l + 1, &posx) && search_sorted_int_list(cy, l, &posy))) {
        array cr = array_new(NULL, NULL);
        unsigned int iy = 0;
        for (ix = 0; ix < cx->sz; ix++) {
            if (ix == posx) {
                continue;
            }
            while ((iy < cy->sz) && (p2i(cy->arr[iy]) / 2) < (p2i(cx->arr[ix]) / 2)) {
                if (iy != posy) {
                    array_append(cr, cy->arr[iy]);
                }
                iy += 1;
            }
            if (iy != cy->sz) {
                if (p2i(cx->arr[ix]) == p2i(cy->arr[iy]) + (p2i(cx->arr[ix]) % 2 ? 1 : -1)) {
                    array_free(cr);
                    return NULL;
                }
                if (cx->arr[ix] == cy->arr[iy]) {
                    continue;
                }
            }
            array_append(cr, cx->arr[ix]);
        }
        while (iy < cy->sz) {
            if (iy != posy) {
                array_append(cr, cy->arr[iy]);
            }
            iy += 1;
        }
        return cr;
    }
    return NULL;
}
예제 #18
0
파일: obj.c 프로젝트: 0ctobyte/ogl
void obj_parser_vtag(obj_parser_t *p, array_t *a) {
  // v = 'v', whitespace, float, whitespace, float, whitespace, float
  // A vtag is followed by 3 floats
  float v[3];

  for(uint64_t i = 0; i < 3; ++i) {
    obj_parser_expect(p, OBJ_FLOAT);
    v[i] = strtof(array_data(p->token.lexeme), NULL);
  }

  array_append(a, &v);
}
예제 #19
0
static array *read_nodes(const char *hostsfile)
{
  array *nodenames;
  int start = 0;
  int pos = 0;
  array *filedata;
  FILE *f;
  int r;
  char buf[1024];

  if (NULL == (f = fopen(hostsfile,"r"))) {
    perror(hostsfile);
    return NULL;
  }

  filedata = array_new(1,0);
  while (0 < (r = fread(buf,1,1024,f)))
    array_append(filedata,buf,r);
  fclose(f);

  nodenames = array_new(sizeof(char*),0);
  while (1) {
    if ((pos == filedata->nbytes) ||
        ('\n' == filedata->data[pos])) {
      if (pos > start) {
        char *line = (char*)malloc(pos-start+1);
        memcpy(line,&filedata->data[start],pos-start);
        line[pos-start] = '\0';
        array_append(nodenames,&line,sizeof(char*));
      }
      start = pos+1;
    }
    if (pos == filedata->nbytes)
      break;
    pos++;
  }

  free(filedata);
  return nodenames;
}
예제 #20
0
파일: main.cpp 프로젝트: yilirin/CPPHW1
int main()
{
    CArray array;
    array_initial(&array);
    
    array_recap(&array, 10);
    assert(array_capacity(&array) == 10);
    
    //////////////////////////////////////////////////////////////////////////
    for (int i = 0; i < 20; ++i)
    {
        array_append(&array, i);
    }
    assert(array_size(&array) == 20);
    
//    printarray(&array);
    
    for (int i = 0; i < array_size(&array); ++i)
    {
        assert(*array_at(&array, i) == i);
    }
    
    //////////////////////////////////////////////////////////////////////////
    CArray array2, array3;
    array_initial(&array2);
    array_initial(&array3);
    
    array_copy(&array, &array2);

    assert(array_compare(&array, &array2) == true);
    array_copy(&array, &array3);
    assert(array_compare(&array, &array3) == true);
//    printarray(&array2);
    
    //////////////////////////////////////////////////////////////////////////
    array_insert(&array2, 2, 3);
    assert(array_compare(&array, &array2) == false);
//    printarray(&array2);

    
    //////////////////////////////////////////////////////////////////////////
    *array_at(&array3, 2) = 5;
    assert(array_compare(&array, &array3) == false);
//    printarray(&array3);

    //////////////////////////////////////////////////////////////////////////
    array_destroy(&array);
    array_destroy(&array2);
    array_destroy(&array3);
    
    return 0;
}
예제 #21
0
int mail_index_map_parse_extensions(struct mail_index_map *map)
{
	struct mail_index *index = map->index;
	const struct mail_index_ext_header *ext_hdr;
	unsigned int i, old_count, offset;
	const char *name, *error;
	uint32_t ext_id, ext_map_idx, ext_offset;

	/* extension headers always start from 64bit offsets, so if base header
	   doesn't happen to be 64bit aligned we'll skip some bytes */
	offset = MAIL_INDEX_HEADER_SIZE_ALIGN(map->hdr.base_header_size);
	if (offset >= map->hdr.header_size && map->extension_pool == NULL) {
		/* nothing to do, skip allocatations and all */
		return 0;
	}

	old_count = array_count(&index->extensions);
	mail_index_map_init_extbufs(map, old_count + 5);

	ext_id = (uint32_t)-1;
	for (i = 0; i < old_count; i++)
		array_append(&map->ext_id_map, &ext_id, 1);

	for (i = 0; offset < map->hdr.header_size; i++) {
		ext_offset = offset;

		if (mail_index_map_ext_get_next(map, &offset,
						&ext_hdr, &name) < 0) {
			mail_index_set_error(index, "Corrupted index file %s: "
				"Header extension #%d (%s) goes outside header",
				index->filepath, i, name);
			return -1;
		}

		if (mail_index_map_ext_hdr_check(&map->hdr, ext_hdr,
						 name, &error) < 0) {
			mail_index_set_error(index, "Corrupted index file %s: "
					     "Broken extension #%d (%s): %s",
					     index->filepath, i, name, error);
			return -1;
		}
		if (mail_index_map_lookup_ext(map, name, &ext_map_idx)) {
			mail_index_set_error(index, "Corrupted index file %s: "
				"Duplicate header extension %s",
				index->filepath, name);
			return -1;
		}

		(void)mail_index_map_register_ext(map, name, ext_offset, ext_hdr);
	}
	return 0;
}
예제 #22
0
파일: utils.c 프로젝트: abudrys/rss
array_t *array_init_split_string(char *string, const char *delims)
{
	array_t *ret = array_init(0);
	char *token;
	
	while ((token = strsep(&string, delims))) {
		if (strlen(token))
			array_append(ret, (void *)xstrdup(token));
	}
	
	free(string);
	return ret;
}
예제 #23
0
static struct mail_search_register *
mail_search_register_init_human(struct mail_search_register *imap_register)
{
	struct mail_search_register *reg;
	mail_search_register_fallback_t *fallback;
	ARRAY(struct mail_search_register_arg) copy_args;
	const struct mail_search_register_arg *human_args, *imap_args;
	unsigned int i, j, human_count, imap_count;
	int ret;

	reg = mail_search_register_init();
	mail_search_register_add(reg, human_register_args,
				 N_ELEMENTS(human_register_args));

	/* find and register args in imap that don't exist in human */
	imap_args = mail_search_register_get(imap_register, &imap_count);
	human_args = mail_search_register_get(reg, &human_count);
	t_array_init(&copy_args, imap_count);
	for (i = j = 0; i < imap_count && j < human_count; ) {
		ret = strcmp(imap_args[i].key, human_args[j].key);
		if (ret < 0) {
			array_append(&copy_args, &imap_args[i], 1);
			i++;
		} else if (ret > 0) {
			j++;
		} else {
			i++; j++;
		}
	}
	for (; i < imap_count; i++)
		array_append(&copy_args, &imap_args[i], 1);

	imap_args = array_get(&copy_args, &imap_count);
	mail_search_register_add(reg, imap_args, imap_count);

	if (mail_search_register_get_fallback(imap_register, &fallback))
		mail_search_register_fallback(reg, fallback);
	return reg;
}
예제 #24
0
파일: array.c 프로젝트: 52nlp/icsiboost
void array_insert(array_t* input, size_t index, array_t* peer)
{
	if(index<0) array_prepend(input, peer);
	else if(index>=input->length) array_append(input, peer);
	else {
		arrayelement_t* element=peer->last;
		while(element)
		{
			array_insert_element(input, index, element->data);
			element=element->previous;
		}
	}
}
예제 #25
0
파일: atms.c 프로젝트: abfeldman/lydia
int atms_add_justification(atms tms, const_material_implication cl)
{
    register unsigned int ix;

    atms_justification justification;

    trie I;

    array key;

    if (NULL == (justification = atms_justification_new())) {
        return 0;
    }

    for (ix = 0; ix < cl->antecedents->sz; ix++) {
        atms_node node = tms->nodes->arr[cl->antecedents->arr[ix] + 1];
        array_append(justification->antecedents, node);

        array_append(node->consequences, justification);
    }
    if (cl->consequent == -1) {
        justification->consequent = tms->nodes->arr[0];
    } else {
        justification->consequent = tms->nodes->arr[cl->consequent + 1];
    }

    array_append(tms->justifications, justification);

    I = trie_new((trie_node_destroy_func_t)array_free,
                 (trie_node_clone_func_t)array_copy);
/* Append the empty environment. */
    key = array_new(NULL, NULL);
    trie_add(I, key, array_new(NULL, NULL));
    array_free(key);
    propagate(tms, justification, NULL, I);
    trie_free(I);

    return 1;
}
예제 #26
0
파일: atms.c 프로젝트: abfeldman/lydia
static array get_environment_key(array env)
{
    register unsigned int ix;

    array result = array_new(NULL, NULL);

    for (ix = 0; ix < env->sz; ix++) {
        atms_node node = (atms_node)env->arr[ix];
        array_append(result, i2p(node->index));
    }

    return result;
}
예제 #27
0
void command_register(const char *name, command_func_t *func,
		      enum command_flags flags)
{
	struct command cmd;

	memset(&cmd, 0, sizeof(cmd));
	cmd.name = name;
	cmd.func = func;
	cmd.flags = flags;
	array_append(&imap_commands, &cmd, 1);

	commands_unsorted = TRUE;
}
예제 #28
0
파일: main.c 프로젝트: brucespang/remodel
// Tarjan's Algorithm from wikipedia
static uint32_t strongly_connected(struct stack* stack, remodel_node_t* node, uint32_t* index) {
  node->index = *index;
  node->low_index = *index;
  (*index)++;
  stack_push(stack, node);

  ht_entry_t* entry;
  ht_iterator_t iter = HT_ITERATOR_INITIALIZER;
  while (ht_next(node->children, &iter, &entry)) {
    remodel_edge_t* edge = entry->value;
    assert(edge->from == node);

    if (edge->to->index == 0) {
      strongly_connected(stack, edge->to, index);
      node->low_index = min(node->low_index, edge->to->low_index);
    } else if(stack_contains(stack, edge->to)) {
      node->low_index = min(node->low_index, edge->to->index);
    }
  }

  if (node->low_index == node->index) {
    array_t* component = array_new();
    remodel_node_t* w;
    do {
      assert(!stack_is_empty(stack));
      w = stack_pop(stack);
      array_append(component, w);
    } while (w != node);

    if (component->len > 1) {
      fprintf(stderr, "error: dependency graph contains cycle:\n");
      fprintf(stderr, "  [");
      for (uint32_t i = 0; i < component->len; i++) {
        remodel_node_t* n = array_get(component, i);
        fprintf(stderr, "%s", n->name);
        if (i != component->len - 1) {
          fprintf(stderr, ", ");
        }
      }
      fprintf(stderr, "]\n");

      array_free(component);
      return true;
    } else {
      array_free(component);
      return false;
    }
  } else {
    return false;
  }
}
예제 #29
0
int hardware_add_stack(Stack *stack) {
	Stack **new_stack = array_append(&_stacks);

	if (new_stack == NULL) {
		log_error("Could not append to stack array: %s (%d)",
		          get_errno_name(errno), errno);

		return -1;
	}

	*new_stack = stack;

	return 0;
}
예제 #30
0
void			array_merge(t_array *dest, t_array *src)
{
	unsigned int	i;

	ft_assert(src != NULL);
	ft_assert(dest != NULL);
	i = 0;
	while (i < src->size)
	{
		array_append(dest, src->data[i]);
		i++;
	}
	array_destroy(src);
}