Esempio n. 1
0
static char	add_v_f(t_object *obj, char **tmp, char *last, int offset)
{
	int		res;
	char	l;

	res = 1;
	l = *last;
	*last = tmp[0][0];
	if (ft_strlen(tmp[0]) == 1 && tmp[0][0] == 'v')
		add_elem(&obj->vertex, new_vector3f(ft_atof(tmp[1]), ft_atof(tmp[2]), \
			ft_atof(tmp[3])));
	else if (tmp[0][0] == 'f')
	{
		put_indices(&obj->indices, ft_atoi(tmp[1]) - 1 - offset, ft_atoi(tmp[2]) - 1 - offset, \
			ft_atoi(tmp[3]) - 1 - offset);
		if (ft_tabsize((void **)tmp) == 5)
			put_indices(&obj->indices, ft_atoi(tmp[3]) - 1 - offset, \
				ft_atoi(tmp[4]) - 1 - offset, ft_atoi(tmp[1]) - 1 - offset);
	}
	else if (ft_strlen(tmp[0]) > 1 && tmp[0][0] == 'v' && tmp[0][1] == 'n')
		add_elem(&obj->normals, new_vector3f(ft_atof(tmp[1]), ft_atof(tmp[2]), \
			ft_atof(tmp[3])));
	else
	{
		*last = l;
		res = 0;
	}
	return (res);
}
Esempio n. 2
0
int main(void){
    char *dllName = choose_way();
    dynamic_t *dll = dynamic_init(dllName);
    if(!dll){
        printf("\nError: could not recieve dll name");
        return 0;
    }
    if(!dll->chk || !dll->react){
        printf("\nError: could not recieve dll funcltion name");
        return 0;
    }

    char sample[ARRAY_SIZE];
    srand(time(NULL));
    printf("\n");
    for(int i = 0; i < ARRAY_SIZE; i++){
        switch(rand() % SPACE_CHANCE + 1){
            case SPACE_CHANCE:
                add_elem(sample, i, ' ');
                break;
            default:
                add_elem(sample, i, rand() % 58 + 65);
                break;
        }
    }
    printf("\n%s", sample);
    if(dll->chk(sample, ARRAY_SIZE)){
        printf("\nReaction positive!");
        dll->react(sample, ARRAY_SIZE);
    }
    else
        printf("\nReaction negative!");
    dynamic_clean(dll);
    return 0;
}
Esempio n. 3
0
int script_read(FILE *stream, struct fcontainer *server, struct fcontainer *client)
{
	char line[FIX_MAX_LINE_LENGTH];
	int size = FIX_MAX_LINE_LENGTH;

	line[size - 1] = 0;

	while (fgets(line, size, stream)) {
		/* Line is too long */
		if (line[size - 1])
			return 1;

		switch (line[0]) {
			case 'c':
			case 'C':
				if (init_elem(add_elem(client), line + 1))
					return 1;
				break;
			case 's':
			case 'S':
				if (init_elem(add_elem(server), line + 1))
					return 1;
				break;
			default:
				break;
		}
	}

	return 0;
}
Esempio n. 4
0
t_tree		*line_to_list(char *str)
{
  t_tree	*list;
  char		*ret;
  int		curs;

  curs = 0;
  list = NULL;
  while (str[curs])
    {
      ret = sort_chain(str, &curs);
      if ((ret == NULL && str[curs]) || (ret != NULL && ret[0] == '\0'))
	return (NULL);
      else if (ret == NULL && !str[curs])
	return (list);
      add_elem(&list, ret);
      ret = take_separ(str, &curs);
      if (ret == NULL && str[curs])
	return (NULL);
      else if (ret == NULL && !str[curs])
	return (list);
      add_elem(&list, ret);
      while (str[curs] == ' ' || str[curs] == '\t')
	curs++;
    }
  return (list);
}
Esempio n. 5
0
/*
 * c1*t1 + c2*t2
 */
ArithmeticTerm::ArithmeticTerm(Term* t1, long int c1, Term* t2, long int c2)
{
	this->type = ARITHMETIC_TERM;
	this->constant = 0;
	this->elem_gcd = -1;
	add_elem(t1, c1);
	add_elem(t2, c2);
	compute_hash_code();
}
Esempio n. 6
0
static void	put_indices(t_list *indices_list, int a, int b, int c)
{
	int		*indices;

	indices = ft_memalloc(sizeof(int) * 3);
	indices[0] = a;
	add_elem(indices_list, &indices[0]);
	indices[1] = b;
	add_elem(indices_list, &indices[1]);
	indices[2] = c;
	add_elem(indices_list, &indices[2]);
}
Esempio n. 7
0
void buffer::add_block (const block & b)
{
	for (std::list<size_t>::const_iterator it = b.data.begin(); it != b.data.end(); ++ it)
	{
		add_elem(*it);
	}
}
Esempio n. 8
0
static char	*cmp_line(t_lst *node, char **arg, char *save)
{
	t_lst	*tmp;

	tmp = node;
	while (node)
	{
		if (ft_strccmp(node->line, *arg, '=') == 0)
		{
			save = ft_strdup(node->line);
			node->line = ft_strdup(*arg);
			return (save);
		}
		node = node->next;
	}
	node = tmp;
	save = NULL;
	if (!save)
	{
		if (check_caract(*arg, '=') == 1)
			add_elem(node, *arg);
		else if (check_caract(*arg, '=') != 1)
			deal_with_command(node, arg);
		else
			print_error_opt(*arg);
	}
	return (save);
}
Esempio n. 9
0
int main(int argc, char **argv)
{
    tree *first_elem;
    char *str;
    int n;
    str = (char *) calloc(10, sizeof(char));
    first_elem = NULL;
    if (argc == 2) {
        if ((strcmp(argv[1], "-h")) == 0) {
            puts("Instructions for use:");
            puts("1.Launch file:");
            puts(" gcc-Wall-Wextra-o lab4.exe lab4.c");
            puts(" ./lab4.exe");
            puts("2.In the screen prompts you to enter the first element of a tree (root).");
            puts("    Enter it. Next, you are prompted to enter ocheredenoy the tree.");
            puts("    Enter it. Proposals will be displayed as long as you do not enter '0'.");
            puts("    Next, you are prompted to enter the level for which you want to calculate the number of nodes.");
            puts("    Enter it.");
            puts("3.The displayed the number of nodes at a given level or '0' if the current level");
            puts("    does not exist or at no nodes.");
            return 0;
        }
    }
    first_elem = create_tree(first_elem);
    add_elem(first_elem);
    puts("Enter level");
    enter_number(str,&n);
    printf("number of nod on level %d: %d", n,
           calculate_number_of_nod(first_elem, n));
    return 0;
}
Esempio n. 10
0
bheap_t *add_heap(bheap_t *src, bheap_t *dest)
{
        for (int i = 0; i < src->index; i++)
                dest = add_elem(src->elems[i], dest);

        return dest;
}
Esempio n. 11
0
/**
  This constructor calculates the inverse wavelet packet transform.
  The constructor is passed a packdata_list object, which contains
  the "best basis" result of the wavelet packet transform.  The 
  liftbase template argument is a pointer to a wavelet transform
  function.  This wavelet transform must be the same function that
  was used to calculate the packet transform.

 */
invpacktree_int::invpacktree_int( packdata_list<int> &list, 
				  liftbase<packcontainer_int, int> *w )
{
  data = 0;
  N = 0;
  waveObj = w;

  // Traverse the "best basis" list and calculate the inverse
  // wavelet packet transform.
  packdata_list<int>::handle h;
  for (h = list.first(); h != 0; h = list.next( h )) {
    packdata<int> *elem = list.get_item( h );
    add_elem( elem );
  } // for

  LIST<packcontainer_int *>::handle tosHandle;
  tosHandle = stack.first();
  packcontainer_int *tos = stack.get_item( tosHandle );

  if (tos != 0) {
    size_t len = tos->length();
    N = len/2;

    data = tos->lhsData();
    stack.remove();
  }
} // invpacktree_int
Esempio n. 12
0
void AddDialog::add()
{
    QString name = nameInput->text();
    add_elem(name);
    emit list_updated();
    hide();
}
Esempio n. 13
0
void update_have_peer(rcb_t *head, hash_v_t hash[], int cnt, short id)
{
    rcb_t *p;
    chunk_map_t *chk_map;
    int n;

    for(n = 0; n < cnt; n++)
    {
        p = head;
        while(p)
        {
            chk_map = p->chk_map;
            assert(chk_map);
            if(!memcmp(chk_map->hash, hash[n].hash, SHA1_HASH_SIZE))
            {
                if(!p->have_peers)
                {
                    p->have_peers = new_darr();
                    if(!p->have_peers)
                        return ;
                }

                add_elem(p->have_peers, (uint32_t)id);
            }

            p = p->next;
        }
    }
}
Esempio n. 14
0
File: env.c Progetto: Zethir/42sh
static int	deal_with_arg(t_shell *sh, char **arg, char **env_cpy)
{
	char	**res;
	char	*cmd;

	res = NULL;
	if (cmp_line(arg, env_cpy) == 0)
	{
		if (check_caract(*arg, '=') < 0)
			return (print_wrong_identifier_env(*arg));
		else if (check_caract(*arg, '=') != 1)
		{
			cmd = join_tab(arg);
			exec_env(sh, cmd, env_cpy);
			free(cmd);
			return (sh->return_val);
		}
		else if (check_caract(*arg, '=') == 1)
		{
			res = add_elem(env_cpy, *arg);
			ft_print_tab(res);
			ft_free_tab(res);
			return (0);
		}
	}
	ft_print_tab(env_cpy);
	return (0);
}
Esempio n. 15
0
/*
 * t * c
 */
ArithmeticTerm::ArithmeticTerm(Term* t, long int c)
{
	this->type = ARITHMETIC_TERM;
	this->constant = 0;
	this->elem_gcd = -1;
	add_elem(t, c);
	compute_hash_code();
}
Esempio n. 16
0
/*
    Add a new obj and the node id to the prefix tree.
    Repeate obj and nid association will not be added twice
 */
int pft_add_obj(char *obj, uint32_t nid)
{
    assert(strlen(obj) <= OBJ_NAME_LEN);
    char buff[OBJ_NAME_LEN + 1];
    int start_idx = 0;

    pf_node_t **curr_lv_rt = &g_obj_pft; // current level root prefix
    pf_node_t *curr_node = *curr_lv_rt;
    pf_node_t *target = NULL;

    while(0 == get_next_field(obj, start_idx, '/', buff, &start_idx))
    {
        // search the current level prefix
        while(curr_node)
        {
            if(!strcmp(buff, curr_node->prefix))
                break;

            curr_node = curr_node->next_peer;
        }
        
        if(!curr_node) // not found
        {
            curr_node = new_node();
            if(!curr_node)
                return -1;

            strcpy(curr_node->prefix, buff);
            curr_node->next_peer = *curr_lv_rt;
            *curr_lv_rt = curr_node;
        }
      
        target = curr_node; 
        curr_lv_rt = &curr_node->next_child;
        curr_node = *curr_lv_rt;
    }

    assert(target != NULL);
   
    // store the nid to the current prefix level node
    if(target->darr == NULL)
    {
        target->darr = new_darr();
    
        if(target->darr == NULL)
            return -1;
    }

    // check repeating before add
    if(-1 == get_elem_idx(target->darr, nid))
    {
        if(-1 == add_elem(target->darr, nid))
            return -1;
    }

    return 0;
}
Esempio n. 17
0
int script_read(FILE *stream, struct fcontainer *self)
{
	char line[FAST_MAX_LINE_LENGTH];
	int size = FAST_MAX_LINE_LENGTH;

	line[size - 1] = 0;

	add_elem(self);
	while (fgets(line, size, stream)) {
		if (line[size - 1])
			goto fail;

		if (init_elem(add_elem(self), line))
			goto fail;
	}

	return 0;

fail:
	return 1;
}
chatmessage_t* process_packet(chatmessage_t* message, packet_t* newpacket)
{
  //if so, and if the message is not complete, add this packet's contents to it
  //if not, create a new chatmessage
  if(message)
    append_to_chatmessage(message, newpacket);
  else
  {
    message = create_chatmessage(newpacket);
    add_elem(UNSEQ_CHAT_MSGS, (void*)message);
  }
  return message;
}
Esempio n. 19
0
ArithmeticTerm::ArithmeticTerm(const map<Term*, long int>& elems,
		long int constant)
{
	this->type = ARITHMETIC_TERM;
	this->constant = constant;
	this->elem_gcd = -1;
	map<Term*, long int>::const_iterator it = elems.begin();
	for(; it!= elems.end(); it++)
	{
		add_elem(it->first, it->second);
	}

	compute_hash_code();
}
Esempio n. 20
0
t_list		*create_list(char **av)
{
  t_list	*list;
  t_elem	*elem;
  int		n;

  n = -1;
  list = init_list();
  while (av[++n] != NULL)
    {
      elem = init_elem(av[n]);
      add_elem(list, elem);
    }
  return (list);
}
Esempio n. 21
0
void read_elems(struct item **head)
{
    int n;
    int p;
    printf("Num: ");
    scanf("%i", &n);
    printf("Power: ");
    scanf("%i", &p);
    while (n != 0)
    {
        add_elem(head, 0, n, p);
        printf("\nNum: ");
        scanf("%i", &n);
        printf("Power: ");
        scanf("%i", &p);
    }
}
Esempio n. 22
0
t_list		*path_to_list(char *path)
{
	char	**array;
	t_list	*result;
	size_t	i;

	array = ft_strsplit(path, '/');
	result = new_list();
	i = 0;
	while (array[i])
	{
		add_elem(result, array[i]);
		i++;
	}

	return (result);
}
void dump_backlog()
{
    pthread_mutex_lock(&UNSEQ_CHAT_MSGS->mutex);
    node_t* curr = UNSEQ_CHAT_MSGS->head;
    while(curr != NULL)
    {
      chatmessage_t* chatmessage = (chatmessage_t*)curr->elem;
      if(chatmessage->iscomplete)
      {
	client_t* sender = find_client_by_uid(chatmessage->senderuid);
	add_elem(sender->unseq_chat_msgs,chatmessage);
      }
      curr = curr->next;
    }
    pthread_mutex_unlock(&UNSEQ_CHAT_MSGS->mutex);
    return;
}
Esempio n. 24
0
void ArithmeticTerm::add_elem(Term* t, long int coef)
{

	if(coef == 0) return;
	switch(t->get_term_type())
	{
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) t;
		map<Term*, long int>::const_iterator it = at->get_elems().begin();
		for(; it!= at->get_elems().end(); it++) {
			add_elem(it->first, coef*it->second);
		}
		constant += coef*at->get_constant();
		break;
	}
	case CONSTANT_TERM:
	{
		ConstantTerm* ct = (ConstantTerm*) t;
		constant += coef*ct->get_constant();
		break;
	}
	case VARIABLE_TERM:
	case FUNCTION_TERM:
	{
		if(elems.count(t) == 0) {
			elems[t] = coef;
		}
		else {
			elems[t] += coef;
			if(elems[t] == 0) {
				elems.erase(t);
			}
		}
		break;
	}
	default: {
		cerr << "Unexpected term: " << t->get_term_type() << endl;
		//cerr << t->to_string() << endl;
		assert(false);
	}

	}
}
Esempio n. 25
0
int             main(int ac, char **av)
{
  t_list        *l_a;
  t_list        *l_b;

  l_a = NULL;
  l_b = NULL;
  ac = ac - 1;
  if (ac == 0)
    return (0);
  while (ac != 0)
    {
      add_elem(&l_a, my_getnbr(av[ac]));
      ac--;
    }
  sort_out(&l_a, &l_b);
  my_putchar('\n');
  my_show_list(l_a);
  my_putchar('\n');
}
Esempio n. 26
0
int main() {
    add_elem('a');
    add_elem('b');
    add_elem('c');
    print_arr();
    printf("\nRemoved Elem: %c",remove_elem());
    printf("\nRemoved Elem: %c",remove_elem());
    add_elem('d');
    print_arr();
    add_elem('e');
    print_arr();
    add_elem('f');
    print_arr();
    return 0;
}
static void join_cluster_with_token(struct Cluster *pCluster,
               struct Parameters *pParam)
{
  char key[MAXKEYLEN];
  int i, len;
  struct Elem *pElem;
  
  pParam->joinedClusterInputNum++;
  
  *key = 0;
  
  for (i = 1; i <= pCluster->constants; i++)
  {
    if (pParam->tokenMarker[i] == 0)
    {
      strcat(key, pCluster->ppWord[i]->pKey);
    }
    else
    {
      strcat(key, pParam->token);
    }
    len = (int) strlen(key);
    key[len] = CLUSTERSEP;
    key[len + 1] = 0;
  }
  
  pElem = add_elem(key, pParam->ppClusterTable, pParam->clusterTableSize,
           pParam->clusterTableSeed, pParam);
  
  if (pElem->count == 1)
  {
    pParam->joinedClusterOutputNum++;
    //create cluster_with_token instance
    create_cluster_with_token_instance(pCluster, pElem, pParam);
  }
  
  
  //adjust this instance
  adjust_cluster_with_token_instance(pCluster, pElem, pParam);
}
Esempio n. 28
0
static void update_ve(int veid, char *ip, int status)
{
	struct Cveinfo *tmp, ve;

	tmp = find_ve(veid);
	if (tmp == NULL) {
		memset(&ve, 0, sizeof(struct Cveinfo));
		ve.veid = veid;
		ve.status = status;
		ve.ip = ip;
		add_elem(&ve);
		qsort(veinfo, n_veinfo, sizeof(struct Cveinfo), id_sort_fn);
		return;
	} else {
		if (tmp->ip == NULL)
			tmp->ip = ip;
		else
			free(ip);
		tmp->status = status;
	}
	return;
}
Esempio n. 29
0
int main()
{
	int number_ieroglif = 0;
	scanf("%d", &number_ieroglif);
	char dictionary[26][26];
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < 26; j++)
			dictionary[i][j] = 0;
	}
	char buff[2];
	for (int i = 0; i < number_ieroglif; i++) {
		scanf("%s\n", &buff);
		add_elem(dictionary[buff[0] - 97], buff[1]);
	}
	/* print_dict(dictionary); */
	scanf("%s\n", &buff);
	for (int i = 0; i < 26; i++) {
		if (dictionary[buff[0] - 97][i] != 0)
			printf("%c%c\n", buff[0], dictionary[buff[0] - 97][i]);
	}
	return 0;
}
Esempio n. 30
0
void PdUI::addVerticalBargraph(const char* label, float* zone, float min, float max)
{ add_elem(UI_V_BARGRAPH, label, zone, min, max); }