int get_next_line(int const fd, char **line) { static char *end = NULL; char *buf; int ret; if (fd < 0 && BUFF_SIZE < 1 && BUFF_SIZE > 2000000000) return (-1); if (ft_check_end(&end, line) == 1) return (1); if (!(buf = ft_strnew(BUFF_SIZE + 1))) return (-1); while ((ret = read(fd, buf, BUFF_SIZE)) > 0) { if (ft_check_line(&end, &buf, line) == 1) { ft_memdel((void **)&buf); return (1); } } ft_memdel((void **)&buf); *line = ft_strdup(end); ft_memdel((void **)&end); return (ret); }
int ft_check_file(char *file) { char **split; int i; int empty_line_ok; int correct_line; int nb_description; t_point *piece; i = 0; nb_description = 0; empty_line_ok = ft_check_empty_line(file); if (empty_line_ok == -1) return (-1); split = ft_strsplit(file, '\n'); while (split[i]) { correct_line = ft_check_line(split[i]); if (correct_line == -1) return (-1); i++; } nb_description = ft_count_description(split); if (nb_description == -1) return (-1); if (ft_count_block(split) == -1) return (-1); piece = ft_store_piece(split); if (ft_check_piece(piece) == -1) return (-1); return (0); }
int ft_check(int maxline, int maxcol, int line, int col) { if (ft_check_line(maxcol, line) == 1 || ft_check_col(maxline, col) == 1) return (1); else return (0); }
int ft_recursive_back(char **argv, int pos) { char k; int x; int y; y = pos / 9; x = pos % 9; k = '1'; if (pos < 0) return (1); if (argv[y][x] != '.') return (ft_recursive_back(argv, pos - 1)); while (k <= '9') { if (ft_check_line(argv, y, k) && ft_check_column(argv, x, k) && ft_check_bloc(argv, k, y, x)) { argv[y][x] = k; if (ft_recursive_back(argv, pos - 1) == 1) return (1); } k++; } argv[y][x] = '.'; return (0); }
int ft_check_file(char *file) { char **split; int i; int correct_line; t_point *piece; i = 0; if (ft_check_empty_line(file) == -1) error(); split = ft_strsplit(file, '\n'); while (split[i]) { correct_line = ft_check_line(split[i++]); if (correct_line == -1) error(); } if (ft_count_description(split) == -1) error(); if (ft_count_block(split) == -1) error(); piece = ft_store_piece(split); if (ft_check_piece(piece) == -1) error(); free(split); free(piece); return (0); }
int ft_check_case(int x, int y, struct s_grid *grid) { if (ft_check_line(grid->lines[y]) && ft_check_column(grid->columns[x]) && ft_check_block(grid->blocks[ft_get_block_of(x, y)]) == 1) return (1); else return (0); }
int ft_new_number(int n, int pos, char tab[9][9]) { while (n++ <= 9) { if (ft_check_line(n, pos, tab) == 0 && ft_check_col(n, pos, tab) == 0 && ft_check_block(n, pos, tab) == 0) { tab[pos / 9][pos % 9] = n; return (1); } } return (0); }
int get_next_line(int const fd, char **line) { static char *end = NULL; char *str; char *buf; size_t ret; char *tmp; ret = 1; str = ft_strnew(BUFF_SIZE); while (ret > 0) { buf = ft_strnew(BUFF_SIZE); ret = read(fd, buf, BUFF_SIZE); buf[ret] = '\0'; tmp = end; if (!ft_check_end(&str, &buf, tmp)) ft_memdel((void**)&end); if (ft_check_line(str, &end, line) == 1) return (1); } *line = str; return (0); }