forked from muratkaanmesum/minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
82 lines (72 loc) · 1.84 KB
/
utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmesum <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/14 17:19:55 by mmesum #+# #+# */
/* Updated: 2023/03/23 13:28:26 by mmesum ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void free_tokens(t_token *token)
{
int i;
i = 0;
while (token[i].token != UNKNOWN)
{
if (token[i].str != NULL)
{
free(token[i].str);
token[i].str = NULL;
}
i++;
}
if (token != NULL)
free(token);
}
void free_double_ptr(char **arr)
{
int i;
i = 0;
while (arr[i] != NULL)
{
free(arr[i]);
i++;
}
free(arr);
}
int get_double_ptr_len(char **arr)
{
int i;
i = 0;
while (arr[i] != NULL)
i++;
return (i);
}
void free_execute(t_execute *execute)
{
int i;
i = 0;
while (execute->env[i] != NULL)
free(execute->env[i++]);
free(execute->env);
i = 0;
while (execute->export[i] != NULL)
free(execute->export[i++]);
free(execute->export);
free(execute->input);
free(execute);
}
void copy_token(t_token *dest, t_token src)
{
dest->token = src.token;
dest->id = src.id;
dest->start_index = src.start_index;
dest->end_index = src.end_index;
if (src.str != NULL)
dest->str = ft_strdup(src.str);
else
dest->str = NULL;
}