int get_intro_2(const char *str, int *nb, int skip, int pattern[6]) { char *buffer; int fd; if (skip <= 3) return (ft_map_error()); buffer = ft_safe_malloc(skip); if ((fd = open(str, O_RDONLY)) <= 0) return (ft_map_error()); if ((read(fd, buffer, skip)) == -1) { write(1, READ_ERROR, sizeof(READ_ERROR)); close(fd); return (0); } close(fd); pattern[0] = buffer[skip - 3]; pattern[1] = buffer[skip - 2]; pattern[2] = buffer[skip - 1]; buffer[skip - 3] = '\0'; *nb = ft_atoi(buffer); free(buffer); if (VERBOSE) ft_tell_intro_2(*nb, pattern); return (1); }
void ft_map_error3(t_env *ret, int width) { if (ret->size_line > 0) if (ret->size_line != width) ft_map_error(); ret->size_line = width; }
int main(int ac, char **av) { int i; t_caract *bsq; t_infos *elem; i = 1; if (ac == 1) { if ((bsq = (t_caract *)malloc(sizeof(t_caract))) == NULL) return (0); if ((elem = malloc(sizeof(t_infos))) == NULL) return (0); ft_readbsq_stdin(bsq, elem); return (0); } while (i < ac) { if ((bsq = (t_caract *)malloc(sizeof(t_caract))) == NULL) i++; if ((elem = malloc(sizeof(t_infos))) == NULL) ft_map_error(bsq); ft_readbsq_file(av[i], bsq, elem); i++; } return (0); }
int get_intro(const char *str, int *nb, int *skip, int pattern[6]) { int fd; int ret; char *ptr; char buffer[BUF_SIZE]; if ((fd = open(str, O_RDONLY)) <= 0) return (ft_map_error()); *skip = 0; ptr = NULL; while ((ret = read(fd, buffer, BUF_SIZE)) == BUF_SIZE) { if ((ptr = ft_strnchr(buffer, '\n', BUF_SIZE))) break ; *skip += BUF_SIZE; } if (ptr || (ptr = ft_strnchr(buffer, '\n', BUF_SIZE))) *skip += ptr - buffer; else *skip += ret; if (VERBOSE) ft_tell_intro(*skip); close(fd); return (get_intro_2(str, nb, *skip, pattern)); }
int get_length(char *str, int *length, int skip) { int fd; int ret; char buffer[BUF_SIZE]; char *ptr; if (!(fd = prepare_fd_skip(str, skip))) return (ft_map_error()); *length = 0; ptr = NULL; while ((ret = read(fd, buffer, BUF_SIZE)) == BUF_SIZE) { if ((ptr = ft_strnchr(buffer, '\n', BUF_SIZE))) break ; *length += BUF_SIZE; } close(fd); if (ptr || (ptr = ft_strnchr(buffer, '\n', BUF_SIZE))) *length += ptr - buffer; else *length += ret; if (VERBOSE) ft_tell_length(*length); return (1); }
void ft_position(t_caract *bsq) { if ((bsq->square = malloc(sizeof(t_point))) == 0) { ft_map_error(bsq); } bsq->square->x = 0; bsq->square->y = 0; bsq->square->size = 0; }
void ft_map_error2(char **value) { int i; i = 0; while (value[i]) { if (ft_isalpha((int)*value[i])) ft_map_error(); i++; } }