Ejemplo n.º 1
0
Archivo: map.c Proyecto: Denis2222/FdF
t_list		*map_wires(t_env *e)
{
	t_dot	*c;
	t_list	*wires;

	wires = NULL;
	c = dot(0, 0, 0);
	while (c->y < e->max->y)
	{
		c->x = 0;
		while (c->x < e->max->x)
		{
			if (c->y + 1 < e->max->y)
				ft_lstadd(&wires,
				ft_lstnew(wire(e->map[c->y][c->x], e->map[c->y + 1][c->x]),
				sizeof(t_wire)));
			if (c->x + 1 < e->max->x)
				ft_lstadd(&wires,
				ft_lstnew(wire(e->map[c->y][c->x], e->map[c->y][c->x + 1]),
				sizeof(t_wire)));
			c->x++;
		}
		c->y++;
	}
	return (wires);
}
Ejemplo n.º 2
0
t_list				*ft_search_fd(t_list **begin, int fd)
{
	t_list	*next;

	next = *begin;
	if (!next)
	{
		next = ft_lstnew("\0", 1);
		next->content_size = fd;
		ft_lstadd(begin, next);
		return (next);
	}
	else
	{
		while (next)
		{
			if (next->content_size == (size_t)fd)
				return (next);
			next = next->next;
		}
		next = ft_lstnew("\0", 1);
		next->content_size = fd;
		ft_lstadd(begin, next);
		return (next);
	}
}
Ejemplo n.º 3
0
static void		d_link(struct dirent *f_drt, t_list **lst, char *arg, t_opt opt)
{
	t_list	*lst_tmp;

	if (opt.a)
	{
		if (!(lst_tmp = mk_link(arg, f_drt->d_name)))
			return ;
		ft_lstadd(lst, lst_tmp);
	}
	else if (opt.aa)
	{
		if (ft_strcmp(f_drt->d_name, ".")
			&& ft_strcmp(f_drt->d_name, ".."))
		{
			if (!(lst_tmp = mk_link(arg, f_drt->d_name)))
				return ;
			ft_lstadd(lst, lst_tmp);
		}
	}
	else if (*(f_drt->d_name) != '.')
	{
		if (!(lst_tmp = mk_link(arg, f_drt->d_name)))
			return ;
		ft_lstadd(lst, lst_tmp);
	}
}
Ejemplo n.º 4
0
void			ft_rev_rot_stack(char stack, t_env *e)
{
	t_list	*beg;
	t_list	*tmp;
	t_list	*last;
	t_list	**lst;
	size_t	len;

	e->nb_op++;
	lst = NULL;
	beg = NULL;
	lst = ft_rev_rot_select_stack(stack, &len, e);
	if (len >= 2)
	{
		last = ft_get_last(*lst, stack);
		ft_lstadd(lst, ft_lstnew(last->content, sizeof(*last)));
		beg = *lst;
		while ((*lst)->next != NULL)
		{
			tmp = *lst;
			(*lst) = (*lst)->next;
		}
		ft_memdel((void **)(&((*lst)->content)));
		ft_memdel((void **)(lst));
		tmp->next = NULL;
	}
	*lst = beg;
}
Ejemplo n.º 5
0
static int	set_next_line(t_buffer *buf, char *newline, char **line)
{
	char	*s;
	t_list	*chunk;
	size_t	new_size;

	if (newline)
	{
		new_size = buf->CHUNK_SIZE - (newline - (char *)buf->CHUNK) - 1;
		if (!(s = ft_strnew(new_size - 1)))
			return (reset_buf(buf, NULL));
		ft_memcpy(s, newline + 1, new_size);
		buf->CHUNK_SIZE -= new_size + 1;
		buf->size -= new_size + 1;
	}
	if (!(*line = ft_strnew(buf->size)))
		return (reset_buf(buf, &s));
	build_line(buf, *line);
	if (newline)
	{
		if (!(chunk = ft_lstnew(s, new_size)))
			return (reset_buf(buf, &s));
		ft_lstadd(&buf->chunks, chunk);
		buf->size = new_size;
	}
	return (1);
}
Ejemplo n.º 6
0
static int		gnl_act(int fd, char **line, t_list **alst, char *str)
{
	int		rd;
	int		i;

	rd = 1;
	str = ft_strnew(BUFF_SIZE);
	while (rd >= 0)
	{
		if ((i = ft_strclen((*alst)->content, '\n')) >= 0 || rd == 0)
		{
			if (i >= 0)
			{
				gnl_rest((*alst)->content + i + 1);
				((char*)(*alst)->content)[i] = '\0';
				(*alst)->content_size = i;
			}
			*line = gnl_lsttochar(alst);
			free(str);
			return (1);
		}
		if ((rd = read(fd, str, BUFF_SIZE)) < 0)
			return (rd);
		ft_lstadd(alst, ft_lstnew(str, rd));
	}
	return (-1);
}
Ejemplo n.º 7
0
static int		my_filllist(t_list **list, int fd)
{
	int		i;
	t_list	*tmp;
	char	**ret;
	char	*line;

	line = NULL;
	*list = NULL;
	while ((i = ft_gnl(fd, &line)) > 0)
	{
		ret = ft_strsplit(line, ' ');
		if (!(tmp = (t_list *)malloc(sizeof(t_list))))
		{
			ft_memdel((void **)&ret);
			ft_lstdel(list, &my_lstdel);
			return (-2);
		}
		tmp->content = ret;
		tmp->content_size = sizeof(char **);
		ft_lstadd(list, tmp);
	}
	ft_memdel((void **)&line);
	return (i);
}
Ejemplo n.º 8
0
Archivo: get.c Proyecto: sbenning42/42
void			lem_get_room(char **data, t_lem_map *map, t_lem_state *state)
{
	t_lem_room	room;
	t_list		*elem;
	
	elem = map->room;
	while (elem)
	{
		if (!ft_strcmp(data[0], ((t_lem_room *)elem->content)->name))
		{
			*state = Lem_error;
			ft_printf("Lem: Error. [%s][%s]: Can't have two rooms with the same name! ", data[0], ((t_lem_room *)elem->content)->name);
			lem_del_data(data);
			return ;
		}
		elem = elem->next;
	}
	room.name = data[0];
	room.id = map->size++;
	room.x = data[1];
	room.y = data[2];
	//free(data[3]);
	elem = ft_lstnew(&room, sizeof(t_lem_room));
	if (!elem)
	{
		*state = Lem_error;
		ft_printf("Lem: Error. Memory allocation fail on room [%s] ", data[0]);
		lem_del_data(data);
		return ;
	}
	ft_lstadd(&map->room, elem);
}
Ejemplo n.º 9
0
static t_list			*get_fdlist(int fd, t_list **toplist)
{
	t_env		*env;
	t_list		*tmplist;

	tmplist = *toplist;
	while (tmplist)
	{
		if (((t_env*)tmplist->content)->fd == fd)
		{
			return (tmplist);
		}
		tmplist = tmplist->next;
	}
	if (!(env = (t_env*)malloc(sizeof(t_env))))
		return (NULL);
	env->fd = fd;
	env->ret = 0;
	env->index = 0;
	if (!(tmplist = (t_list*)malloc(sizeof(t_list))))
		return (NULL);
	tmplist->content = env;
	tmplist->content_size = sizeof(env);
	ft_lstadd(toplist, tmplist);
	return (tmplist);
}
Ejemplo n.º 10
0
void			build_agregateur(t_redirections *r, int fd,
								int type, char **cmd)
{
	t_agregateur	a;
	char			*word;

	ft_bzero(&a, sizeof(t_agregateur));
	a.fd_1 = (fd == -1) ? type & 1 : fd;
	word = ft_strword(*cmd);
	if (!ft_strcmp("-", word))
	{
		a.close = 1;
		free(word);
	}
	else if (is_a_file_descriptor(word))
	{
		a.fd_2 = ft_atoi(word);
		free(word);
	}
	else
	{
		a.fd_2 = open(word, (type & 1) ? O_CREAT | O_RDWR : O_RDONLY, 0644);
		a.filename = word;
	}
	while (**cmd == ' ')
		(*cmd)++;
	(*cmd) += ft_strlen(word);
	ft_lstadd(&r->agr, ft_lstnew(&a, sizeof(t_agregateur)));
}
Ejemplo n.º 11
0
int			parse_cylinder(t_env *env, char **line)
{
	int			i[2];
	t_tobj		tobj;
	t_cylinder	*obj;
	t_list		*lst;

	if (env->scene == NULL)
		return (return_print("Error, a scene must be declared first", 0));
	if ((obj = (t_cylinder *)ft_memalloc(sizeof(t_obj))) == NULL ||
		(lst = ft_lstnewfrom(obj, sizeof(*obj))) == NULL)
		return (return_print("malloc error", 0));
	init_cylinder(env, &tobj, obj);
	i[0] = 0;
	i[1] = 0;
	while (line[++i[0]])
		if (parse_cyl_2(line, i, set_objenv(env, (t_obj *)obj, &tobj)) == 0)
			return (0);
	transform_object((t_obj *)obj, &tobj);
	obj->inter = cylinder_inter;
	obj->normal = cylinder_normal;
	if (env->scene->objects == NULL)
		env->scene->objects = lst;
	else
		ft_lstadd(&(env->scene->objects), lst);
	return (i[1] == 1 ? 1 : return_print("error cylinder imcomplete", 0));
}
Ejemplo n.º 12
0
int			get_spot(t_obj *obj, char *line)
{
	char		**tab;
	t_spot		*spot;

	if ((tab = ft_strsplit(line, ' ')) == NULL)
	{
		ft_printf("%rAllocation Fail ");
		return (-1);
	}
	if (get_size_tab(tab) != 5)
	{
		ft_printf("%rThis line has no five param\n");
		return (-1);
	}
	if (!test_tab(tab, 4))
		return (-1);
	if ((spot = (t_spot *)malloc(sizeof(t_spot))) == NULL)
	{
		ft_printf("%rAllocation Fail ");
		return (-1);
	}
	if (fill_spot(spot, tab))
		return (-1);
	ft_lstadd(&(obj->spot), ft_lstnew(spot, sizeof(t_spot)));
	free(tab);
	return (0);
}
Ejemplo n.º 13
0
int			get_sphere(t_obj *obj, char *line)
{
	char		**tab;
	t_sphere	*sphere;

	if ((tab = ft_strsplit(line, ' ')) == NULL)
	{
		ft_printf("%rAllocation Fail: ");
		return (-1);
	}
	if (get_size_tab(tab) != 21)
	{
		ft_printf("%rThis line has no 21 param: ");
		return (-1);
	}
	if (!test_tab(tab, 20))
		return (-1);
	if ((sphere = (t_sphere *)malloc(sizeof(t_sphere))) == NULL)
		ft_printf("%rAllocation fail: ");
	set_sphere(sphere, tab);
	sphere->color = get_color(tab[20]);
	if (sphere->color == NULL)
		return (-1);
	calc_matrix((void *)sphere, SPHERE);
	ft_lstadd(&(obj->sphere), ft_lstnew(sphere, sizeof(t_sphere)));
	return (0);
}
Ejemplo n.º 14
0
Archivo: parse.c Proyecto: Remaii/FdF
void		parsemap(t_mlx *fdf, int fd)
{
	int		i;
	int		j;
	t_list	*pts;
	char	*line;
	char	**lines;

	i = 0;
	while (get_next_line(fd, &line))
	{
		lines = ft_strsplit(line, ' ');
		j = 0;
		while (lines[j] != NULL)
		{
			ft_lstadd(&pts, ft_lstnew(n_pts(j, i, ft_atoi(lines[j])),\
													sizeof(t_pts)));
			j++;
		}
		i++;
	}
	fdf->x = j;
	fdf->y = i;
	lst_map(pts, fdf, j, i);
}
Ejemplo n.º 15
0
void	ft_lstcpy(t_list **dest, t_list *src)
{
	while (src)
	{
		ft_lstadd(dest, ft_lstnew(src->content, src->content_size));
		src = src->next;
	}
}
Ejemplo n.º 16
0
t_list	*ft_lstaddnew(t_list **lst, void const *content, size_t content_size)
{
	t_list		*ptr;

	if (!(ptr = ft_lstnew(content, content_size)))
		return (NULL);
	ft_lstadd(lst, ptr);
	return (ptr);
}
Ejemplo n.º 17
0
void	test_lstadd(void)
{
	t_list *list;

	list = NULL;
	ft_lstadd(&list, ft_lstnew("you", 4));
	ft_lstadd(&list, ft_lstnew("are", 4));
	ft_lstadd(&list, ft_lstnew("how", 4));
	if (ft_strcmp((char*)list->content, "how") != 0)
		ft_putendl("ERROR: ft_lstadd.");
	list = list->next;
	if (ft_strcmp((char*)list->content, "are") != 0)
		ft_putendl("ERROR: ft_lstadd.");
	list = list->next;
	if (ft_strcmp((char*)list->content, "you") != 0)
		ft_putendl("ERROR: ft_lstadd.");
	ft_putendl("OK: ft_lstadd passed.");
	ft_putendl("---------");
}
Ejemplo n.º 18
0
t_list	*ft_lstmapup(t_list *l, t_list *(*f)(t_list *elem, void *up), void *up)
{
	t_list *lst;

	if (!l->next)
		return (f(l, up));
	lst = ft_lstmapup(l->next, f, up);
	if (lst)
		ft_lstadd(&lst, f(l, up));
	return (lst);
}
Ejemplo n.º 19
0
void	remove_ste_connections(t_queue *paths, t_rooms *rooms, int start,
		int end)
{
	t_list	*ta;
	t_list	*wrapper;

	if (rooms->paths[start][end])
	{
		ta = NULL;
		ft_lstadd(&ta, new_list(end));
		ft_lstadd(&ta, new_list(start));
		wrapper = (t_list *)malloc(sizeof(t_list));
		wrapper->content = ta;
		wrapper->content_size = 1;
		wrapper->next = NULL;
		rooms->paths[start][end] = 0;
		rooms->paths[end][start] = 0;
		push(paths, wrapper);
	}
}
Ejemplo n.º 20
0
t_list	*ft_lstrev(t_list *lst)
{
	t_list	*out;

	out = NULL;
	while (lst)
	{
		ft_lstadd(&out, ft_lstnew(lst->content, lst->content_size));
		lst = lst->next;
	}
	return (out);
}
Ejemplo n.º 21
0
void	parser_light(char **tab, t_env *e)
{
	t_obj	spot;

	if (check_tab_is_valid(tab) == 0)
		ft_exit("too few argument", e);
	ft_bzero(&spot, sizeof(t_obj));
	spot.type = SPOT;
	spot.origin = new_vector(atof(tab[1]), atof(tab[2]), atof(tab[3]));
	spot.color = set_rgb(atoi(tab[4]), atoi(tab[5]), atoi(tab[6]));
	ft_lstadd(&(e->list_spot), ft_lstnew(&spot, sizeof(t_obj)));
}
Ejemplo n.º 22
0
t_list	*ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
	t_list	*result;

	result = NULL;
	if (lst != NULL)
	{
		result = ft_lstmap(lst->next, f);
		ft_lstadd(&result, f(lst));
	}
	return (result);
}
Ejemplo n.º 23
0
int	parse_label(t_parse *p)
{
	t_list	*label;

	label = ft_lstnew(LEXEM, ft_strlen(LEXEM) - 1);
	label->content_size = CHAMPION->len;
	ft_lstadd(&LABEL, label);
	if (!chk_label(label->content))
		error(LABEL_NAMED, p);
	if (POS == 0)
		POS++;
	return (1);
}
Ejemplo n.º 24
0
Archivo: get_map.c Proyecto: Snosky/fdf
static void	do_split(char *line, t_env *env)
{
	char	**split;

	split = ft_strsplit(line, ' ');
	env->px.x = 0;
	while (*split)
	{
		env->px.z = ft_atoi(*split);
		ft_lstadd(&(env->map), ft_lstnew(&(env->px), sizeof(t_px)));
		env->px.x++;
		free(*split++);
	}
}
Ejemplo n.º 25
0
t_list	*ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
	t_list	*l;

	if (!f || !lst)
		return (NULL);
	l = lst;
	if (lst->next)
		lst = ft_lstmap(lst->next, f);
	else
		lst = NULL;
	ft_lstadd(&lst, f(ft_lstnew(l->content, l->content_size)));
	return (lst);
}
Ejemplo n.º 26
0
void	pb(t_stck *stck)
{
    t_list	*to_push;

    if (stck->a)
    {
        to_push = stck->a;
        stck->a = stck->a->next;
        stck->a_size--;
        ft_lstadd(&stck->b, to_push);
        stck->b_size++;
        ft_newmove(stck, "pb");
    }
}
Ejemplo n.º 27
0
static void		create_piece(t_list **head, char *buf, char letter)
{
	t_list		*node;
	t_tetri		t;

	gen_piece(&t);
	get_piece_metrics(buf, &t);
	t.letter = letter;
	t.height = t.ymax - t.ymin + 1;
	t.width = t.xmax - t.xmin + 1;
	buf_to_struct(buf, &t);
	if (!(node = ft_lstnew(&t, sizeof(t_tetri))))
		return ;
	ft_lstadd(head, node);
}
Ejemplo n.º 28
0
int		op_lfork(t_vm *vm, t_process *process, int *params, int len)
{
	t_process		*fork;
	unsigned char	*addr;

	addr = vm->memory + ((((short)params[0]) +
								(process->next_instr - vm->memory)) % MEM_SIZE);
	if (!(fork = new_process(addr, vm->current_cycle -
								get_cycles_for_opcode(*process->next_instr))))
		return (len);
	if (!(fork->registres = copy_regs(process->registres)))
		exit(1);
	copy_state(fork, process);
	ft_lstadd(&vm->processes, ft_lstnew(fork, sizeof(t_process)));
	return (len);
}
Ejemplo n.º 29
0
t_list		*ft_create_list_maps(void)
{
	int		i;
	t_map	*map;
	t_list	*list;

	i = 0;
	list = NULL;
	while (i < 4)
	{
		map = ft_create_map_strings(4);
		ft_lstadd(&list, ft_lstnew(map, sizeof(t_map)));
		free(map);
		i++;
	}
	return (list);
}
Ejemplo n.º 30
0
static t_fd	*actual_fd(int const fd, t_list **fds)
{
	t_list	*tmp;
	t_fd	content;

	tmp = *fds;
	while (tmp != NULL)
	{
		if (((t_fd *)tmp->content)->fd == fd)
			return (tmp->content);
		tmp = tmp->next;
	}
	content.fd = fd;
	content.rest = NULL;
	ft_lstadd(fds, ft_lstnew((void *)&content, sizeof(content)));
	return ((*fds)->content);
}