forked from LeGuit/fillit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessing.c
More file actions
54 lines (47 loc) · 1.68 KB
/
Copy pathprocessing.c
File metadata and controls
54 lines (47 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* processing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwoodwar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/04 14:42:23 by gwoodwar #+# #+# */
/* Updated: 2015/12/04 17:52:47 by gwoodwar ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static t_tetri *create_piece(char letter, t_list **head)
{
t_list *node;
t_tetri contentnew;
contentnew.letter = letter;
contentnew.piece = ft_strnew(BUFF_SIZE);
if (!(node = ft_lstnew(&contentnew, sizeof(t_tetri))))
{
free(contentnew.piece);
return (NULL);
}
ft_lstadd_last(head, node);
return (CONTENT(node));
}
static int read_in_fd(int const fd, t_tetri *tetri)
{
int ret;
ret = read(fd, tetri->piece, BUFF_SIZE);
// (tetri->piece)[ret] = 0;
ft_putstr(tetri->piece);
if (!is_valid(tetri->piece))
return (-2);
return (ret);
}
int get_next_tetri(int const fd, char letter, t_list **head)
{
t_tetri *tetri;
int ret;
if (fd < 0 || BUFF_SIZE < 1)
return (-1);
if (!(tetri = create_piece(letter, head)))
return (-1);
ret = read_in_fd(fd, tetri);
return (ret);
}