forked from muratkaanmesum/minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_utils.c
67 lines (60 loc) · 1.66 KB
/
main_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmesum <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/21 15:09:51 by mmesum #+# #+# */
/* Updated: 2023/03/29 14:57:35 by mmesum ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void free_all_node_tokens(t_node *node)
{
int i;
i = 0;
if (node->connection_count == 0)
free_tokens(node->tokens);
else
{
while (i < node->connection_count)
{
free_all_node_tokens(node->connections[i]);
i++;
}
free_tokens(node->tokens);
}
}
int parse_error_free(t_node *head, t_token *tokens, char *inpt)
{
if (head == NULL)
{
free(inpt);
free_tokens(tokens);
return (1);
}
return (0);
}
int first_check_free(t_token *tokens, char *inpt)
{
int temp_out;
temp_out = dup(1);
dup2(2, 1);
if (check_first(tokens) == 1)
{
free(inpt);
free_tokens(tokens);
close(temp_out);
return (1);
}
dup2(temp_out, 1);
close(temp_out);
return (0);
}
void exec_rest(t_node *head)
{
execute(head);
free(head->execute->input);
free_tree(head);
}