Esempio n. 1
0
static int	ft_concat_buff(char **line, char *buff, int ret, int fd)
{
	char	*cpy;

	if (!ft_strchr(buff, '\n'))
	{
		*line = ft_strdup_gnl(buff);
		if ((ret = read(fd, buff, BUFF_SIZE)) == -1)
			return (-1);
		if (!ret)
			return (0);
		buff[ret] = '\0';
		ft_free_line(&cpy, line, buff);
		while (!ft_strchr(buff, '\n') && ret)
		{
			ft_offset_adress(buff);
			if ((ret = read(fd, buff, BUFF_SIZE)) == -1)
				return (-1);
			if (!ret)
				return (0);
			buff[ret] = '\0';
			ft_free_line(&cpy, line, buff);
		}
		ft_offset_adress(buff);
	}
	return (1);
}
Esempio n. 2
0
void		ft_menu(char **puissance)
{
	int		ok;
	char	*line;
	int		ret;

	ok = 0;
	line = NULL;
	while (ok != 3)
	{
		ft_display_menu();
		ret = get_next_line(0, &line);
		if (ret == 1)
		{
			ok = ft_atoi(line);
			if (ok == 1)
				ft_puissance4(puissance);
			else if (ok == 2)
				if (!(puissance = ft_change_size()))
					ok = 3;
		}
		puissance = ft_create_board(puissance);
		ft_free_line(line);
	}
	if (puissance)
		ft_destruct_board(puissance);
}
Esempio n. 3
0
int					get_next_line(int const fd, char **line)
{
	static t_line	*begin = NULL;
	int				test;
	char			*tmp;

	test = -1;
	if (fd < 0 || !line || read(fd, NULL, 0) < 0
		|| (test = ft_findread(&begin, begin, fd, FIND)) <= 0)
		return ((fd < 0 ? ft_gnl_reset(&begin) : test));
	*line = ft_memalloc(1);
	while (!(test = ft_strcut(DATA, '\n', RET))
		&& (tmp = *line)
		&& (*line = ft_strjoin(*line, DATA))
		&& (RET = ft_findread(&begin, begin, fd, READ))
		&& ft_freegiveone((void **)&tmp))
		if (!(*line))
			return (-1);
	if (RET && test)
	{
		tmp = *line;
		*line = ft_strjoin(*line, DATA);
		free(tmp);
		RET = RET - test;
		ft_strncpy(DATA, DATA + test, RET);
	}
	return ((RET ? 1 : ft_free_line(&begin, begin)));
}
Esempio n. 4
0
static int	ft_input_line(int ligne)
{
	int		retour;
	int		col;
	char	*line;
	int		ret;

	retour = 0;
	col = 0;
	line = NULL;
	while (retour == 0)
	{
		ret = get_next_line(0, &line);
		if (ret == 1)
		{
			if (!(ft_check_value(line)))
				ft_display_error(-1);
			else
				retour = ft_input_line_norm(col, retour, ligne, line);
		}
		ft_free_line(line);
	}
	return (retour);
}
Esempio n. 5
0
int			ft_dr_li(t_mlx *mlx, t_line *line)
{
	int		color;

	line->dx = line->ex - line->sx;
	line->dy = line->ey - line->sy;
	if (line->dx > line->dy)
		line->st = line->dx;
	else
		line->st = line->dy;
	line->st *= line->st > 0 ? 1 : -1;
	line->st *= STEPS;
	line->ix = line->dx / line->st;
	line->iy = line->dy / line->st;
	while (line->st-- > 0)
	{
		color = ft_asign_color(line->color / RATIO);
		mlx_pixel_put(mlx->init, mlx->win, line->sx, line->sy, color);
		line->sx += line->ix;
		line->sy += line->iy;
	}
	ft_free_line(line);
	return (0);
}
Esempio n. 6
0
static int			ft_gnl_reset(t_line **begin)
{
	while (*begin)
		ft_free_line(begin, (*begin)->next);
	return (-1);
}