t_tetris *get_all_tetri(char *line) { int add21; int tetri_count; char letter; t_tetris *tr; t_tetris *tmp; tmp = NULL; tetri_count = count_tetri(line); add21 = 0; letter = 'A'; if (!(tr = (t_tetris*)ft_memalloc(sizeof(t_tetris)))) return (NULL); tmp = tr; while (tetri_count > 0) { get_pos(&tmp, ft_strsub(line, add21, 20), letter); letter++; add21 += 21; tetri_count--; if (!(tmp->next = (t_tetris*)ft_memalloc(sizeof(t_tetris)))) return (NULL); tmp = tmp->next; } tmp->next = NULL; return (tr); }
void open_lst_tetri(t_app *app) { int fd; int rt; unsigned char *data; t_tetri *cursor; rt = 1; fd = ft_open(app->av[1], O_RDONLY); rt = readfile(fd, &data, rt); app->tetri = new_tetri(idfrompiece(lire_piece(data), app->pieces)); ft_free(data); cursor = app->tetri; rt = readfile(fd, &data, rt); while (rt != 0) { cursor = add_tetri(cursor, idfrompiece(lire_piece(data), app->pieces)); ft_free(data); rt = readfile(fd, &data, rt); } close(fd); app->nb_tetri = count_tetri(app->tetri); if (app->nb_tetri > 26) ft_puterror(); app->nb_point = app->nb_tetri * 4; }
int main(int ac, char **av) { int fd; int size; char *line; t_tetris *tr; size = 0; tr = NULL; if (ac != 2) { ft_putendl_fd("usage: ./fillit file", 1); exit(EXIT_SUCCESS); } fd = open(av[1], O_RDONLY); if (fd < 0) exit_error(); line = read_file(fd); check_all(line); tr = get_all_tetri(line); size = ft_sqrt(count_tetri(line) * 4); solve(size, tr); return (0); }