-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec4.c
88 lines (80 loc) · 2.08 KB
/
exec4.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec4.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adel-cor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/05 12:31:24 by adel-cor #+# #+# */
/* Updated: 2022/04/12 10:25:13 by adel-cor ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_job *ms_head_list_job(t_job *job)
{
while (job)
{
if (!job->previous)
return (job);
job = job->previous;
}
return (job);
}
struct s_tnode *ms_head_list(struct s_tnode *token)
{
while (token)
{
if (!token->prev)
return (token);
token = token->prev;
}
return (token);
}
t_job *ms_job_last(t_job *job)
{
while (job)
{
if (job->next == NULL)
return (job);
job = job->next;
}
return (job);
}
int redir_counter(struct s_tnode *tok)
{
int i;
i = 0;
while (tok && tok->next)
{
if (tok->type == PIPE)
tok = tok->next;
if (tok->type == STRING)
tok = tok->next;
if (is_redirection(tok))
i++;
tok = tok->next;
}
return (i);
}
t_job *redirection_to_tab(struct s_tnode *token, t_job *job)
{
int counter;
int i;
if (!job->file)
{
counter = redir_counter(token);
job->file = ft_calloc((counter * 2) + 1, sizeof(char *));
}
i = 0;
while (job->file[i])
i++;
job->file[i] = ft_calloc(ft_strlen(token->str) + 1, sizeof(char));
ft_strcpy(job->file[i], token->str);
i++;
if (!token->next)
return (job);
token = token->next;
job->file[i] = ft_calloc(ft_strlen(token->str) + 1, sizeof(char));
ft_strcpy(job->file[i], token->str);
return (job);
}