/* 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 */
/* */
/* ************************************************************************** */
char quote_check);
void print_token(t_token *token);
+void free_token2(t_token *token);
+void free_token_and_connect2(t_token *token);
#endif
/* 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 */
/* */
/* ************************************************************************** */
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)
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)
// {
/* 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 */
/* */
/* ************************************************************************** */
/* 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 */
/* */
/* ************************************************************************** */
*tokens = split->next;
if (result == split)
result = NULL;
- free_token(split);
+ free_token2(split);
split = NULL;
return (result);
}
/* 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 */
/* */
/* ************************************************************************** */
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;