-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils9.c
116 lines (105 loc) · 2.81 KB
/
utils9.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils9.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fayan <42istanbul.com.tr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/01 17:24:36 by dayan #+# #+# */
/* Updated: 2022/12/01 17:24:38 by dayan ### ########.tr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int redir_sep_helper_2(int line)
{
int i;
char **tmp;
i = 0;
while (g_data.redirsep[line][++i])
{
tmp = manuelsplit(g_data.redirsep[line][i]);
if (!tmp[1])
{
print_error("|ragoroliptik|: syntax error", 0);
free_ezhel(tmp);
return (0);
}
free_ezhel(tmp);
}
return (1);
}
int redir_sep_helper(int line)
{
char **tmp;
if (g_data.redirsep[line][0][0] == '>'
|| g_data.redirsep[line][0][0] == '<')
{
tmp = manuelsplit(g_data.redirsep[line][0]);
if (!tmp[1])
{
free_ezhel(tmp);
print_error("|ragoroliptik|: syntax error", 0);
return (0);
}
free_ezhel(tmp);
}
if (!redir_sep_helper_2(line))
return (0);
return (1);
}
void tripleredir(void)
{
int line;
int redir;
line = -1;
while (g_data.args[++line])
{
redir = 0;
while (g_data.args[line][++redir]
&& !ft_strcmp(g_data.args[line][redir][0], "<<<"))
{
pipe(g_data.pipes[line]);
ft_putendl_fd(g_data.args[line][redir][1], g_data.pipes[line][1]);
close(g_data.pipes[line][1]);
}
}
}
void fix_redirection_helper(int line, int redir, int idx, char *holder)
{
char *tmp;
tmp = ft_strdup(g_data.redirsep[line][redir]);
free(g_data.redirsep[line][redir]);
g_data.redirsep[line][redir] = ft_substr(tmp, 0, idx);
free(tmp);
tmp = ft_strjoin(g_data.redirsep[line][redir], " ");
free(g_data.redirsep[line][redir]);
g_data.redirsep[line][redir] = ft_strjoin(tmp, holder);
free(tmp);
}
void ft_exit(int line)
{
int status;
if (!g_data.args[line][0][1])
{
free_data();
free_ezhel(g_data.env);
exit(0);
}
else if (!is_numeric(g_data.args[line][0][1]))
{
print_error("|ragoroliptik|: exit: numeric argument required: ",
g_data.args[line][0][1]);
free_data();
free_ezhel(g_data.env);
exit(255);
}
else if (g_data.args[line][0][2])
print_error("|ragoroliptik|: exit: too many arguments", 0);
else
{
status = ft_atoi(g_data.args[line][0][1]);
free_data();
free_ezhel(g_data.env);
exit(status);
}
}