av[1] parsing, doesnt compile yet
This commit is contained in:
parent
63c6f69988
commit
b93eebc9be
3 changed files with 94 additions and 4 deletions
|
|
@ -1 +1,14 @@
|
||||||
#include "libft.h"
|
#ifndef FILLIT_H
|
||||||
|
# include "libft.h"
|
||||||
|
# define FILLIT_H
|
||||||
|
# define BUF_SIZE 32
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct s_tetrim
|
||||||
|
{
|
||||||
|
char id;
|
||||||
|
int pos[3][2];
|
||||||
|
int placed;
|
||||||
|
} t_tetrim;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 36afd3d0ebf5258b9201fcbba8272e94b0b60df7
|
Subproject commit 5d24c020c6563f8d7eb78bdcb18e61f28aa0d435
|
||||||
|
|
@ -5,13 +5,90 @@ void ft_usage(void)
|
||||||
ft_putendl("error");
|
ft_putendl("error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t_list *ft_get_tetrims(char *filename)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char buf[BUF_SIZE + 1];
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int k;
|
||||||
|
int ref[2];
|
||||||
|
char letter = 'A';
|
||||||
|
t_tetrim tetrim;
|
||||||
|
t_list *tetrims;
|
||||||
|
|
||||||
|
fd = open(filename);
|
||||||
|
if (fd == -1)
|
||||||
|
return (0);
|
||||||
|
j = -1;
|
||||||
|
k = 0;
|
||||||
|
while ((ret = read(fd, buf, BUF_SIZE)))
|
||||||
|
{
|
||||||
|
ret[BUF_SIZE] = '\0';
|
||||||
|
i = 0;
|
||||||
|
while (ret[i])
|
||||||
|
{
|
||||||
|
if (ret[i] == '.')
|
||||||
|
;
|
||||||
|
else if (ret[i] == '#')
|
||||||
|
{
|
||||||
|
if (j == -1)
|
||||||
|
{
|
||||||
|
tetrim.id = letter++;
|
||||||
|
ref[0] = k / 5;
|
||||||
|
ref[1] = k % 5;
|
||||||
|
}
|
||||||
|
else if (j >= 0 && j <= 2)
|
||||||
|
{
|
||||||
|
(tetrim.pos)[j][0] = i / 5 - ref[0];
|
||||||
|
(tetrim.pos)[j][1] = i % 5 - ref[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
else if (i > 0 && ret[i] == '\n' && ret[i - 1] == '\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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j != 3 || k != 20)
|
||||||
|
return (0);
|
||||||
|
ft_lstadd(&tetrims, ft_lstnew(tetrim, sizeof(tetrim)));
|
||||||
|
return (tetrims);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
(void)av;
|
t_list *tetrims;
|
||||||
if (ac != 2)
|
int i;
|
||||||
|
|
||||||
|
if (ac != 2 || !(tetrims = ft_get_tetrims(av[1])))
|
||||||
{
|
{
|
||||||
ft_usage();
|
ft_usage();
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
while (tetrims)
|
||||||
|
{
|
||||||
|
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]);
|
||||||
|
ft_putendl("");
|
||||||
|
tetrims = tetrims->next;
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue