-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.c
executable file
·79 lines (71 loc) · 1.28 KB
/
error.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
#include "minibash.h"
void lite_error(char *comment)
{
printf("\n%s\n", comment);
exit(EXIT_FAILURE);
}
static void free_hist_env(t_shell **shell)
{
t_history *tmph;
t_env *tmpe;
while ((*shell)->history)
{
tmph = (*shell)->history;
(*shell)->history = (*shell)->history->next;
if (tmph->command)
free(tmph->command);
if (tmph->cache)
free(tmph->cache);
free(tmph);
}
while ((*shell)->env)
{
tmpe = (*shell)->env;
(*shell)->env = (*shell)->env->next;
if (tmpe->key)
free(tmpe->key);
if (tmpe->value)
free(tmpe->value);
free(tmpe);
}
}
static void free_redirect(t_redir_chain **redir)
{
t_redir_chain *tmp;
while (*redir)
{
tmp = *redir;
*redir = (*redir)->next;
if (tmp->path)
free(tmp->path);
free(tmp);
}
}
void free_seq(t_seq **seq)
{
t_seq *tmp;
while (*seq)
{
tmp = *seq;
*seq = (*seq)->next;
if (tmp->run)
free(tmp->run);
if (tmp->args)
ft_twodarr_free(&tmp->args, ft_twodarr_len(tmp->args));
if (tmp->redirect)
free_redirect(&tmp->redirect);
if (tmp->pipe)
free_seq(&tmp->pipe);
free(tmp);
}
}
void free_error(char *comment, t_shell **shell)
{
if ((*shell)->history || (*shell)->env)
free_hist_env(shell);
if ((*shell)->seq)
free_seq(&(*shell)->seq);
free(*shell);
if (comment)
lite_error(comment);
}