aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Kaiser2025-01-22 17:34:07 +0100
committerDominik Kaiser2025-01-22 17:34:07 +0100
commitd6b4b8116084f7aec25c101a82fc457ac9989033 (patch)
tree5d3d64f0a97d91da642086976d793b6dc47b94a9
parente745796ffea1580b7d9263305ee57233536b3365 (diff)
downloadminishell-d6b4b8116084f7aec25c101a82fc457ac9989033.tar.gz
minishell-d6b4b8116084f7aec25c101a82fc457ac9989033.zip
Test test test
-rw-r--r--include/token.h4
-rw-r--r--src/free_token.c31
-rw-r--r--src/parse_cmd.c2
-rw-r--r--src/parser.c4
-rw-r--r--src/praise_the_norme.c6
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 <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/20 18:35:41 by dkaiser #+# #+# */
-/* Updated: 2025/01/20 18:39:31 by dkaiser ### ########.fr */
+/* Updated: 2025/01/22 17:30:02 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,13 +17,13 @@ void i_love_the_norme(t_token **cur, t_token **tokens)
t_token *next_token;
next_token = (*cur)->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;