From 3b9498e2303985036496827a34f7e8e58a40205e Mon Sep 17 00:00:00 2001 From: Willem Haffmans Date: Sun, 24 Nov 2024 20:40:12 +0000 Subject: [PATCH] norminette errors --- libft/inc/libft.h | 3 +- libft/src/get_next_line/get_next_line.c | 200 ++++++++++++------------ libft/src/string/ft_strcmp.c | 26 ++- src/moves/swap.c | 3 +- 4 files changed, 123 insertions(+), 109 deletions(-) diff --git a/libft/inc/libft.h b/libft/inc/libft.h index a8aa2b5..7814ae8 100644 --- a/libft/inc/libft.h +++ b/libft/inc/libft.h @@ -81,6 +81,7 @@ int ft_printf(const char *format, ...); */ # define OPEN_MAX 1024 # define BUFFER_SIZE 256 -char *get_next_line(int fd); + +char *get_next_line(int fd); #endif diff --git a/libft/src/get_next_line/get_next_line.c b/libft/src/get_next_line/get_next_line.c index f74a6e6..3c7edf0 100644 --- a/libft/src/get_next_line/get_next_line.c +++ b/libft/src/get_next_line/get_next_line.c @@ -1,124 +1,124 @@ /* ************************************************************************** */ -/* */ -/* ::: o_ :::::: ::: */ -/* get_next_line.c :+: / :+::+: :+: */ -/* +:+ > +:++:+ +:+ */ -/* By: whaffman +#+ +:+ +#++#++:++#++ */ -/* +#+ +#+#+ +#++#+ +#+ \o/ */ -/* Created: 2024/07/15 16:59:55 by whaffman #+#+# #+#+# #+# #+# | */ -/* Updated: 2024/07/15 17:00:24 by whaffman ### ### ### ### / \ */ -/* */ +/* */ +/* ::: o_ :::::: ::: */ +/* get_next_line.c :+: / :+::+: :+: */ +/* +:+ > +:++:+ +:+ */ +/* By: whaffman +#+ +:+ +#++#++:++#++ */ +/* +#+ +#+#+ +#++#+ +#+ \o/ */ +/* Created: 2024/07/15 16:59:55 by whaffman #+#+# #+#+# #+# #+# | */ +/* Updated: 2024/07/15 17:00:24 by whaffman ### ### ### ### / \ */ +/* */ /* ************************************************************************** */ #include "libft.h" #include #include -static void gnl_clean(void **ptr) +static void gnl_clean(void **ptr) { - if (*ptr) - { - free(*ptr); - *ptr = NULL; - } + if (*ptr) + { + free(*ptr); + *ptr = NULL; + } } -static int gnl_check_and_extract(char **line, char **stock) +static int gnl_check_and_extract(char **line, char **stock) { - char *temp1; - char *temp2; + char *temp1; + char *temp2; - if (!stock || !*stock) - return (0); - temp1 = *stock; - while (temp1 && *temp1 != '\n') - if (!*temp1++) - return (0); - if (temp1) - temp1++; - temp2 = ft_strdup(temp1); - *temp1 = '\0'; - *line = ft_strdup(*stock); - free(*stock); - *stock = temp2; - if (!*line || !*stock) - { - gnl_clean((void **)line); - gnl_clean((void **)stock); - return (-1); - } - return (1); + if (!stock || !*stock) + return (0); + temp1 = *stock; + while (temp1 && *temp1 != '\n') + if (!*temp1++) + return (0); + if (temp1) + temp1++; + temp2 = ft_strdup(temp1); + *temp1 = '\0'; + *line = ft_strdup(*stock); + free(*stock); + *stock = temp2; + if (!*line || !*stock) + { + gnl_clean((void **)line); + gnl_clean((void **)stock); + return (-1); + } + return (1); } -static int gnl_read(int fd, char **buffer, size_t size) +static int gnl_read(int fd, char **buffer, size_t size) { - int bytes_read; + int bytes_read; - if (!*buffer) - { - *buffer = malloc(sizeof(char) * (BUFFER_SIZE + 1)); - if (!*buffer) - return (-1); - } - bytes_read = read(fd, *buffer, size); - if (bytes_read >= 0) - (*buffer)[bytes_read] = '\0'; - return (bytes_read); + if (!*buffer) + { + *buffer = malloc(sizeof(char) * (BUFFER_SIZE + 1)); + if (!*buffer) + return (-1); + } + bytes_read = read(fd, *buffer, size); + if (bytes_read >= 0) + (*buffer)[bytes_read] = '\0'; + return (bytes_read); } -static int gnl_read_file(int fd, char **stock, char **line) +static int gnl_read_file(int fd, char **stock, char **line) { - char *buffer; - char *temp; - int bytes_read; + char *buffer; + char *temp; + int bytes_read; - buffer = NULL; - bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE); - while (bytes_read > 0) - { - if (!*stock) - *stock = ft_strdup(buffer); - else - { - temp = *stock; - *stock = ft_strjoin(temp, buffer); - free(temp); - } - if (gnl_check_and_extract(line, stock)) - break ; - bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE); - } - free(buffer); - if (!*stock) - return (-1); - return (bytes_read); + buffer = NULL; + bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE); + while (bytes_read > 0) + { + if (!*stock) + *stock = ft_strdup(buffer); + else + { + temp = *stock; + *stock = ft_strjoin(temp, buffer); + free(temp); + } + if (gnl_check_and_extract(line, stock)) + break ; + bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE); + } + free(buffer); + if (!*stock) + return (-1); + return (bytes_read); } -char *get_next_line(int fd) +char *get_next_line(int fd) { - static char *stock[OPEN_MAX]; - char *line; - int status; + static char *stock[OPEN_MAX]; + char *line; + int status; - if (fd < 0 || fd >= OPEN_MAX || BUFFER_SIZE <= 0) - return (NULL); - if (stock[fd] && gnl_check_and_extract(&line, &stock[fd])) - return (line); - status = gnl_read_file(fd, &stock[fd], &line); - if (status > 0) - return (line); - else if (status < 0) - { - gnl_clean((void **)&stock[fd]); - return (NULL); - } - if (stock[fd] && *stock[fd]) - { - line = ft_strdup(stock[fd]); - gnl_clean((void **)&stock[fd]); - if (line) - return (line); - } - gnl_clean((void **)&stock[fd]); - return (NULL); -} \ No newline at end of file + if (fd < 0 || fd >= OPEN_MAX || BUFFER_SIZE <= 0) + return (NULL); + if (stock[fd] && gnl_check_and_extract(&line, &stock[fd])) + return (line); + status = gnl_read_file(fd, &stock[fd], &line); + if (status > 0) + return (line); + else if (status < 0) + { + gnl_clean((void **)&stock[fd]); + return (NULL); + } + if (stock[fd] && *stock[fd]) + { + line = ft_strdup(stock[fd]); + gnl_clean((void **)&stock[fd]); + if (line) + return (line); + } + gnl_clean((void **)&stock[fd]); + return (NULL); +} diff --git a/libft/src/string/ft_strcmp.c b/libft/src/string/ft_strcmp.c index 3da5c32..de583cc 100644 --- a/libft/src/string/ft_strcmp.c +++ b/libft/src/string/ft_strcmp.c @@ -1,11 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: o_ :::::: ::: */ +/* ft_strcmp.c :+: / :+::+: :+: */ +/* +:+ > +:++:+ +:+ */ +/* By: whaffman +#+ +:+ +#++#++:++#++ */ +/* +#+ +#+#+ +#++#+ +#+ \o/ */ +/* Created: 2024/11/24 20:06:19 by whaffman #+#+# #+#+# #+# #+# | */ +/* Updated: 2024/11/24 20:07:08 by whaffman ### ### ### ### / \ */ +/* */ +/* ************************************************************************** */ + #include -int ft_strcmp(const char *s1, const char *s2) +int ft_strcmp(const char *s1, const char *s2) { - size_t i; + size_t i; - i = 0; - while (s1[i] && s2[i] && s1[i] == s2[i]) - i++; - return ((unsigned char)s1[i] - (unsigned char)s2[i]); -} \ No newline at end of file + i = 0; + while (s1[i] && s2[i] && s1[i] == s2[i]) + i++; + return ((unsigned char)s1[i] - (unsigned char)s2[i]); +} diff --git a/src/moves/swap.c b/src/moves/swap.c index 85009a5..68c463a 100644 --- a/src/moves/swap.c +++ b/src/moves/swap.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ +:+ +#++#++:++#++ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */ /* Created: 2024/11/06 20:07:09 by whaffman #+#+# #+#+# #+# #+# | */ -/* Updated: 2024/11/06 20:10:41 by whaffman ### ### ### ### / \ */ +/* Updated: 2024/11/24 20:20:23 by whaffman ### ### ### ### / \ */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ void sa(t_state *state, int silent) if (!silent) ft_putstr_fd("sa\n", STDOUT_FILENO); } + void sb(t_state *state, int silent) { swap(&(state->b));