-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_for_test.c
93 lines (84 loc) · 2.23 KB
/
main_for_test.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
89
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main_for_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hyerkim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/09 19:49:02 by hokim #+# #+# */
/* Updated: 2021/05/23 17:07:21 by hyerkim ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_sig g_sig;
void shell_init(t_datas *datas, char **envv)
{
datas->env_list = array_to_list(envv, 0);
datas->export_list = array_to_list(envv, 1);
ft_rm_env(datas, "OLDPWD");
ft_export_env(datas, NULL, "OLDPWD");
datas->envv = envv;
datas->fd.read = 0;
datas->fd.write = 1;
datas->status = 0;
}
void new_init(char *buf, int *i)
{
buf[0] = '\0';
*i = 0;
signal(SIGINT, sig_ft);
signal(SIGQUIT, sig_ft);
}
void make_blocks(char *buf, t_datas *datas)
{
int i;
char **blocks;
blocks = ft_split(buf, ';');
i = -1;
while (blocks[++i])
{
if (g_sig.is_exit == 1)
break ;
pipe_process(blocks[i], datas);
}
free_str_array(blocks);
}
void read_char(char *buf, char c, int *i)
{
if (g_sig.sig == 'c')
{
g_sig.sig = 0;
*i = 0;
buf[0] = '\0';
exit(0);
}
buf[(*i)++] = c;
buf[*i] = '\0';
}
int main(int argc, char **argv, char **envv)
{
char buf[4096];
t_datas datas;
char c;
int i;
shell_init(&datas, envv);
new_init(buf, &i);
while (argc && argv[0] && read(0, &c, 1) > 0)
{
if (c != '\n')
{
read_char(buf, c, &i);
continue;
}
if (buf[0] == '\0' || buf[0] == '\n')
{
new_init(buf, &i);
continue;
}
if (buf[0] != '\0' && buf[0] != '\n')
if (syntax_error_check(datas.ori_fd.err, buf, &(datas.status)))
make_blocks(buf, &datas);
new_init(buf, &i);
}
return (datas.status);
}