int get_next_line(int const fd, char **line) { char *buf; static t_line *begin; t_line *ptr; int ret; if (fd < 0 || !line) return (-1); buf = (char *)malloc(sizeof(char) * (BUFF_SIZE + 1)); buf = ft_memset(buf, '\0', BUFF_SIZE + 1); while (ft_strchr(buf, '\n') == NULL && (ret = read(fd, buf, BUFF_SIZE))) { if (ret == -1) return (-1); ptr = ft_fill(&begin, fd, buf); buf = ft_memset(buf, '\0', BUFF_SIZE + 1); } ptr = ft_fill(&begin, fd, buf); if (ptr->read[0][0] != '\0') *line = ptr->read[ptr->line]; else *line = NULL; ptr->line++; if (ret == 0 && ptr->read[ptr->line] == NULL) return (0); return (1); }
void ft_display_char(char *str, int *count, int *flags) { int n; n = flags[ATTR_WIDTH] - 1; if (flags[ATTR_MINUS] == 0) ft_fill(n, ' '); ft_putstr(str); if (flags[ATTR_MINUS] != 0) ft_fill(n, ' '); *count += 1; if (n > 0) *count += n; free(str); }
char *ft_mask_wstr(LL value) { int bits; char *bin; bin = ft_ullitoa(value, 2); bits = ft_strlen(bin); if (bits < 8) return (ft_fill(ft_strdup(MASK8), bin)); else if (bits < 12) return (ft_fill(ft_strdup(MASK16), bin)); else if (bits < 17) return (ft_fill(ft_strdup(MASK24), bin)); else return (ft_fill(ft_strdup(MASK32), bin)); }
int get_next_line(int const fd, char **line) { static char *stay; char *ptr; int size; if (BUFF_SIZE < 1 || fd < 0 || !line) return (-1); if (stay == 0) stay = ""; size = BUFF_SIZE; while (1) { ptr = stay; while (*ptr || size < BUFF_SIZE) { if (*ptr == '\n' || *ptr == -1 || *ptr == 0) return (ft_fill(line, &stay, ptr)); ptr++; } size = ft_read_fd(&stay, fd); if (size == -1) return (-1); } return (0); }
void ft_main2(int fd) { char *file; t_map map; t_tetri *tetri; if (!(file = ft_getfile(fd, &map)) || !(ft_check_file(file))) ft_putstr("error\n"); else { tetri = ft_create_tetri(map); ft_fill(tetri, file, map); ft_init_map(&map); map.ret = 1; ft_solve(tetri, &map); while (map.ret == 0) { map.size++; ft_solve(tetri, &map); } ft_print_map(tetri, map); ft_free(&tetri); } }
void ft_display_str(char *str, int *count, int *flags) { int len; int n; len = ft_strlen(str); if (flags[ATTR_HAVE_PREC] == 1 && flags[ATTR_PREC_VALUE] < len) { str = ft_strsub(str, 0, flags[ATTR_PREC_VALUE]); len = ft_strlen(str); } n = flags[ATTR_WIDTH] - len; if (!(flags[ATTR_MINUS])) ft_fill(n, ' '); ft_putstr(str); if (flags[ATTR_MINUS]) ft_fill(n, ' '); *count += len; if (n > 0) *count += n; free(str); }
static int ft_place_shape(t_gridinfo *info, t_tetriminos *shapes, int i, char *grid) { while (grid[i]) { ft_fill(info, shapes, i, grid); if (grid[i] == shapes[(*info).index].letter) { (*info).index++; return (1); } i++; } return (-1); }
char *ft_itoa(int n) { char *str; str = NULL; str = (char *)malloc(sizeof(char) * ft_size(n) + 1); if (str) { if (n == -2147483648) str = ft_strcpy(str, "-2147483648"); else str = ft_fill(str, n, ft_size(n)); } return (str); }
char *ft_uitoa(unsigned int n) { char *ret; int i; int div; unsigned int nb; i = 0; div = 0; nb = (unsigned int)n; ret = (char*)malloc(sizeof(*ret) * ft_size_alloc(nb) + 1); if (ret == NULL) return (NULL); div = ft_div(nb); ret = ft_fill(ret, nb, div, i); return (ret); }
void ft_solve(t_piece **pieces, int size, int n) { t_tet tets[n + 1]; char **result; unsigned short map[16]; (tets + n)->blocs = 0; ft_memset(map, 0, 18); ft_get_tets(tets, pieces); ft_make_idents(tets, n); while (ft_rec(map, tets, tets, size) == -1) size++; result = ft_create(size); ft_fill(result, tets, pieces); ft_print(result); ft_clear((void **)result); ft_clear((void **)pieces); free(result); }
int main(int ac, char **av) { int i; int v; t_list *la; t_list *lb; la = NULL; lb = NULL; i = 1; v = 0; if (ac == 1) return (ft_error(0)); if (ft_strcmp(av[1], "-v") == 0) v = 1; while (i < ac) { if (ft_check_num(av[i]) == 1) ft_fill(&la, ft_atoi(av[i])); i++; } ft_pushswap(la, lb, v); write (1, "\n", 1); }