parsing done
This commit is contained in:
parent
b93eebc9be
commit
b9edcec9b9
4 changed files with 70 additions and 40 deletions
19
fillit/examples/valid_sample.fillit
Normal file
19
fillit/examples/valid_sample.fillit
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
...#
|
||||
...#
|
||||
...#
|
||||
...#
|
||||
|
||||
....
|
||||
....
|
||||
....
|
||||
####
|
||||
|
||||
.###
|
||||
...#
|
||||
....
|
||||
....
|
||||
|
||||
....
|
||||
..##
|
||||
.##.
|
||||
....
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
#ifndef FILLIT_H
|
||||
# include <fcntl.h>
|
||||
# include <stdio.h>
|
||||
# include "libft.h"
|
||||
# define FILLIT_H
|
||||
# define BUF_SIZE 32
|
||||
|
||||
|
||||
typedef struct s_tetrim
|
||||
{
|
||||
char id;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 5d24c020c6563f8d7eb78bdcb18e61f28aa0d435
|
||||
Subproject commit b12c10b76eee97e4ed9f5aafef7954cd06c0e9f3
|
||||
|
|
@ -5,90 +5,100 @@ void ft_usage(void)
|
|||
ft_putendl("error");
|
||||
}
|
||||
|
||||
t_list *ft_get_tetrims(char *filename)
|
||||
t_tetrim *ft_get_tetrims(char *filename)
|
||||
{
|
||||
int fd;
|
||||
char buf[BUF_SIZE + 1];
|
||||
int ret;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int l;
|
||||
int ref[2];
|
||||
char letter = 'A';
|
||||
t_tetrim tetrim;
|
||||
t_list *tetrims;
|
||||
t_tetrim *tetrims;
|
||||
|
||||
fd = open(filename);
|
||||
tetrims = (t_tetrim *)ft_memalloc(sizeof(t_tetrim) * 27);
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return (0);
|
||||
j = -1;
|
||||
k = 0;
|
||||
k = -1;
|
||||
j = 0;
|
||||
l = 0;
|
||||
while ((ret = read(fd, buf, BUF_SIZE)))
|
||||
{
|
||||
ret[BUF_SIZE] = '\0';
|
||||
buf[ret] = '\0';
|
||||
i = 0;
|
||||
while (ret[i])
|
||||
while (buf[i])
|
||||
{
|
||||
if (ret[i] == '.')
|
||||
/* printf("%i, %i, %i: '%c'\n", i, j, k, buf[i]); */
|
||||
if (buf[i] == '.')
|
||||
;
|
||||
else if (ret[i] == '#')
|
||||
else if (buf[i] == '#')
|
||||
{
|
||||
if (j == -1)
|
||||
if (k == -1)
|
||||
{
|
||||
tetrim.id = letter++;
|
||||
ref[0] = k / 5;
|
||||
ref[1] = k % 5;
|
||||
tetrims[l].id = letter++;
|
||||
ref[0] = j / 5;
|
||||
ref[1] = j % 5;
|
||||
}
|
||||
else if (j >= 0 && j <= 2)
|
||||
else if (k >= 0 && k <= 2)
|
||||
{
|
||||
(tetrim.pos)[j][0] = i / 5 - ref[0];
|
||||
(tetrim.pos)[j][1] = i % 5 - ref[1];
|
||||
tetrims[l].pos[k][0] = j / 5 - ref[0];
|
||||
tetrims[l].pos[k][1] = j % 5 - ref[1];
|
||||
}
|
||||
else
|
||||
return (0);
|
||||
j++;
|
||||
k++;
|
||||
}
|
||||
else if (i > 0 && ret[i] == '\n' && ret[i - 1] == '\n')
|
||||
else if (buf[i] == '\n')
|
||||
{
|
||||
if (j != 3 || k != 20)
|
||||
return (0);
|
||||
ft_lstadd(&tetrims, ft_lstnew(tetrim, sizeof(tetrim)));
|
||||
j = -1;
|
||||
k = -1;
|
||||
}
|
||||
else if (ret[i] == '\n')
|
||||
{
|
||||
if ((k + 1) % 5 != 0)
|
||||
return (0);
|
||||
if (i > 0 && buf[i - 1] == '\n')
|
||||
{
|
||||
if (k != 3 || j != 20)
|
||||
return (0);
|
||||
l++;
|
||||
j = -1;
|
||||
k = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((j + 1) % 5 != 0)
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
k++;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
if (j != 3 || k != 20)
|
||||
if (k != 3 || j != 20)
|
||||
return (0);
|
||||
ft_lstadd(&tetrims, ft_lstnew(tetrim, sizeof(tetrim)));
|
||||
tetrims[l + 1].id = '\0';
|
||||
return (tetrims);
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
t_list *tetrims;
|
||||
t_tetrim *tetrims;
|
||||
int i;
|
||||
int l;
|
||||
|
||||
if (ac != 2 || !(tetrims = ft_get_tetrims(av[1])))
|
||||
{
|
||||
ft_usage();
|
||||
return (1);
|
||||
}
|
||||
while (tetrims)
|
||||
l = -1;
|
||||
while (tetrims[++l].id)
|
||||
{
|
||||
printf("%c", tetrims->content.id);
|
||||
for (i=0; i<=3; i++)
|
||||
printf("\t%i,%i\n", tetrims->content.pos[i][0], tetrims->content.pos[i][1]);
|
||||
printf("%c\n",tetrims[l].id);
|
||||
for (i=0; i < 3; i++)
|
||||
printf("%i,%i\n", tetrims[l].pos[i][0], tetrims[l].pos[i][1]);
|
||||
ft_putendl("");
|
||||
tetrims = tetrims->next;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue