int get_next_line(int const fd, char **line) { static char *buff; int ret; if (BUFF_SIZE < 1 || fd < 0 || BUFF_SIZE > 2147483647) return (-1); if (!buff) buff = ft_strnew(((size_t)BUFF_SIZE)); *line = ft_strnew(0); if (!buff) return (-1); ret = ft_buff_leftover(buff, line); if (ret == 1) return (1); if (strchr(buff, '\n') == NULL) ret = ft_readfile(fd, line, buff); if (ret == 0 && *line[0] != '\0') return (1); if (ret == 0) ft_strdel(&buff); if (ret > 0) ret = 1; return (ret); }
int main(int ac, char **av) { char *file; t_bloc *blocs; int nbblocs; char **square; if (ac != 2) ft_error(); file = ft_readfile(av[1]); ft_veriffile(file, 0); nbblocs = ft_verifblocs(file); blocs = ft_stockblocs(file, nbblocs); *square = ft_resolve(blocs, nbblocs); ft_printsquare(*square); return (0); }
int ft_testdata(t_gnldata *data, char **line, int fd) { int i; i = 0; line = line; data->fd = fd; if (!(*data).nbline) (*data).nbline = 0; if (!(*data).fileended) (*data).fileended = 0; if (!(*data).txtsize) (*data).txtsize = 0; if ((*data).fileended == 1) return (0); if (!(*data).text) (*data).text = ft_strnew(0); if ((i = ft_readfile(&((*data).text), fd)) > 0) (*data).txtsize = i; if (i == -1) return (0); return (1); }
static int ft_getfile(int const fd, char **line, char **file) { int ret; if (!*file) *file = ft_strnew(2); if (ft_strchr(*file, '\n') != NULL) { *line = *file; *file = ft_strdup((ft_strchr(*file, '\n') + 1)); *line = ft_getline(*line); return (1); } else { ret = ft_readfile(fd, file); if (ret == 0 || ret == -1) return (ret); *line = *file; *file = ft_strdup((ft_strchr(*file, '\n')) + 1); *line = ft_getline(*line); return (1); } }