forked from kyomawolf/minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
free.c
119 lines (109 loc) · 2.44 KB
/
free.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mstrantz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/08 16:45:35 by jkasper #+# #+# */
/* Updated: 2021/12/30 00:26:34 by mstrantz ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "minis.h"
#include "struct.h"
#include <stdio.h>
void free_char_array(char ***arr)
{
int i;
i = 0;
if (*arr == NULL)
return ;
while (arr[0][i] != NULL)
{
free(arr[0][i]);
arr[0][i] = NULL;
i++;
}
free(*arr);
*arr = NULL;
}
void free_t_node_content_list(t_node *head)
{
t_node *temp;
temp = NULL;
while (head != NULL)
{
if (head->content != NULL)
{
free(head->content);
head->content = NULL;
}
temp = head;
head = head->next;
free(temp);
temp = NULL;
}
}
void free_token(t_token *token)
{
void *temp;
temp = NULL;
if (token->string != NULL)
free(token->string);
token->string = NULL;
while (token->heredoc != NULL)
{
if (token->heredoc->content != NULL)
free (token->heredoc->content);
token->heredoc->content = NULL;
temp = token->heredoc;
token->heredoc = token->heredoc->next;
free (temp);
temp = NULL;
}
free(token);
token = NULL;
}
void free_t_node_list(t_node *head)
{
t_token *token;
t_node *temp;
temp = NULL;
token = NULL;
while (head != NULL)
{
token = (t_token *)head->content;
if (token != NULL)
{
free_token(token);
token = NULL;
}
temp = head;
head = head->next;
free(temp);
temp = NULL;
}
}
void free_main(t_data *data)
{
if (data->input != NULL)
{
free(data->input);
data->input = NULL;
}
if (data->prompt != NULL)
{
free(data->prompt);
data->prompt = NULL;
}
if (data->currdir != NULL)
{
free(data->currdir);
data->currdir = NULL;
}
free_t_node_content_list(data->envp);
free_t_node_content_list(data->expo);
free(data);
data = NULL;
}