From d6b4b8116084f7aec25c101a82fc457ac9989033 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Wed, 22 Jan 2025 17:34:07 +0100 Subject: [PATCH] Test test test --- include/token.h | 4 +++- src/free_token.c | 31 ++++++++++++++++++++++++++++--- src/parse_cmd.c | 2 +- src/parser.c | 4 ++-- src/praise_the_norme.c | 6 +++--- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/include/token.h b/include/token.h index 2e8da35..67d5737 100644 --- a/include/token.h +++ b/include/token.h @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 13:27:18 by dkaiser #+# #+# */ -/* Updated: 2025/01/20 19:10:30 by chuhlig ### ########.fr */ +/* Updated: 2025/01/22 17:27:48 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,4 +50,6 @@ void tokenizer(char *s, t_token **token_list, char quote_check); void print_token(t_token *token); +void free_token2(t_token *token); +void free_token_and_connect2(t_token *token); #endif diff --git a/src/free_token.c b/src/free_token.c index 66ab1dd..2292eb0 100644 --- a/src/free_token.c +++ b/src/free_token.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 14:38:57 by dkaiser #+# #+# */ -/* Updated: 2025/01/22 15:56:38 by chuhlig ### ########.fr */ +/* Updated: 2025/01/22 17:28:31 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,19 @@ void free_token(t_token *token) token = NULL; } +void free_token2(t_token *token) +{ + if (token->previous != NULL) + token->previous->next = NULL; + if (token->next != NULL) + token->next->previous = NULL; + if (token->type == STRING_TOKEN && token->content.string != NULL) + free(token->content.string); // Ensure content is freed + free(token);//maybe free token + token = NULL; +} + + void free_token_and_connect(t_token *token) { if (token->previous != NULL) @@ -38,14 +51,26 @@ void free_token_and_connect(t_token *token) token = NULL; } +void free_token_and_connect2(t_token *token) +{ + if (token->previous != NULL) + token->previous->next = token->next; + if (token->next != NULL) + token->next->previous = token->previous; + if (token->type == STRING_TOKEN && token->content.string != NULL) + free(token->content.string); // Ensure content is freed + free(token); + token = NULL; +} + void free_tokens(t_token *tokens) { while (tokens->next != NULL) { tokens = tokens->next; - free_token(tokens->previous); + free_token2(tokens->previous); } - free_token(tokens); + free_token2(tokens); } // void free_tokens(t_token *tokens) // { diff --git a/src/parse_cmd.c b/src/parse_cmd.c index c0a9ad9..02c4bda 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */ -/* Updated: 2025/01/21 21:27:29 by chuhlig ### ########.fr */ +/* Updated: 2025/01/22 17:26:14 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/parser.c b/src/parser.c index e7b53c2..2d748c9 100644 --- a/src/parser.c +++ b/src/parser.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/29 15:53:29 by dkaiser #+# #+# */ -/* Updated: 2025/01/21 21:27:15 by chuhlig ### ########.fr */ +/* Updated: 2025/01/22 17:13:50 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,7 @@ t_token *split_at_first(t_token **tokens, int type) *tokens = split->next; if (result == split) result = NULL; - free_token(split); + free_token2(split); split = NULL; return (result); } diff --git a/src/praise_the_norme.c b/src/praise_the_norme.c index a22843b..6af28c3 100644 --- a/src/praise_the_norme.c +++ b/src/praise_the_norme.c @@ -6,7 +6,7 @@ /* By: dkaiser next; - free_token_and_connect(*cur); + free_token_and_connect2(*cur); if (next_token) { if (next_token->previous == NULL) *tokens = next_token->next; *cur = next_token->next; - free_token_and_connect(next_token); + free_token_and_connect2(next_token); } else *cur = NULL; -- 2.47.2