text: /* ************************************************************************** */
  /*                                                                            */
  /*                                                        :::      ::::::::   */
  /*   ft_readstdin.c                                     :+:      :+:    :+:   */
  /*                                                    +:+ +:+         +:+     */
  /*   By: cfelbacq <marvin@42.fr>                    +#+  +:+       +#+        */
  /*                                                +#+#+#+#+#+   +#+           */
  /*   Created: 2015/12/06 14:31:53 by cfelbacq          #+#    #+#             */
  /*   Updated: 2015/12/23 16:31:19 by cfelbacq         ###   ########.fr       */
  /*                                                                            */
  /* ************************************************************************** */
  
  #include "fillit.h"
  #include <stdlib.h>
  #include "libft.h"
  
  static	char	**ft_fill_tab(char **tab, char *buf)
  {
  	int	i;
  	int	j;
  	int	k;
  
  	i = 0;
  	j = 0;
  	k = 0;
  	while (j < ft_get_nb_tetrimino(buf))
  	{
  		tab[j] = (char*)malloc(sizeof(char) * 20 + 1);
  		if (tab[j] == NULL)
  			return (NULL);
  		while (k < 20)
  		{
  			tab[j][k] = buf[i];
  			k++;
  			i++;
  		}
  		tab[j][20] = '\0';
  		k = 0;
  		j++;
  		i++;
  	}
  	tab[j] = NULL;
  	return (tab);
  }
  
  char			**read_stdin(char *argv)
  {
  	int		fd;
  	int		ret;
  	char	buf[BUFF_SIZE + 1];
  	char	**tmp;
  
  	if ((fd = open(argv, O_RDONLY)) == -1)
  		return (NULL);
  	ret = 1;
  	tmp = NULL;
  	while ((ret = read(fd, buf, BUFF_SIZE)) != 0)
  		buf[ret] = '\0';
  	g_nb_tetrimino = ft_get_nb_tetrimino(buf);
  	tmp = (char**)malloc(sizeof(char *) * ft_get_nb_tetrimino(buf) + 1);
  	if (tmp == NULL)
  		return (NULL);
  	if (first_test(buf) == 0)
  		return (NULL);
  	tmp = ft_fill_tab(tmp, buf);
  	return (tmp);
  }
  
  t_tetrimino		*ft_splittab(char **tab)
  {
  	int			i;
  	t_tetrimino	*start;
  	t_tetrimino	*ptr;
  
  	i = 1;
  	start = NULL;
  	ptr = NULL;
  	start = ft_newtetri(ft_strsplit(tab[0], '\n'), 0);
  	ptr = start;
  	while (i < g_nb_tetrimino)
  	{
  		ptr->next = ft_newtetri(ft_strsplit(tab[i], '\n'), i);
  		ptr = ptr->next;
  		i++;
  	}
  	ptr->next = NULL;
  	return (start);
  }
  