-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroutine_v3.c
More file actions
115 lines (104 loc) · 2.32 KB
/
routine_v3.c
File metadata and controls
115 lines (104 loc) · 2.32 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* routine_v3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bguzel <bguzel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/09 18:37:57 by bguzel #+# #+# */
/* Updated: 2023/09/09 18:39:33 by bguzel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void cmd_init_help(void)
{
t_list *tmp;
int i;
tmp = g_var.list;
i = 0;
pipe_init();
g_var.string_3 = malloc(sizeof(char **) * (g_var.pipe_count + 2));
while (tmp)
{
g_var.string_3[i] = malloc(sizeof(char *) * (arg_count() + 2));
get_arg(&i, &tmp);
i++;
}
g_var.string_3[i] = NULL;
}
void pipe_init(void)
{
t_list *tmp;
int len;
int i;
i = 0;
len = 0;
tmp = g_var.list;
while (tmp)
{
if (tmp->flag == '|')
len++;
tmp = tmp->next;
}
g_var.pipe_count = len;
g_var.pipe = malloc(sizeof(int *) * len);
while (i < len)
{
g_var.pipe[i] = malloc(sizeof(int) * 2);
pipe(g_var.pipe[i]);
i++;
}
g_var.pid = malloc(sizeof(pid_t) * (len + 1));
}
int arg_count(void)
{
t_list *tmp;
int len;
len = 0;
tmp = g_var.list;
while (tmp)
{
if (tmp->flag == 'b')
len++;
if (tmp->flag == '|')
break ;
tmp = tmp->next;
}
return (len);
}
void get_arg(int *k, t_list **tmp)
{
int i;
i = 0;
while (*tmp)
{
if ((*tmp)->flag == 'b')
{
g_var.string_3[*k][i] = ft_strdup((*tmp)->content);
i++;
}
if ((*tmp)->flag == '|')
break ;
(*tmp) = (*tmp)->next;
}
g_var.string_3[*k][i] = 0;
if ((*tmp))
if ((*tmp)->flag == '|')
(*tmp) = (*tmp)->next;
}
void input_to_place(void)
{
int i;
i = 0;
while (i < g_var.pipe_count)
{
g_var.cmds[i]->f_out = g_var.pipe[i][1];
i++;
}
i = 1;
while (i < (g_var.pipe_count + 1))
{
g_var.cmds[i]->f_in = g_var.pipe[i - 1][0];
i++;
}
}