From cbcf839860f4a590d93e0c259691165c8caf87f1 Mon Sep 17 00:00:00 2001 From: Lea Yeh Date: Fri, 22 Dec 2023 20:51:36 +0100 Subject: [PATCH 01/13] refact: Change the basic data type --- libraries/libft/inc/libft.h | 24 +++++++------------ libraries/libft/src/libft/stack/ft_stkclear.c | 6 ++--- .../libft/src/libft/stack/ft_stkdelone.c | 4 ++-- libraries/libft/src/libft/stack/ft_stknew.c | 8 +++---- .../libft/src/libft/stack/ft_stkpeektop.c | 4 ++-- libraries/libft/src/libft/stack/ft_stkpop.c | 6 ++--- libraries/libft/src/libft/stack/ft_stkpush.c | 4 ++-- libraries/libft/src/libft/stack/ft_stksize.c | 6 ++--- 8 files changed, 28 insertions(+), 34 deletions(-) diff --git a/libraries/libft/inc/libft.h b/libraries/libft/inc/libft.h index 6be87a02..302257a7 100644 --- a/libraries/libft/inc/libft.h +++ b/libraries/libft/inc/libft.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* libft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ldulling +#+ +:+ +#+ */ +/* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:17:46 by ldulling #+# #+# */ -/* Updated: 2023/12/20 22:19:36 by ldulling ### ########.fr */ +/* Updated: 2023/12/22 19:53:13 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,12 +34,6 @@ typedef struct s_list_d struct s_list_d *next; } t_list_d; -typedef struct s_stack -{ - void *content; - struct s_stack *next; -} t_stack; - /* Chars */ int ft_isalnum(int c); int ft_isalpha(int c); @@ -97,13 +91,13 @@ size_t ft_putnstr_fd(const char *s, size_t n, int fd); void ft_putstr_fd(char *s, int fd); /* Stack */ -void ft_stkclear(t_stack **stk, void (*del)(void *)); -void ft_stkdelone(t_stack *stk, void (*del)(void *)); -t_stack *ft_stknew(void *content); -t_stack *ft_stkpeektop(t_stack *stk); -t_stack *ft_stkpop(t_stack **stk); -void ft_stkpush(t_stack **stk, t_stack *new); -int ft_stksize(t_stack *stk); +void ft_stkclear(t_list **stk, void (*del)(void *)); +void ft_stkdelone(t_list *stk, void (*del)(void *)); +t_list *ft_stknew(void *content); +t_list *ft_stkpeektop(t_list *stk); +t_list *ft_stkpop(t_list **stk); +void ft_stkpush(t_list **stk, t_list *new); +int ft_stksize(t_list *stk); /* Strings */ char *ft_itoa(int n); diff --git a/libraries/libft/src/libft/stack/ft_stkclear.c b/libraries/libft/src/libft/stack/ft_stkclear.c index 127be87e..f47011c7 100644 --- a/libraries/libft/src/libft/stack/ft_stkclear.c +++ b/libraries/libft/src/libft/stack/ft_stkclear.c @@ -6,15 +6,15 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/11 21:03:00 by lyeh #+# #+# */ -/* Updated: 2023/12/21 14:23:00 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 19:53:22 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -void ft_stkclear(t_stack **stk, void (*del)(void *)) +void ft_stkclear(t_list **stk, void (*del)(void *)) { - t_stack *cur; + t_list *cur; if (stk == NULL) return ; diff --git a/libraries/libft/src/libft/stack/ft_stkdelone.c b/libraries/libft/src/libft/stack/ft_stkdelone.c index 19b8c760..2e53dca9 100644 --- a/libraries/libft/src/libft/stack/ft_stkdelone.c +++ b/libraries/libft/src/libft/stack/ft_stkdelone.c @@ -6,13 +6,13 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/17 19:41:12 by lyeh #+# #+# */ -/* Updated: 2023/12/17 22:13:23 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 19:53:31 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -void ft_stkdelone(t_stack *stk, void (*del)(void *)) +void ft_stkdelone(t_list *stk, void (*del)(void *)) { if (stk != NULL) { diff --git a/libraries/libft/src/libft/stack/ft_stknew.c b/libraries/libft/src/libft/stack/ft_stknew.c index 97474814..7b5b1989 100644 --- a/libraries/libft/src/libft/stack/ft_stknew.c +++ b/libraries/libft/src/libft/stack/ft_stknew.c @@ -6,17 +6,17 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/11 20:59:19 by lyeh #+# #+# */ -/* Updated: 2023/12/11 21:02:21 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 19:53:40 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -t_stack *ft_stknew(void *content) +t_list *ft_stknew(void *content) { - t_stack *new_node; + t_list *new_node; - new_node = malloc(sizeof(t_stack)); + new_node = malloc(sizeof(t_list)); if (new_node == NULL) return (NULL); new_node->content = content; diff --git a/libraries/libft/src/libft/stack/ft_stkpeektop.c b/libraries/libft/src/libft/stack/ft_stkpeektop.c index ba6ed896..9d520106 100644 --- a/libraries/libft/src/libft/stack/ft_stkpeektop.c +++ b/libraries/libft/src/libft/stack/ft_stkpeektop.c @@ -6,13 +6,13 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/13 20:29:13 by lyeh #+# #+# */ -/* Updated: 2023/12/17 13:58:59 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 19:53:45 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -t_stack *ft_stkpeektop(t_stack *stk) +t_list *ft_stkpeektop(t_list *stk) { if (stk == NULL) return (NULL); diff --git a/libraries/libft/src/libft/stack/ft_stkpop.c b/libraries/libft/src/libft/stack/ft_stkpop.c index 4784b128..7cccbb90 100644 --- a/libraries/libft/src/libft/stack/ft_stkpop.c +++ b/libraries/libft/src/libft/stack/ft_stkpop.c @@ -6,15 +6,15 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/11 21:07:28 by lyeh #+# #+# */ -/* Updated: 2023/12/11 21:08:22 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 19:53:51 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -t_stack *ft_stkpop(t_stack **stk) +t_list *ft_stkpop(t_list **stk) { - t_stack *top; + t_list *top; if (stk != NULL && *stk != NULL) { diff --git a/libraries/libft/src/libft/stack/ft_stkpush.c b/libraries/libft/src/libft/stack/ft_stkpush.c index 5293bee5..39e952ff 100644 --- a/libraries/libft/src/libft/stack/ft_stkpush.c +++ b/libraries/libft/src/libft/stack/ft_stkpush.c @@ -6,13 +6,13 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/11 21:05:44 by lyeh #+# #+# */ -/* Updated: 2023/12/11 21:07:11 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 19:54:53 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -void ft_stkpush(t_stack **stk, t_stack *new) +void ft_stkpush(t_list **stk, t_list *new) { if (stk != NULL && new != NULL) { diff --git a/libraries/libft/src/libft/stack/ft_stksize.c b/libraries/libft/src/libft/stack/ft_stksize.c index dc2b2164..d966f70b 100644 --- a/libraries/libft/src/libft/stack/ft_stksize.c +++ b/libraries/libft/src/libft/stack/ft_stksize.c @@ -6,16 +6,16 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/11 21:04:09 by lyeh #+# #+# */ -/* Updated: 2023/12/11 21:05:09 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 19:54:04 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -int ft_stksize(t_stack *stk) +int ft_stksize(t_list *stk) { int n; - t_stack *cur; + t_list *cur; if (stk == NULL) return (0); From ada4f5632d4a52d50ec18a30c1b60549fe02793e Mon Sep 17 00:00:00 2001 From: Lea Yeh Date: Fri, 22 Dec 2023 20:58:10 +0100 Subject: [PATCH 02/13] refact: Change the data type in parser module --- include/parser.h | 18 +++++++++--------- include/utils.h | 12 ++++++------ source/frontend/parser/ast.c | 12 ++++++++++++ source/frontend/parser/parse.c | 14 +++++++------- source/frontend/parser/parser_operation.c | 16 ++++++++-------- source/frontend/parser/parser_utils.c | 8 ++++---- source/utils/stack_utils.c | 16 ++++++++-------- 7 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 source/frontend/parser/ast.c diff --git a/include/parser.h b/include/parser.h index 4c74392f..8692f760 100644 --- a/include/parser.h +++ b/include/parser.h @@ -6,7 +6,7 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/08 19:57:56 by lyeh #+# #+# */ -/* Updated: 2023/12/18 22:03:01 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 20:52:14 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,16 +16,16 @@ t_pt_node *get_next_pt_entry(int state, int token_type, int action); -bool push_state(t_stack **state_stack, int next_step); -bool push_token(t_stack **parse_stack, t_token *token); +bool push_state(t_list **state_stack, int next_step); +bool push_token(t_list **parse_stack, t_token *token); bool parse_shift(t_token *input_token, - t_stack **state_stack, t_stack **parse_stack, int next_step); -bool parse_reduce(t_stack **state_stack, - t_stack **parse_stack, t_pt_node *pt_entry); -bool parse_goto(t_stack **state_stack, int token_type); + t_list **state_stack, t_list **parse_stack, int next_step); +bool parse_reduce(t_list **state_stack, + t_list **parse_stack, t_pt_node *pt_entry); +bool parse_goto(t_list **state_stack, int token_type); -bool init_parse(t_stack **state_stack, t_stack **parse_stack); -void free_parse(t_stack **state_stack, t_stack **parse_stack); +bool init_parse(t_list **state_stack, t_list **parse_stack); +void free_parse(t_list **state_stack, t_list **parse_stack); bool ft_parse(t_list **token_list); #endif diff --git a/include/utils.h b/include/utils.h index da6768e3..1443383a 100644 --- a/include/utils.h +++ b/include/utils.h @@ -6,7 +6,7 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/17 13:38:17 by lyeh #+# #+# */ -/* Updated: 2023/12/19 21:13:55 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 20:53:30 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,20 +14,20 @@ # define UTILS_H # include "defines.h" -bool drop_num_stack(t_stack **stack, int num, void (*del)(void *)); +bool drop_num_stack(t_list **stack, int num, void (*del)(void *)); t_token *init_token_node(int type, char *data); void free_token_node(void *content); char *ft_get_token_type_str(int type); -int get_state_from_stack(t_stack *node); -t_token *get_token_from_stack(t_stack *node); +int get_state_from_stack(t_list *node); +t_token *get_token_from_stack(t_list *node); int get_token_type_from_list(t_list *token_list); char *get_token_data_from_list(t_list *token_list); -void print_state_stack(t_stack *stack); -void print_parse_stack(t_stack *stack); +void print_state_stack(t_list *stack); +void print_parse_stack(t_list *stack); void print_token_list(t_list *token_list); diff --git a/source/frontend/parser/ast.c b/source/frontend/parser/ast.c new file mode 100644 index 00000000..1e99ad90 --- /dev/null +++ b/source/frontend/parser/ast.c @@ -0,0 +1,12 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lyeh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/20 21:37:46 by lyeh #+# #+# */ +/* Updated: 2023/12/20 21:37:47 by lyeh ### ########.fr */ +/* */ +/* ************************************************************************** */ + diff --git a/source/frontend/parser/parse.c b/source/frontend/parser/parse.c index d9581b29..075a70bd 100644 --- a/source/frontend/parser/parse.c +++ b/source/frontend/parser/parse.c @@ -6,7 +6,7 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/11 17:28:20 by lyeh #+# #+# */ -/* Updated: 2023/12/21 14:20:46 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 20:54:13 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ #include "utils.h" bool parse_step(t_pt_node *pt_entry, - t_list **token_list, t_stack **state_stack, t_stack **parse_stack) + t_list **token_list, t_list **state_stack, t_list **parse_stack) { bool ret; @@ -37,7 +37,7 @@ bool parse_step(t_pt_node *pt_entry, } // TODO: Need to verify if the return value always be one of the operators -char *get_error_token_data(t_list *token_list, t_stack *parse_stack) +char *get_error_token_data(t_list *token_list, t_list *parse_stack) { char *error_token_data; @@ -49,7 +49,7 @@ char *get_error_token_data(t_list *token_list, t_stack *parse_stack) return (error_token_data); } -void report_syntax_error(t_list *token_list, t_stack *parse_stack) +void report_syntax_error(t_list *token_list, t_list *parse_stack) { ft_dprintf(2, "%s: syntax error near unexpected token `%s'\n", PROGRAM_NAME, @@ -57,7 +57,7 @@ void report_syntax_error(t_list *token_list, t_stack *parse_stack) } bool parse( - t_list **token_list, t_stack **state_stack, t_stack **parse_stack) + t_list **token_list, t_list **state_stack, t_list **parse_stack) { bool ret; t_pt_node *pt_entry; @@ -86,8 +86,8 @@ bool parse( bool ft_parse(t_list **token_list) { - t_stack *state_stack; - t_stack *parse_stack; + t_list *state_stack; + t_list *parse_stack; if (!init_parse(&state_stack, &parse_stack)) return (false); diff --git a/source/frontend/parser/parser_operation.c b/source/frontend/parser/parser_operation.c index 067fad84..3e1348ed 100644 --- a/source/frontend/parser/parser_operation.c +++ b/source/frontend/parser/parser_operation.c @@ -6,16 +6,16 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/16 19:52:51 by lyeh #+# #+# */ -/* Updated: 2023/12/20 21:05:04 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 20:54:32 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ #include "parser.h" #include "utils.h" -bool push_state(t_stack **state_stack, int next_step) +bool push_state(t_list **state_stack, int next_step) { - t_stack *node; + t_list *node; int *tmp; tmp = malloc(sizeof(int)); @@ -29,9 +29,9 @@ bool push_state(t_stack **state_stack, int next_step) return (true); } -bool push_token(t_stack **parse_stack, t_token *token) +bool push_token(t_list **parse_stack, t_token *token) { - t_stack *node; + t_list *node; node = ft_stknew(token); if (!node) @@ -41,7 +41,7 @@ bool push_token(t_stack **parse_stack, t_token *token) } bool parse_shift(t_token *input_token, - t_stack **state_stack, t_stack **parse_stack, int next_step) + t_list **state_stack, t_list **parse_stack, int next_step) { if (!push_token(parse_stack, input_token)) return (free_token_node(input_token), false); @@ -56,7 +56,7 @@ bool parse_shift(t_token *input_token, } bool parse_reduce( - t_stack **state_stack, t_stack **parse_stack, t_pt_node *pt_entry) + t_list **state_stack, t_list **parse_stack, t_pt_node *pt_entry) { t_token *reduction_node; @@ -76,7 +76,7 @@ bool parse_reduce( return (true); } -bool parse_goto(t_stack **state_stack, int token_type) +bool parse_goto(t_list **state_stack, int token_type) { t_pt_node *pt_entry; diff --git a/source/frontend/parser/parser_utils.c b/source/frontend/parser/parser_utils.c index 7518d85f..1570163a 100644 --- a/source/frontend/parser/parser_utils.c +++ b/source/frontend/parser/parser_utils.c @@ -3,17 +3,17 @@ /* ::: :::::::: */ /* parser_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ldulling +#+ +:+ +#+ */ +/* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/16 22:05:05 by lyeh #+# #+# */ -/* Updated: 2023/12/21 14:24:52 by ldulling ### ########.fr */ +/* Updated: 2023/12/22 20:54:41 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ #include "parser.h" #include "utils.h" -bool init_parse(t_stack **state_stack, t_stack **parse_stack) +bool init_parse(t_list **state_stack, t_list **parse_stack) { *state_stack = NULL; *parse_stack = NULL; @@ -22,7 +22,7 @@ bool init_parse(t_stack **state_stack, t_stack **parse_stack) return (true); } -void free_parse(t_stack **state_stack, t_stack **parse_stack) +void free_parse(t_list **state_stack, t_list **parse_stack) { ft_stkclear(state_stack, free); ft_stkclear(parse_stack, free_token_node); diff --git a/source/utils/stack_utils.c b/source/utils/stack_utils.c index 3f0b39bb..9927c6e9 100644 --- a/source/utils/stack_utils.c +++ b/source/utils/stack_utils.c @@ -6,16 +6,16 @@ /* By: lyeh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/16 21:55:34 by lyeh #+# #+# */ -/* Updated: 2023/12/18 21:46:44 by lyeh ### ########.fr */ +/* Updated: 2023/12/22 20:53:49 by lyeh ### ########.fr */ /* */ /* ************************************************************************** */ #include "defines.h" -bool drop_num_stack(t_stack **stack, int num, void (*del)(void *)) +bool drop_num_stack(t_list **stack, int num, void (*del)(void *)) { int i; - t_stack *node; + t_list *node; i = 0; while (i < num) @@ -29,19 +29,19 @@ bool drop_num_stack(t_stack **stack, int num, void (*del)(void *)) return (true); } -int get_state_from_stack(t_stack *node) +int get_state_from_stack(t_list *node) { return (*((int *)node->content)); } -t_token *get_token_from_stack(t_stack *node) +t_token *get_token_from_stack(t_list *node) { return ((t_token *)node->content); } -void print_state_stack(t_stack *stack) +void print_state_stack(t_list *stack) { - t_stack *node; + t_list *node; node = stack; while (node) @@ -52,7 +52,7 @@ void print_state_stack(t_stack *stack) printf("(NULL)\n"); } -void print_parse_stack(t_stack *node) +void print_parse_stack(t_list *node) { while (node) { From e7e3f432b65f067c7216093acd8472cad512fe07 Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 11:18:56 +0100 Subject: [PATCH 03/13] lib: Make ft_lst functions behave exactly the same as ft_stk functions Now the ft_lstclear and ft_lstdelone functions still free the node even when the function pointer argument is NULL. This really is more useful. And the ft_lstpop function now also sets the next ptr for the popped node to NULL. --- .../src/libft/lists/singly_linked/ft_lstclear.c | 16 +++++++--------- .../src/libft/lists/singly_linked/ft_lstdelone.c | 10 +++++----- .../src/libft/lists/singly_linked/ft_lstpop.c | 3 ++- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstclear.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstclear.c index a9aa317d..fb4d9172 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstclear.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstclear.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:22 by ldulling #+# #+# */ -/* Updated: 2023/11/27 00:16:44 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 11:17:18 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,15 +16,13 @@ void ft_lstclear(t_list **lst, void (*del)(void *)) { t_list *cur; - if (lst != NULL && del != NULL) + if (lst == NULL) + return ; + while (*lst != NULL) { - while (*lst != NULL) - { - cur = *lst; - *lst = (*lst)->next; - (*del)(cur->content); - free(cur); - } + cur = *lst; + *lst = (*lst)->next; + ft_lstdelone(cur, del); } return ; } diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstdelone.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstdelone.c index c1d285d3..84e8a2bc 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstdelone.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstdelone.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:26 by ldulling #+# #+# */ -/* Updated: 2023/09/26 12:35:15 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 11:16:35 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,10 @@ void ft_lstdelone(t_list *lst, void (*del)(void *)) { - if (lst != NULL && del != NULL) - { + if (lst == NULL) + return ; + if (del != NULL && lst->content != NULL) (*del)(lst->content); - free(lst); - } + free(lst); return ; } diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c index 56d9d47a..c1fb7697 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:29 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:11:51 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 11:13:08 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,5 +29,6 @@ t_list *ft_lstpop(t_list **lst) return (NULL); popped = *lst; *lst = (*lst)->next; + popped->next = NULL; return (popped); } From 9a7df1412c6c6a7fb9741bf6d51c1e286c250c02 Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 15:16:56 +0100 Subject: [PATCH 04/13] lib: Add ft_lstswap_head function to libft --- libraries/libft/build/libft.mk | 13 +------ libraries/libft/inc/libft.h | 12 ++---- .../lists/singly_linked/ft_lstsort_bubble.c | 28 ++++---------- .../lists/singly_linked/ft_lstswap_head.c | 37 +++++++++++++++++++ 4 files changed, 50 insertions(+), 40 deletions(-) create mode 100644 libraries/libft/src/libft/lists/singly_linked/ft_lstswap_head.c diff --git a/libraries/libft/build/libft.mk b/libraries/libft/build/libft.mk index 4c747c34..d4ad6a14 100644 --- a/libraries/libft/build/libft.mk +++ b/libraries/libft/build/libft.mk @@ -6,7 +6,7 @@ # By: ldulling +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/16 13:33:38 by ldulling #+# #+# # -# Updated: 2023/12/20 22:20:35 by ldulling ### ########.fr # +# Updated: 2023/12/23 14:23:25 by ldulling ### ########.fr # # # # **************************************************************************** # @@ -59,16 +59,7 @@ TMP += $(addprefix $(DIR)$(SUBDIR), \ ft_lstpop_content.c \ ft_lstsize.c \ ft_lstsort_bubble.c \ -) - -# Doubly-linked: -SUBDIR := lists/doubly_linked/ -TMP += $(addprefix $(DIR)$(SUBDIR), \ - ft_lstadd_back_d.c \ - ft_lstadd_front_d.c \ - ft_lstclear_d.c \ - ft_lstlast_d.c \ - ft_lstnew_d.c \ + ft_lstswap_head.c \ ) # Memory: diff --git a/libraries/libft/inc/libft.h b/libraries/libft/inc/libft.h index 302257a7..8b64b6fd 100644 --- a/libraries/libft/inc/libft.h +++ b/libraries/libft/inc/libft.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* libft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ +/* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:17:46 by ldulling #+# #+# */ -/* Updated: 2023/12/22 19:53:13 by lyeh ### ########.fr */ +/* Updated: 2023/12/23 14:24:34 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,13 +58,7 @@ t_list *ft_lstpop(t_list **lst); void *ft_lstpop_content(t_list **lst); int ft_lstsize(t_list *lst); void ft_lstsort_bubble(t_list **lst, void *(*cmp)(void *, void *)); - -/* Lists doubly-linked */ -void ft_lstadd_back_d(t_list_d **lst, t_list_d *new); -void ft_lstadd_front_d(t_list_d **lst, t_list_d *new); -void ft_lstclear_d(t_list_d **lst, void (*del)(void *)); -t_list_d *ft_lstlast_d(t_list_d *lst); -t_list_d *ft_lstnew_d(void *content); +void ft_lstswap_head(t_list **lst); /* Memory */ void ft_bzero(void *s, size_t n); diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstsort_bubble.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstsort_bubble.c index 32078e26..94b8daba 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstsort_bubble.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstsort_bubble.c @@ -6,42 +6,30 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/19 21:16:52 by ldulling #+# #+# */ -/* Updated: 2023/11/27 10:36:43 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 11:55:40 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -static void swap_head(t_list **lst); static bool bubble_sort(t_list **lst, void *(*cmp)(void *, void *)); void ft_lstsort_bubble(t_list **lst, void *(*cmp)(void *, void *)) { bool is_sorted; - if (lst != NULL && *lst != NULL && (*lst)->next != NULL && cmp != NULL) + if (lst == NULL || *lst == NULL || (*lst)->next == NULL || cmp == NULL) + return ; + is_sorted = false; + while (is_sorted != true) { - is_sorted = false; - while (is_sorted != true) - { - if (!(*cmp)((*lst)->content, (*lst)->next->content)) - swap_head(lst); - is_sorted = bubble_sort(lst, cmp); - } + if (!(*cmp)((*lst)->content, (*lst)->next->content)) + ft_lstswap_head(lst); + is_sorted = bubble_sort(lst, cmp); } return ; } -static void swap_head(t_list **lst) -{ - t_list *tmp; - - tmp = (*lst)->next; - (*lst)->next = tmp->next; - tmp->next = *lst; - *lst = tmp; -} - static bool bubble_sort(t_list **lst, void *(*cmp)(void *, void *)) { t_list *cur; diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstswap_head.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstswap_head.c new file mode 100644 index 00000000..0a7e41ca --- /dev/null +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstswap_head.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstswap_head.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ldulling +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/23 11:52:20 by ldulling #+# #+# */ +/* Updated: 2023/12/23 12:08:21 by ldulling ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/** + * The ft_lstswap_head function swaps the first two nodes of a singly linked + * list. + * + * @param lst A double pointer to the first node of the list. + * + * @return No return value. + * + * @note The function does nothing if the list is empty or contains only + * one node. + * + */ +void ft_lstswap_head(t_list **lst) +{ + t_list *new_head; + + if (lst == NULL || *lst == NULL || (*lst)->next == NULL) + return ; + new_head = (*lst)->next; + (*lst)->next = new_head->next; + new_head->next = *lst; + *lst = new_head; +} From a295837ae18d0354b93d94ddaa656130c8a72ec2 Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 15:19:48 +0100 Subject: [PATCH 05/13] lib: Change ft_lstadd functions to add full lists to another list, not just a single node --- .../lists/doubly_linked/ft_lstadd_back_d.c | 24 ++++++++--------- .../lists/doubly_linked/ft_lstadd_front_d.c | 21 ++++++++------- .../lists/singly_linked/ft_lstadd_back.c | 27 +++++++++---------- .../lists/singly_linked/ft_lstadd_front.c | 20 +++++++------- 4 files changed, 47 insertions(+), 45 deletions(-) diff --git a/libraries/libft/src/libft/lists/doubly_linked/ft_lstadd_back_d.c b/libraries/libft/src/libft/lists/doubly_linked/ft_lstadd_back_d.c index 1af58b43..7754f81c 100644 --- a/libraries/libft/src/libft/lists/doubly_linked/ft_lstadd_back_d.c +++ b/libraries/libft/src/libft/lists/doubly_linked/ft_lstadd_back_d.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:12 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:08:49 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 14:05:01 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,23 +14,23 @@ /** * Does not mark the new node as the end of the list by itself. + * Therefore, a whole list can be appended, not just one node. */ void ft_lstadd_back_d(t_list_d **lst, t_list_d *new) { t_list_d *cur; - if (lst != NULL && new != NULL) + if (lst == NULL || new == NULL) + return ; + if (*lst == NULL) + *lst = new; + else { - if (*lst == NULL) - *lst = new; - else - { - cur = *lst; - while (cur->next != NULL) - cur = cur->next; - cur->next = new; - new->prev = cur; - } + cur = *lst; + while (cur->next != NULL) + cur = cur->next; + cur->next = new; + new->prev = cur; } return ; } diff --git a/libraries/libft/src/libft/lists/doubly_linked/ft_lstadd_front_d.c b/libraries/libft/src/libft/lists/doubly_linked/ft_lstadd_front_d.c index d0b935f4..ed0148fd 100644 --- a/libraries/libft/src/libft/lists/doubly_linked/ft_lstadd_front_d.c +++ b/libraries/libft/src/libft/lists/doubly_linked/ft_lstadd_front_d.c @@ -6,24 +6,25 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:18 by ldulling #+# #+# */ -/* Updated: 2023/11/27 00:25:38 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 14:10:51 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" +/** + * Can prepend a whole list, not just one node. + */ void ft_lstadd_front_d(t_list_d **lst, t_list_d *new) { - if (lst != NULL && new != NULL) + if (lst == NULL || new == NULL) + return ; + if (*lst == NULL) + *lst = new; + else { - if (*lst == NULL) - *lst = new; - else - { - new->next = *lst; - (*lst)->prev = new; - *lst = new; - } + ft_lstadd_back_d(&new, *lst); + *lst = new; } return ; } diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstadd_back.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstadd_back.c index eede9486..78691c45 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstadd_back.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstadd_back.c @@ -6,31 +6,30 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:12 by ldulling #+# #+# */ -/* Updated: 2023/11/13 21:33:20 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 14:29:36 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ +#include "libft.h" + /** * Does not mark the new node as the end of the list by itself. + * Therefore, a whole list can be appended, not just one node. */ - -#include "libft.h" - void ft_lstadd_back(t_list **lst, t_list *new) { t_list *cur; - if (lst != NULL && new != NULL) + if (lst == NULL || new == NULL) + return ; + if (*lst == NULL) + *lst = new; + else { - if (*lst == NULL) - *lst = new; - else - { - cur = *lst; - while (cur->next != NULL) - cur = cur->next; - cur->next = new; - } + cur = *lst; + while (cur->next != NULL) + cur = cur->next; + cur->next = new; } return ; } diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstadd_front.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstadd_front.c index 90af169a..96b8e227 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstadd_front.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstadd_front.c @@ -6,23 +6,25 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:18 by ldulling #+# #+# */ -/* Updated: 2023/09/24 16:21:35 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 11:32:51 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" +/** + * Can prepend a whole list, not just one node. + */ void ft_lstadd_front(t_list **lst, t_list *new) { - if (lst != NULL && new != NULL) + if (lst == NULL || new == NULL) + return ; + if (*lst == NULL) + *lst = new; + else { - if (*lst == NULL) - *lst = new; - else - { - new->next = *lst; - *lst = new; - } + ft_lstadd_back(&new, *lst); + *lst = new; } return ; } From ddd7ccc34925ca37a64d31b90971a5b5ec4d2dba Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 15:24:26 +0100 Subject: [PATCH 06/13] style: Standardize ft_lst function coding style and improve readability --- libraries/libft/build/libft.mk | 11 ++++++ libraries/libft/inc/libft.h | 36 ++++++++++++++++++- .../libft/lists/doubly_linked/ft_lstclear_d.c | 16 ++++----- .../lists/doubly_linked/ft_lstdelone_d.c | 23 ++++++++++++ .../lists/singly_linked/ft_lstinsert_after.c | 25 ++++++------- .../libft/lists/singly_linked/ft_lstiter.c | 15 ++++---- .../src/libft/lists/singly_linked/ft_lstmap.c | 4 +-- .../src/libft/lists/singly_linked/ft_lstpop.c | 10 +++--- 8 files changed, 100 insertions(+), 40 deletions(-) create mode 100644 libraries/libft/src/libft/lists/doubly_linked/ft_lstdelone_d.c diff --git a/libraries/libft/build/libft.mk b/libraries/libft/build/libft.mk index d4ad6a14..78e027d0 100644 --- a/libraries/libft/build/libft.mk +++ b/libraries/libft/build/libft.mk @@ -43,6 +43,17 @@ TMP += $(addprefix $(DIR)$(SUBDIR), \ ) # Lists: +# Doubly-linked: +SUBDIR := lists/doubly_linked/ +TMP += $(addprefix $(DIR)$(SUBDIR), \ + ft_lstadd_back_d.c \ + ft_lstadd_front_d.c \ + ft_lstclear_d.c \ + ft_lstdelone_d.c \ + ft_lstlast_d.c \ + ft_lstnew_d.c \ +) + # Singly-linked: SUBDIR := lists/singly_linked/ TMP += $(addprefix $(DIR)$(SUBDIR), \ diff --git a/libraries/libft/inc/libft.h b/libraries/libft/inc/libft.h index 8b64b6fd..9f6be9e4 100644 --- a/libraries/libft/inc/libft.h +++ b/libraries/libft/inc/libft.h @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:17:46 by ldulling #+# #+# */ -/* Updated: 2023/12/23 14:24:34 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 18:20:07 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,7 +34,9 @@ typedef struct s_list_d struct s_list_d *next; } t_list_d; +\ /* Chars */ + int ft_isalnum(int c); int ft_isalpha(int c); int ft_isascii(int c); @@ -44,7 +46,19 @@ int ft_isspace(int c); int ft_tolower(int c); int ft_toupper(int c); +\ +/* Lists doubly-linked */ + +void ft_lstadd_back_d(t_list_d **lst, t_list_d *new); +void ft_lstadd_front_d(t_list_d **lst, t_list_d *new); +void ft_lstclear_d(t_list_d **lst, void (*del)(void *)); +void ft_lstdelone_d(t_list_d *lst, void (*del)(void *)); +t_list_d *ft_lstlast_d(t_list_d *lst); +t_list_d *ft_lstnew_d(void *content); + +\ /* Lists singly-linked */ + void ft_lstadd_back(t_list **lst, t_list *new); void ft_lstadd_front(t_list **lst, t_list *new); void ft_lstclear(t_list **lst, void (*del)(void *)); @@ -60,7 +74,9 @@ int ft_lstsize(t_list *lst); void ft_lstsort_bubble(t_list **lst, void *(*cmp)(void *, void *)); void ft_lstswap_head(t_list **lst); +\ /* Memory */ + void ft_bzero(void *s, size_t n); void *ft_calloc(size_t nmemb, size_t size); void ft_free_and_null(void **ptr); @@ -70,11 +86,14 @@ void *ft_memcpy(void *dest, const void *src, size_t n); void *ft_memmove(void *dest, const void *src, size_t n); void *ft_memset(void *s, int c, size_t n); +\ /* Numbers */ + double ft_atof(const char *nptr); int ft_atoi(const char *nptr); long ft_atol(const char *nptr); +\ /* Put */ void ft_putchar_fd(char c, int fd); void ft_putendl_fd(char *s, int fd); @@ -84,7 +103,9 @@ size_t ft_putnchar_fd(unsigned char c, size_t n, int fd); size_t ft_putnstr_fd(const char *s, size_t n, int fd); void ft_putstr_fd(char *s, int fd); +\ /* Stack */ + void ft_stkclear(t_list **stk, void (*del)(void *)); void ft_stkdelone(t_list *stk, void (*del)(void *)); t_list *ft_stknew(void *content); @@ -93,7 +114,20 @@ t_list *ft_stkpop(t_list **stk); void ft_stkpush(t_list **stk, t_list *new); int ft_stksize(t_list *stk); + +/* Stack */ + +void ft_stkclear(t_list **stk, void (*del)(void *)); +void ft_stkdelone(t_list *stk, void (*del)(void *)); +t_list *ft_stknew(void *content); +t_list *ft_stkpeektop(t_list *stk); +t_list *ft_stkpop(t_list **stk); +void ft_stkpush(t_list **stk, t_list *new); +int ft_stksize(t_list *stk); + +\ /* Strings */ + char *ft_itoa(int n); char **ft_split(char const *s, char c); char **ft_split_at_index(char *str, size_t index); diff --git a/libraries/libft/src/libft/lists/doubly_linked/ft_lstclear_d.c b/libraries/libft/src/libft/lists/doubly_linked/ft_lstclear_d.c index 9eab53ac..0de4fd04 100644 --- a/libraries/libft/src/libft/lists/doubly_linked/ft_lstclear_d.c +++ b/libraries/libft/src/libft/lists/doubly_linked/ft_lstclear_d.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:22 by ldulling #+# #+# */ -/* Updated: 2023/11/27 00:31:29 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 14:25:30 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,15 +16,13 @@ void ft_lstclear_d(t_list_d **lst, void (*del)(void *)) { t_list_d *cur; - if (lst != NULL && del != NULL) + if (lst == NULL || del == NULL) + return ; + while (*lst != NULL) { - while (*lst != NULL) - { - cur = *lst; - *lst = (*lst)->next; - (*del)(cur->content); - free(cur); - } + cur = *lst; + *lst = (*lst)->next; + ft_lstdelone_d(cur, del); } return ; } diff --git a/libraries/libft/src/libft/lists/doubly_linked/ft_lstdelone_d.c b/libraries/libft/src/libft/lists/doubly_linked/ft_lstdelone_d.c new file mode 100644 index 00000000..56c03ff4 --- /dev/null +++ b/libraries/libft/src/libft/lists/doubly_linked/ft_lstdelone_d.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone_d.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ldulling +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/09/24 16:04:26 by ldulling #+# #+# */ +/* Updated: 2023/12/23 14:16:57 by ldulling ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstdelone_d(t_list_d *lst, void (*del)(void *)) +{ + if (lst == NULL) + return ; + if (del != NULL && lst->content != NULL) + (*del)(lst->content); + free(lst); + return ; +} diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstinsert_after.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstinsert_after.c index d64a0018..68237886 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstinsert_after.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstinsert_after.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:12 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:09:44 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 11:39:56 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,22 +26,17 @@ */ void ft_lstinsert_after(t_list **lst, t_list *new) { - t_list *last_new; - t_list *old; + t_list *old_next; - if (lst != NULL && new != NULL) + if (lst == NULL && new == NULL) + return ; + if (*lst == NULL) + *lst = new; + else { - if (*lst == NULL) - *lst = new; - else - { - old = (*lst)->next; - (*lst)->next = new; - last_new = new; - while (last_new->next != NULL) - last_new = last_new->next; - last_new->next = old; - } + old_next = (*lst)->next; + (*lst)->next = new; + ft_lstlast(new)->next = old_next; } return ; } diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstiter.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstiter.c index 5bec81f6..2b82ba08 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstiter.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstiter.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:29 by ldulling #+# #+# */ -/* Updated: 2023/09/24 16:21:57 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 11:41:51 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,14 +16,13 @@ void ft_lstiter(t_list *lst, void (*f)(void *)) { t_list *cur; - if (lst != NULL && f != NULL) + if (lst == NULL || f == NULL) + return ; + cur = lst; + while (cur != NULL) { - cur = lst; - while (cur != NULL) - { - (*f)(cur->content); - cur = cur->next; - } + (*f)(cur->content); + cur = cur->next; } return ; } diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstmap.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstmap.c index c1d9de74..faf7cc48 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstmap.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstmap.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:35 by ldulling #+# #+# */ -/* Updated: 2023/11/27 00:18:44 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 11:43:14 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) t_list *new_node; void *new_content; - if (!lst || !f || !del) + if (lst == NULL || f == NULL || del == NULL) return (NULL); new_lst = NULL; new_lst_tail = NULL; diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c index c1fb7697..15e79997 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:29 by ldulling #+# #+# */ -/* Updated: 2023/12/23 11:13:08 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 11:47:10 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,12 +23,12 @@ */ t_list *ft_lstpop(t_list **lst) { - t_list *popped; + t_list *popped_node; if (lst == NULL || *lst == NULL) return (NULL); - popped = *lst; + popped_node = *lst; *lst = (*lst)->next; - popped->next = NULL; - return (popped); + popped_node->next = NULL; + return (popped_node); } From 64d055f179a325b977442a77bb3fd831e786d7b7 Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 15:27:28 +0100 Subject: [PATCH 07/13] doc: Add @note highlighting feature to libft documentation --- libraries/libft/src/libft/memory/ft_memcpy.c | 8 +++++--- libraries/libft/src/libft/memory/ft_memmove.c | 8 +++++--- libraries/libft/src/libft/strings/ft_strlcat.c | 10 +++++----- libraries/libft/src/libft/strings/ft_strlen.c | 7 ++++--- libraries/libft/src/libft/strings/ft_strnstr.c | 8 +++++--- libraries/libft/src/libft/strings/ft_strtok.c | 8 +++++--- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/libraries/libft/src/libft/memory/ft_memcpy.c b/libraries/libft/src/libft/memory/ft_memcpy.c index 2f123e85..74a7248e 100644 --- a/libraries/libft/src/libft/memory/ft_memcpy.c +++ b/libraries/libft/src/libft/memory/ft_memcpy.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:08:20 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:26:15 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 12:17:36 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,11 +20,13 @@ * @param dest The memory area to copy to. * @param src The memory area to copy from. * @param n The number of bytes to copy. - * Note: Calling ft_memcpy with dest or src equal to NULL with n - * not 0 will cause a segmentation fault. * * @return Returns a pointer to dest. * + * @note Calling ft_memcpy with dest or src equal to NULL with n not 0 + * will cause a segmentation fault (mirrors the behavior of the + * original memcpy). + * */ void *ft_memcpy(void *dest, const void *src, size_t n) { diff --git a/libraries/libft/src/libft/memory/ft_memmove.c b/libraries/libft/src/libft/memory/ft_memmove.c index e4f3a270..fa74ad4d 100644 --- a/libraries/libft/src/libft/memory/ft_memmove.c +++ b/libraries/libft/src/libft/memory/ft_memmove.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:08:23 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:26:52 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 12:17:54 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,8 +24,10 @@ * @param n The number of bytes to copy. * * @return Returns a pointer to dest. - * Note: Calling ft_memcpy with dest or src equal to NULL with n - * not 0 will cause a segmentation fault. + * + * @note Calling ft_memcpy with dest or src equal to NULL with n not 0 + * will cause a segmentation fault (mirrors the behavior of the + * original memmove). * */ void *ft_memmove(void *dest, const void *src, size_t n) diff --git a/libraries/libft/src/libft/strings/ft_strlcat.c b/libraries/libft/src/libft/strings/ft_strlcat.c index 7ab0088e..b4518244 100644 --- a/libraries/libft/src/libft/strings/ft_strlcat.c +++ b/libraries/libft/src/libft/strings/ft_strlcat.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:15:16 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:30:03 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 12:21:31 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,11 +20,7 @@ * longer than size. * * @param dst The string to be appended to. - * Note: Calling ft_strlcat with dst equal to NULL with a size - * not 0 will cause a segmentation fault. * @param src The string to append to dst. - * Note: Calling ft_strlcat with src equal to NULL will cause a - * segmentation fault. * @param size The total size of dst, including the space for the * NUL-terminator. * @@ -33,6 +29,10 @@ * If the return value is >= size, the output string has been * truncated. * + * @note Calling ft_strlcat with dst equal to NULL with a size not 0, + * or with src equal to NULL will cause a segmentation fault + * (mirrors the behavior of the original strlcat). + * */ size_t ft_strlcat(char *dst, const char *src, size_t size) { diff --git a/libraries/libft/src/libft/strings/ft_strlen.c b/libraries/libft/src/libft/strings/ft_strlen.c index 97180cb1..ffa8eeb8 100644 --- a/libraries/libft/src/libft/strings/ft_strlen.c +++ b/libraries/libft/src/libft/strings/ft_strlen.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:16:06 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:30:43 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 12:18:50 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,11 +17,12 @@ * excluding the terminating null byte ('\0'). * * @param s The string to be measured. - * Note: Calling ft_strlen with s equal to NULL will cause a - * segmentation fault. * * @return The length of the string s. * + * @note Calling ft_strlen with s equal to NULL will cause a segmentation + * fault (mirrors the behavior of the original strlen). + * */ size_t ft_strlen(const char *s) { diff --git a/libraries/libft/src/libft/strings/ft_strnstr.c b/libraries/libft/src/libft/strings/ft_strnstr.c index b241dfdd..02b5ff4a 100644 --- a/libraries/libft/src/libft/strings/ft_strnstr.c +++ b/libraries/libft/src/libft/strings/ft_strnstr.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:16:27 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:32:08 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 12:17:17 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,8 +18,6 @@ * searched. Characters that appear after a '\0' character are not searched. * * @param big The string to be scanned. - * Note: Calling ft_strnstr with big equal to NULL with a size - * not 0 will cause a segmentation fault. * @param little The string to be searched within big. * @param len The number of characters to be scanned in big. * @@ -28,6 +26,10 @@ * to the first character of the first occurrence of little is * returned. * + * @note Calling ft_strnstr with big equal to NULL with a size not 0 + * will cause a segmentation fault (mirrors the behavior of the + * original strnstr). + * */ char *ft_strnstr(const char *big, const char *little, size_t len) { diff --git a/libraries/libft/src/libft/strings/ft_strtok.c b/libraries/libft/src/libft/strings/ft_strtok.c index 49e6b32d..c8d8d71a 100644 --- a/libraries/libft/src/libft/strings/ft_strtok.c +++ b/libraries/libft/src/libft/strings/ft_strtok.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/24 21:48:31 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:33:22 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 15:34:45 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,6 @@ * @param str The string to be tokenized. On the first call to ft_strtok, * this should be the string you want to tokenize. On subsequent * calls, it should be NULL. - * Note: Calling ft_strtok the first time with str equal to NULL - * will cause a segmentation fault. * @param delim The delimiter string. Each character in this string is * considered a valid delimiter. * @@ -28,6 +26,10 @@ * string. * If there are no more tokens, it returns NULL. * + * @note Calling ft_strtok the first time with str equal to NULL will + * cause a segmentation fault (mirrors the behavior of the + * original strtok). + * */ char *ft_strtok(char *str, const char *delim) { From b8195b5b8f2452de78a94349949e5e445dab0759 Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 16:13:11 +0100 Subject: [PATCH 08/13] refactor: Replace ft_stk functions with ft_lst functions --- source/frontend/parser/parse.c | 12 +++++------- source/frontend/parser/parser_operation.c | 24 +++++++++++------------ source/frontend/parser/parser_utils.c | 8 ++++---- source/utils/stack_utils.c | 8 ++++---- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/source/frontend/parser/parse.c b/source/frontend/parser/parse.c index 075a70bd..eb8a1812 100644 --- a/source/frontend/parser/parse.c +++ b/source/frontend/parser/parse.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* parse.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ +/* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/11 17:28:20 by lyeh #+# #+# */ -/* Updated: 2023/12/22 20:54:13 by lyeh ### ########.fr */ +/* Updated: 2023/12/23 15:49:55 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,8 +27,7 @@ bool parse_step(t_pt_node *pt_entry, else if (pt_entry && pt_entry->action == A_REDUCE) { if (parse_reduce(state_stack, parse_stack, pt_entry) && \ - parse_goto(state_stack, - get_token_from_stack(ft_stkpeektop(*parse_stack))->type)) + parse_goto(state_stack, get_token_from_stack(*parse_stack)->type)) ret = true; } else @@ -44,8 +43,7 @@ char *get_error_token_data(t_list *token_list, t_list *parse_stack) if (token_list) error_token_data = get_token_data_from_list(token_list); else - error_token_data = get_token_from_stack( - ft_stkpeektop(parse_stack))->data; + error_token_data = get_token_from_stack(parse_stack)->data; return (error_token_data); } @@ -67,7 +65,7 @@ bool parse( { print_token_list(*token_list); pt_entry = get_next_pt_entry( - get_state_from_stack(ft_stkpeektop(*state_stack)), + get_state_from_stack(*state_stack), get_token_type_from_list(*token_list), A_SHIFT | A_REDUCE | A_ACCEPT); if (pt_entry && pt_entry->action == A_ACCEPT) diff --git a/source/frontend/parser/parser_operation.c b/source/frontend/parser/parser_operation.c index 3e1348ed..46e0a1a6 100644 --- a/source/frontend/parser/parser_operation.c +++ b/source/frontend/parser/parser_operation.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* parser_operation.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ +/* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/16 19:52:51 by lyeh #+# #+# */ -/* Updated: 2023/12/22 20:54:32 by lyeh ### ########.fr */ +/* Updated: 2023/12/23 16:08:09 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,10 +22,10 @@ bool push_state(t_list **state_stack, int next_step) if (!tmp) return (false); *tmp = next_step; - node = ft_stknew((void *)tmp); + node = ft_lstnew((void *)tmp); if (!node) return (free(tmp), false); - ft_stkpush(state_stack, node); + ft_lstadd_front(state_stack, node); return (true); } @@ -33,10 +33,10 @@ bool push_token(t_list **parse_stack, t_token *token) { t_list *node; - node = ft_stknew(token); + node = ft_lstnew(token); if (!node) return (false); - ft_stkpush(parse_stack, node); + ft_lstadd_front(parse_stack, node); return (true); } @@ -49,9 +49,9 @@ bool parse_shift(t_token *input_token, return (false); printf("After shift:\n"); printf("state_stack: "); - print_state_stack(ft_stkpeektop(*state_stack)); + print_state_stack(*state_stack); printf("parse_stack: "); - print_parse_stack(ft_stkpeektop(*parse_stack)); + print_parse_stack(*parse_stack); return (true); } @@ -70,9 +70,9 @@ bool parse_reduce( return (free_token_node(reduction_node), false); printf("reduction_node->type: %d\n", reduction_node->type); printf("state_stack: "); - print_state_stack(ft_stkpeektop(*state_stack)); + print_state_stack(*state_stack); printf("parse_stack: "); - print_parse_stack(ft_stkpeektop(*parse_stack)); + print_parse_stack(*parse_stack); return (true); } @@ -81,7 +81,7 @@ bool parse_goto(t_list **state_stack, int token_type) t_pt_node *pt_entry; pt_entry = get_next_pt_entry( - get_state_from_stack(ft_stkpeektop(*state_stack)), + get_state_from_stack(*state_stack), token_type, A_GOTO); if (!pt_entry) @@ -90,6 +90,6 @@ bool parse_goto(t_list **state_stack, int token_type) return (free(pt_entry), false); printf("After goto:\n"); printf("state_stack: "); - print_state_stack(ft_stkpeektop(*state_stack)); + print_state_stack(*state_stack); return (free(pt_entry), true); } diff --git a/source/frontend/parser/parser_utils.c b/source/frontend/parser/parser_utils.c index 1570163a..10106246 100644 --- a/source/frontend/parser/parser_utils.c +++ b/source/frontend/parser/parser_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* parser_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ +/* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/16 22:05:05 by lyeh #+# #+# */ -/* Updated: 2023/12/22 20:54:41 by lyeh ### ########.fr */ +/* Updated: 2023/12/23 15:41:56 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,6 +24,6 @@ bool init_parse(t_list **state_stack, t_list **parse_stack) void free_parse(t_list **state_stack, t_list **parse_stack) { - ft_stkclear(state_stack, free); - ft_stkclear(parse_stack, free_token_node); + ft_lstclear(state_stack, free); + ft_lstclear(parse_stack, free_token_node); } diff --git a/source/utils/stack_utils.c b/source/utils/stack_utils.c index 9927c6e9..e200a35e 100644 --- a/source/utils/stack_utils.c +++ b/source/utils/stack_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* stack_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ +/* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/16 21:55:34 by lyeh #+# #+# */ -/* Updated: 2023/12/22 20:53:49 by lyeh ### ########.fr */ +/* Updated: 2023/12/23 15:42:41 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,10 +20,10 @@ bool drop_num_stack(t_list **stack, int num, void (*del)(void *)) i = 0; while (i < num) { - node = ft_stkpop(stack); + node = ft_lstpop(stack); if (!node) return (false); - ft_stkdelone(node, del); + ft_lstdelone(node, del); i++; } return (true); From 3109c80a7d0e79c52081325ef9d0f495188a2897 Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 16:13:54 +0100 Subject: [PATCH 09/13] lib: Remove ft_stk functions from libft --- libraries/libft/build/libft.mk | 14 +-------- libraries/libft/inc/libft.h | 24 +-------------- libraries/libft/src/libft/stack/ft_stkclear.c | 30 ------------------- .../libft/src/libft/stack/ft_stkdelone.c | 24 --------------- libraries/libft/src/libft/stack/ft_stknew.c | 25 ---------------- .../libft/src/libft/stack/ft_stkpeektop.c | 20 ------------- libraries/libft/src/libft/stack/ft_stkpop.c | 27 ----------------- libraries/libft/src/libft/stack/ft_stkpush.c | 28 ----------------- libraries/libft/src/libft/stack/ft_stksize.c | 30 ------------------- 9 files changed, 2 insertions(+), 220 deletions(-) delete mode 100644 libraries/libft/src/libft/stack/ft_stkclear.c delete mode 100644 libraries/libft/src/libft/stack/ft_stkdelone.c delete mode 100644 libraries/libft/src/libft/stack/ft_stknew.c delete mode 100644 libraries/libft/src/libft/stack/ft_stkpeektop.c delete mode 100644 libraries/libft/src/libft/stack/ft_stkpop.c delete mode 100644 libraries/libft/src/libft/stack/ft_stkpush.c delete mode 100644 libraries/libft/src/libft/stack/ft_stksize.c diff --git a/libraries/libft/build/libft.mk b/libraries/libft/build/libft.mk index 78e027d0..9a0c3168 100644 --- a/libraries/libft/build/libft.mk +++ b/libraries/libft/build/libft.mk @@ -6,7 +6,7 @@ # By: ldulling +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/16 13:33:38 by ldulling #+# #+# # -# Updated: 2023/12/23 14:23:25 by ldulling ### ########.fr # +# Updated: 2023/12/23 16:09:12 by ldulling ### ########.fr # # # # **************************************************************************** # @@ -106,18 +106,6 @@ TMP += $(addprefix $(DIR)$(SUBDIR), \ ft_putstr_fd.c \ ) -# Stack: -SUBDIR := stack/ -TMP += $(addprefix $(DIR)$(SUBDIR), \ - ft_stkclear.c \ - ft_stkdelone.c \ - ft_stknew.c \ - ft_stkpeektop.c \ - ft_stkpop.c \ - ft_stkpush.c \ - ft_stksize.c \ -) - # Strings: SUBDIR := strings/ TMP += $(addprefix $(DIR)$(SUBDIR), \ diff --git a/libraries/libft/inc/libft.h b/libraries/libft/inc/libft.h index 9f6be9e4..73d0ac80 100644 --- a/libraries/libft/inc/libft.h +++ b/libraries/libft/inc/libft.h @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:17:46 by ldulling #+# #+# */ -/* Updated: 2023/12/23 18:20:07 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 18:21:23 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -103,28 +103,6 @@ size_t ft_putnchar_fd(unsigned char c, size_t n, int fd); size_t ft_putnstr_fd(const char *s, size_t n, int fd); void ft_putstr_fd(char *s, int fd); -\ -/* Stack */ - -void ft_stkclear(t_list **stk, void (*del)(void *)); -void ft_stkdelone(t_list *stk, void (*del)(void *)); -t_list *ft_stknew(void *content); -t_list *ft_stkpeektop(t_list *stk); -t_list *ft_stkpop(t_list **stk); -void ft_stkpush(t_list **stk, t_list *new); -int ft_stksize(t_list *stk); - - -/* Stack */ - -void ft_stkclear(t_list **stk, void (*del)(void *)); -void ft_stkdelone(t_list *stk, void (*del)(void *)); -t_list *ft_stknew(void *content); -t_list *ft_stkpeektop(t_list *stk); -t_list *ft_stkpop(t_list **stk); -void ft_stkpush(t_list **stk, t_list *new); -int ft_stksize(t_list *stk); - \ /* Strings */ diff --git a/libraries/libft/src/libft/stack/ft_stkclear.c b/libraries/libft/src/libft/stack/ft_stkclear.c deleted file mode 100644 index f47011c7..00000000 --- a/libraries/libft/src/libft/stack/ft_stkclear.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stkclear.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 21:03:00 by lyeh #+# #+# */ -/* Updated: 2023/12/22 19:53:22 by lyeh ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_stkclear(t_list **stk, void (*del)(void *)) -{ - t_list *cur; - - if (stk == NULL) - return ; - while (*stk != NULL) - { - cur = *stk; - *stk = (*stk)->next; - if (*del) - (*del)(cur->content); - free(cur); - } - return ; -} diff --git a/libraries/libft/src/libft/stack/ft_stkdelone.c b/libraries/libft/src/libft/stack/ft_stkdelone.c deleted file mode 100644 index 2e53dca9..00000000 --- a/libraries/libft/src/libft/stack/ft_stkdelone.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stkdelone.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/17 19:41:12 by lyeh #+# #+# */ -/* Updated: 2023/12/22 19:53:31 by lyeh ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_stkdelone(t_list *stk, void (*del)(void *)) -{ - if (stk != NULL) - { - if (del != NULL && stk->content != NULL) - (*del)(stk->content); - free(stk); - } - return ; -} diff --git a/libraries/libft/src/libft/stack/ft_stknew.c b/libraries/libft/src/libft/stack/ft_stknew.c deleted file mode 100644 index 7b5b1989..00000000 --- a/libraries/libft/src/libft/stack/ft_stknew.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stknew.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 20:59:19 by lyeh #+# #+# */ -/* Updated: 2023/12/22 19:53:40 by lyeh ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_stknew(void *content) -{ - t_list *new_node; - - new_node = malloc(sizeof(t_list)); - if (new_node == NULL) - return (NULL); - new_node->content = content; - new_node->next = NULL; - return (new_node); -} diff --git a/libraries/libft/src/libft/stack/ft_stkpeektop.c b/libraries/libft/src/libft/stack/ft_stkpeektop.c deleted file mode 100644 index 9d520106..00000000 --- a/libraries/libft/src/libft/stack/ft_stkpeektop.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stkpeektop.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/13 20:29:13 by lyeh #+# #+# */ -/* Updated: 2023/12/22 19:53:45 by lyeh ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_stkpeektop(t_list *stk) -{ - if (stk == NULL) - return (NULL); - return (stk); -} diff --git a/libraries/libft/src/libft/stack/ft_stkpop.c b/libraries/libft/src/libft/stack/ft_stkpop.c deleted file mode 100644 index 7cccbb90..00000000 --- a/libraries/libft/src/libft/stack/ft_stkpop.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stkpop.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 21:07:28 by lyeh #+# #+# */ -/* Updated: 2023/12/22 19:53:51 by lyeh ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_stkpop(t_list **stk) -{ - t_list *top; - - if (stk != NULL && *stk != NULL) - { - top = *stk; - *stk = (*stk)->next; - top->next = NULL; - return (top); - } - return (NULL); -} diff --git a/libraries/libft/src/libft/stack/ft_stkpush.c b/libraries/libft/src/libft/stack/ft_stkpush.c deleted file mode 100644 index 39e952ff..00000000 --- a/libraries/libft/src/libft/stack/ft_stkpush.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stkpush.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 21:05:44 by lyeh #+# #+# */ -/* Updated: 2023/12/22 19:54:53 by lyeh ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_stkpush(t_list **stk, t_list *new) -{ - if (stk != NULL && new != NULL) - { - if (*stk == NULL) - *stk = new; - else - { - new->next = *stk; - *stk = new; - } - } - return ; -} diff --git a/libraries/libft/src/libft/stack/ft_stksize.c b/libraries/libft/src/libft/stack/ft_stksize.c deleted file mode 100644 index d966f70b..00000000 --- a/libraries/libft/src/libft/stack/ft_stksize.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stksize.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: lyeh +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/11 21:04:09 by lyeh #+# #+# */ -/* Updated: 2023/12/22 19:54:04 by lyeh ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_stksize(t_list *stk) -{ - int n; - t_list *cur; - - if (stk == NULL) - return (0); - n = 0; - cur = stk; - while (cur != NULL) - { - cur = cur->next; - n++; - } - return (n); -} From 89edf9848887f66518335b2a7fb47b64be7f949f Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 18:24:14 +0100 Subject: [PATCH 10/13] fix: Prevent segfaults in ft_strmatches_any If given a NULL, now it will search for another NULL in the other given strings. Also no segfault anymore when any of the given strings is NULL. --- .../src/libft/strings/ft_strmatches_any.c | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/libraries/libft/src/libft/strings/ft_strmatches_any.c b/libraries/libft/src/libft/strings/ft_strmatches_any.c index c015db55..27a51bd3 100644 --- a/libraries/libft/src/libft/strings/ft_strmatches_any.c +++ b/libraries/libft/src/libft/strings/ft_strmatches_any.c @@ -6,40 +6,64 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/13 19:50:45 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:31:32 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 18:12:21 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" +static int search_null_str(va_list ap, int n); + /** * The ft_strmatches_any function checks if the first string matches any of the * n other strings provided as arguments. * - * @param str The string to compare. - * @param n The number of strings to compare against. + * @param str The string to compare against. + * If str is NULL, NULL will be searched. + * @param n The number of strings to compare. * @param ... Variable number of strings to compare with str. * - * @return If a match is found, it returns the position of the matching - * string (1-indexed). - * If no match is found, it returns 0. + * @return If a match is found, the position of the matching string + * (1-indexed). + * If no match is found, 0. * */ int ft_strmatches_any(const char *str, int n, ...) { - va_list ap; - int i; + va_list ap; + int i; + const char *cmp; va_start(ap, n); - i = 0; - while (i++ < n) + if (str == NULL) + i = search_null_str(ap, n); + else { - if (ft_strcmp(str, va_arg(ap, const char *)) == 0) + i = 0; + while (i < n) { - va_end(ap); - return (i); + cmp = va_arg(ap, const char *); + if (cmp != NULL && ft_strcmp(str, cmp) == 0) + break ; + i++; } } va_end(ap); - return (0); + if (i == n) + return (0); + return (i + 1); +} + +static int search_null_str(va_list ap, int n) +{ + int i; + + i = 0; + while (i < n) + { + if (va_arg(ap, const char *) == NULL) + break ; + i++; + } + return (i); } From b26337ca32d43f4bf3a75e2ace8d3ee93531e435 Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 18:27:36 +0100 Subject: [PATCH 11/13] doc: Add documentation to the rest of the libft functions that can segfault --- libraries/libft/src/libft/strings/ft_strchr.c | 16 +++++++++++++- libraries/libft/src/libft/strings/ft_strcmp.c | 19 ++++++++++++++++- libraries/libft/src/libft/strings/ft_strdup.c | 15 ++++++++++++- .../libft/src/libft/strings/ft_strlcpy.c | 21 +++++++++++++++++-- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/libraries/libft/src/libft/strings/ft_strchr.c b/libraries/libft/src/libft/strings/ft_strchr.c index 55315cfb..76f0c813 100644 --- a/libraries/libft/src/libft/strings/ft_strchr.c +++ b/libraries/libft/src/libft/strings/ft_strchr.c @@ -6,12 +6,26 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:13:12 by ldulling #+# #+# */ -/* Updated: 2023/09/24 16:14:51 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 16:59:08 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" +/** + * The ft_strchr function locates the first occurrence of c (converted to a + * char) in the string pointed to by s. + * + * @param s The string in which to search for the character. + * @param c The character to search for. + * + * @return A pointer to the located character, or NULL if the character does + * not appear in the string. + * + * @note Calling ft_strchr with s equal to NULL will cause a segmentation + * fault (mirrors the behavior of the original strchr). + * + */ char *ft_strchr(const char *s, int c) { char casted_c; diff --git a/libraries/libft/src/libft/strings/ft_strcmp.c b/libraries/libft/src/libft/strings/ft_strcmp.c index c15ff97e..283d03f9 100644 --- a/libraries/libft/src/libft/strings/ft_strcmp.c +++ b/libraries/libft/src/libft/strings/ft_strcmp.c @@ -6,12 +6,29 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:16:22 by ldulling #+# #+# */ -/* Updated: 2023/11/12 11:18:04 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 16:51:07 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" +/** + * The ft_strcmp function compares the string pointed to by s1 with the string + * pointed to by s2. + * + * @param s1 A pointer to the first string. + * @param s2 A pointer to the second string. + * + * @return 0 if the strings are identical. + * A positive integer if the first character that does not match + * has a greater value in s1 than in s2. + * A negative integer if the first character that does not match + * has a lower value in s1 than in s2. + * + * @note Calling ft_strcmp with s1 or s2 equal to NULL will cause a + * segmentation fault (mirrors the behavior of the original + * strcmp). + */ int ft_strcmp(const char *s1, const char *s2) { const unsigned char *casted_ptr_s1; diff --git a/libraries/libft/src/libft/strings/ft_strdup.c b/libraries/libft/src/libft/strings/ft_strdup.c index ef8bded8..14d9f171 100644 --- a/libraries/libft/src/libft/strings/ft_strdup.c +++ b/libraries/libft/src/libft/strings/ft_strdup.c @@ -6,12 +6,25 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:14:59 by ldulling #+# #+# */ -/* Updated: 2023/09/24 16:15:00 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 16:28:07 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" +/** + * The ft_strdup function duplicates the string pointed to by s. + * + * @param s A pointer to the string to be duplicated. + * + * @return A pointer to the newly allocated string, or NULL if the + * allocation failed. + * The returned string will have to be freed later. + * + * @note Calling ft_strdup with s equal to NULL will cause a segmentation + * fault (mirrors the behavior of the original strdup). + * + */ char *ft_strdup(const char *s) { char *dup; diff --git a/libraries/libft/src/libft/strings/ft_strlcpy.c b/libraries/libft/src/libft/strings/ft_strlcpy.c index cc19e3bb..4c4b0ab9 100644 --- a/libraries/libft/src/libft/strings/ft_strlcpy.c +++ b/libraries/libft/src/libft/strings/ft_strlcpy.c @@ -6,14 +6,31 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:15:57 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:18:18 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 17:15:07 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" /** - * @param size Has to account for NUL-terminator. + * The ft_strlcpy function copies the NUL-terminated string from src to dst. + * It will copy at most size - 1 characters. + * It will then NUL-terminate, unless size is 0 or the src string is longer than + * size. + * + * @param dst The string to copy to. + * @param src The string to copy from. + * @param size The total size of dst, including the space for the + * NUL-terminator. + * + * @return The total length of src. + * If the return value is >= size, the output string has been + * truncated. + * + * @note Calling ft_strlcpy with dst equal to NULL with a size not 0, + * or with src equal to NULL will cause a segmentation fault + * (mirrors the behavior of the original strlcpy). + * */ size_t ft_strlcpy(char *dst, const char *src, size_t size) { From 4c3698a23ca7d6118f7d33b5d7263dbd740c843f Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 18:28:19 +0100 Subject: [PATCH 12/13] style: Rename a tmp variable in parser to be more descriptive --- source/frontend/parser/parser_operation.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/frontend/parser/parser_operation.c b/source/frontend/parser/parser_operation.c index 46e0a1a6..8887b847 100644 --- a/source/frontend/parser/parser_operation.c +++ b/source/frontend/parser/parser_operation.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/16 19:52:51 by lyeh #+# #+# */ -/* Updated: 2023/12/23 16:08:09 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 18:46:46 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,15 +16,15 @@ bool push_state(t_list **state_stack, int next_step) { t_list *node; - int *tmp; + int *state; - tmp = malloc(sizeof(int)); - if (!tmp) + state = malloc(sizeof(int)); + if (!state) return (false); - *tmp = next_step; - node = ft_lstnew((void *)tmp); + *state = next_step; + node = ft_lstnew(state); if (!node) - return (free(tmp), false); + return (free(state), false); ft_lstadd_front(state_stack, node); return (true); } From 7a706c43f0cebbf076b7f99a9ab67bc310d72e61 Mon Sep 17 00:00:00 2001 From: Lukas Dullinger <129603980+itislu@users.noreply.github.com> Date: Sat, 23 Dec 2023 21:02:00 +0100 Subject: [PATCH 13/13] style: Rename ft_lstpop functions to ft_lstpop_front --- libraries/libft/build/libft.mk | 6 +++--- libraries/libft/inc/libft.h | 6 +++--- .../singly_linked/{ft_lstpop.c => ft_lstpop_front.c} | 10 +++++----- .../{ft_lstpop_content.c => ft_lstpop_front_content.c} | 10 +++++----- source/frontend/lexer/create_token_list.c | 4 ++-- source/frontend/parser/parse.c | 4 ++-- source/utils/stack_utils.c | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) rename libraries/libft/src/libft/lists/singly_linked/{ft_lstpop.c => ft_lstpop_front.c} (79%) rename libraries/libft/src/libft/lists/singly_linked/{ft_lstpop_content.c => ft_lstpop_front_content.c} (78%) diff --git a/libraries/libft/build/libft.mk b/libraries/libft/build/libft.mk index 9a0c3168..d2580f2a 100644 --- a/libraries/libft/build/libft.mk +++ b/libraries/libft/build/libft.mk @@ -6,7 +6,7 @@ # By: ldulling +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/16 13:33:38 by ldulling #+# #+# # -# Updated: 2023/12/23 16:09:12 by ldulling ### ########.fr # +# Updated: 2023/12/23 20:58:20 by ldulling ### ########.fr # # # # **************************************************************************** # @@ -66,8 +66,8 @@ TMP += $(addprefix $(DIR)$(SUBDIR), \ ft_lstlast.c \ ft_lstmap.c \ ft_lstnew.c \ - ft_lstpop.c \ - ft_lstpop_content.c \ + ft_lstpop_front.c \ + ft_lstpop_front_content.c \ ft_lstsize.c \ ft_lstsort_bubble.c \ ft_lstswap_head.c \ diff --git a/libraries/libft/inc/libft.h b/libraries/libft/inc/libft.h index 73d0ac80..142b6b69 100644 --- a/libraries/libft/inc/libft.h +++ b/libraries/libft/inc/libft.h @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:17:46 by ldulling #+# #+# */ -/* Updated: 2023/12/23 18:21:23 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 20:58:20 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,8 +68,8 @@ void ft_lstiter(t_list *lst, void (*f)(void *)); t_list *ft_lstlast(t_list *lst); t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); t_list *ft_lstnew(void *content); -t_list *ft_lstpop(t_list **lst); -void *ft_lstpop_content(t_list **lst); +t_list *ft_lstpop_front(t_list **lst); +void *ft_lstpop_front_content(t_list **lst); int ft_lstsize(t_list *lst); void ft_lstsort_bubble(t_list **lst, void *(*cmp)(void *, void *)); void ft_lstswap_head(t_list **lst); diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstpop_front.c similarity index 79% rename from libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c rename to libraries/libft/src/libft/lists/singly_linked/ft_lstpop_front.c index 15e79997..dc2703fb 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstpop.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstpop_front.c @@ -1,27 +1,27 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstpop.c :+: :+: :+: */ +/* ft_lstpop_front.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:29 by ldulling #+# #+# */ -/* Updated: 2023/12/23 11:47:10 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 21:00:54 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" /** - * The ft_lstpop function removes the first node from a singly linked list and - * returns it - like popping a stack. + * The ft_lstpop_front function removes the first node from a singly linked list + * and returns it - like popping a stack. * * @param lst A double pointer to the first node of the list. * * @return The removed node, or NULL if the list was empty. * */ -t_list *ft_lstpop(t_list **lst) +t_list *ft_lstpop_front(t_list **lst) { t_list *popped_node; diff --git a/libraries/libft/src/libft/lists/singly_linked/ft_lstpop_content.c b/libraries/libft/src/libft/lists/singly_linked/ft_lstpop_front_content.c similarity index 78% rename from libraries/libft/src/libft/lists/singly_linked/ft_lstpop_content.c rename to libraries/libft/src/libft/lists/singly_linked/ft_lstpop_front_content.c index 01d1e136..7c13cdb0 100644 --- a/libraries/libft/src/libft/lists/singly_linked/ft_lstpop_content.c +++ b/libraries/libft/src/libft/lists/singly_linked/ft_lstpop_front_content.c @@ -1,27 +1,27 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstpop_content.c :+: :+: :+: */ +/* ft_lstpop_front_content.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/24 16:04:29 by ldulling #+# #+# */ -/* Updated: 2023/12/20 19:11:45 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 21:00:58 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" /** - * The ft_lstpop_content function removes and frees the first node from a singly - * linked list and returns its content - like popping a stack. + * The ft_lstpop_front_content function removes and frees the first node from a + * singly linked list and returns its content - like popping a stack. * * @param lst A double pointer to the first node of the list. * * @return The content of the removed node, or NULL if the list was empty. * */ -void *ft_lstpop_content(t_list **lst) +void *ft_lstpop_front_content(t_list **lst) { void *popped_content; t_list *popped_node; diff --git a/source/frontend/lexer/create_token_list.c b/source/frontend/lexer/create_token_list.c index 400cd139..139d8cc4 100644 --- a/source/frontend/lexer/create_token_list.c +++ b/source/frontend/lexer/create_token_list.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/20 11:54:32 by ldulling #+# #+# */ -/* Updated: 2023/12/21 20:09:21 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 20:58:20 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ bool create_token_list(t_list **token_list, t_list **token_data_list) if (!new_nodes || !separate_operators(new_nodes, 0)) break ; ft_lstadd_back(token_list, new_nodes); - free(ft_lstpop(token_data_list)); + free(ft_lstpop_front(token_data_list)); } if (*token_data_list) return (ft_lstclear(token_data_list, free), free_token_node(token), \ diff --git a/source/frontend/parser/parse.c b/source/frontend/parser/parse.c index eb8a1812..4ebe4413 100644 --- a/source/frontend/parser/parse.c +++ b/source/frontend/parser/parse.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/11 17:28:20 by lyeh #+# #+# */ -/* Updated: 2023/12/23 15:49:55 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 20:58:20 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ bool parse_step(t_pt_node *pt_entry, ret = false; if (pt_entry && pt_entry->action == A_SHIFT) - ret = parse_shift(ft_lstpop_content(token_list), + ret = parse_shift(ft_lstpop_front_content(token_list), state_stack, parse_stack, pt_entry->next_state); else if (pt_entry && pt_entry->action == A_REDUCE) { diff --git a/source/utils/stack_utils.c b/source/utils/stack_utils.c index e200a35e..c6c113a8 100644 --- a/source/utils/stack_utils.c +++ b/source/utils/stack_utils.c @@ -6,7 +6,7 @@ /* By: ldulling +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/16 21:55:34 by lyeh #+# #+# */ -/* Updated: 2023/12/23 15:42:41 by ldulling ### ########.fr */ +/* Updated: 2023/12/23 20:58:20 by ldulling ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ bool drop_num_stack(t_list **stack, int num, void (*del)(void *)) i = 0; while (i < num) { - node = ft_lstpop(stack); + node = ft_lstpop_front(stack); if (!node) return (false); ft_lstdelone(node, del);