blob: a63e750f54622ccc4fbd16a8de29747bb99037a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free_token.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 14:38:57 by dkaiser #+# #+# */
/* Updated: 2025/01/25 11:36:59 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "token.h"
#include "debug_tools.h"
void free_token(t_token *token)
{
if (token->previous != NULL)
token->previous->next = NULL;
if (token->next != NULL)
token->next->previous = NULL;
free(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);
free(token);
token = NULL;
}
void free_token_and_connect(t_token *token)
{
if (token->previous != NULL)
token->previous->next = token->next;
if (token->next != NULL)
token->next->previous = token->previous;
free(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);
free(token);
token = NULL;
}
void free_tokens(t_token *tokens)
{
while (tokens->next != NULL)
{
tokens = tokens->next;
free_token2(tokens->previous);
}
free_token2(tokens);
}
|