-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroutine_v11.c
More file actions
93 lines (87 loc) · 2.58 KB
/
routine_v11.c
File metadata and controls
93 lines (87 loc) · 2.58 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* routine_v11.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bguzel <bguzel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/09 20:26:22 by bguzel #+# #+# */
/* Updated: 2023/09/10 15:07:44 by bguzel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void fd_error(int fd, char *str)
{
if (fd == -1)
{
printf("minishell: %s: No such file or directory\n", str);
g_var.exit_code = 1;
}
else
{
printf("minishell: syntax error near unexpected token `%s'\n", str);
g_var.exit_code = 258;
}
}
void no_such(char *str)
{
printf("minishell: %s: No such file or directory\n", str);
g_var.exit_code = 127;
}
int rdr_init_help(t_list *tmp, int *k, int fd)
{
if (tmp->flag == 'r')
{
fd = open(tmp->content, O_CREAT | O_APPEND | O_RDWR, 0777);
g_var.cmds[*k]->f_out = fd;
}
if (tmp->flag == 'h')
ft_here_doc(tmp->content, *k);
if (tmp->flag == '|')
*k += 1;
if (fd == -1)
{
g_var.cmds[*k]->f_out = -1;
fd_error(fd, tmp->content);
return (1);
}
return (0);
}
int rdr_pipe_ctrl(t_list *tmp)
{
if (tmp->content[0] == '<' && tmp->content[1] == '\0'
&& tmp->next->content[0] == '>' && tmp->next->content[1] == '\0')
{
tmp = tmp->next;
if (tmp->next != NULL)
{
if (tmp->next->flag == '<' || tmp->next->flag == '>')
return (rdr_pipe_return_v2(tmp->next->content));
}
else
return (rdr_pipe_return());
}
if (tmp->content[0] == '<' || tmp->content[1] == '<')
if (tmp->next != NULL)
if (tmp->next->flag == '<' || tmp->next->flag == '>')
return (rdr_pipe_return_v2(tmp->next->content));
if (rdr_pipe_ctrl_v2(tmp))
return (1);
return (0);
}
int rdr_pipe_ctrl_v2(t_list *tmp)
{
if (tmp->content[0] == '>' && tmp->content[1] == '\0'
&& tmp->next->content[0] == '<' && tmp->next->content[1] == '\0')
{
tmp = tmp->next;
if (tmp->next != NULL)
{
if (tmp->next->flag == '<' || tmp->next->flag == '>')
return (rdr_pipe_return_v2(tmp->next->content));
else
return (rdr_pipe_return());
}
}
return (0);
}