Exemple #1
0
int			main(int argc, char **argv)
{
	int		fd;
	t_list	*ints;
	int		width;
	int		this_width;
	int		check;

	ints = NULL;
	if (argc == 2)
	{
		fd = open(argv[1], O_RDONLY);
		if (fd < 0)
			fdf_error(argv[1]);
		check = set_next_line(&ints, fd, &width);
		while (((check = set_next_line(&ints, fd, &this_width)) > 0))
		{
			if (width != this_width)
			{
				ft_putendl_fd("Invalid File Format", 2);
				return (1);
			}
		}
		mlx(ints, width);
	}
	return (0);
}
Exemple #2
0
int			get_next_line(int const fd, char **line)
{
	ssize_t			r;
	char			*n;
	char			*s;
	static t_buffer	buf;
	t_list			*chunk;

	r = 42;
	while (!buf.chunks
		|| (!(n = ft_memchr(buf.CHUNK, '\n', buf.CHUNK_SIZE)) && r))
	{
		if (!(s = ft_strnew(BUF_SIZE - 1))
			|| (r = read(fd, s, BUF_SIZE)) < 0
			|| !(chunk = ft_lstnew(s, r)))
			return (reset_buf(&buf, &s));
		ft_lstadd(&buf.chunks, chunk);
		buf.size += r;
	}
	if (buf.size)
		return (set_next_line(&buf, n, line));
	reset_buf(&buf, NULL);
	return (0);
}