Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/parsing/parsing.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* parsing.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: ssabbaji <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/07/26 18:17:19 by yabtaour #+# #+# */
9
/* Updated: 2022/10/03 14:28:28 by ssabbaji ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../minishell.h"
14
15
int ft_check_still_redirection(t_data *data)
16
{
17
t_lexer *lexer_clone;
18
19
lexer_clone = data->lst_lexer;
20
while (lexer_clone && lexer_clone->type != PIPE)
21
{
22
if (lexer_clone->type == REDIRECTION
23
&& ft_strcmp(lexer_clone->val, "<<"))
24
return (1);
25
lexer_clone = lexer_clone->next;
26
}
27
return (0);
28
}
29
30
void ft_add_normal_command(t_data *data, char *new, int *fd, int *red)
31
{
32
int red_num;
33
t_lexer *lexer_clone;
34
int i;
35
36
i = 0;
37
red_num = ft_red_num(data);
38
red = ft_fill_red(data, red_num);
39
fd = malloc (sizeof(int) * red_num);
40
if (!fd)
41
exit (1);
42
lexer_clone = data->lst_lexer;
43
while (lexer_clone && lexer_clone->type != PIPE)
44
{
45
if (lexer_clone->type == REDIRECTION
46
&& ft_strcmp(lexer_clone->val, "<<"))
47
{
48
lexer_clone = lexer_clone->next;
49
new = ft_new(lexer_clone->val);
50
fd[i] = ft_fill_fd(data, new, red[i]);
51
free(new);
52
i++;
53
}
54
lexer_clone = lexer_clone->next;
55
}
56
data->lst_cmd = ft_add_back_cmd(data, fd, red, red_num);
57
}
58
59
int ft_check_still_pipe(t_data *data)
60
{
61
t_lexer *lexer_clone;
62
63
lexer_clone = data->lst_lexer;
64
while (lexer_clone)
65
{
66
if ((lexer_clone) || lexer_clone->type == PIPE)
67
return (1);
68
lexer_clone = lexer_clone->next;
69
}
70
return (0);
71
}
72
73
void ft_parsing(t_data *data)
74
{
75
t_lexer *lexer_clone;
76
77
lexer_clone = data->lst_lexer;
78
ft_change_exit_status(data);
79
ft_handle_herdoc(data, lexer_clone, 0);
80
ft_add_command_pipe(data);
81
ft_delete_quotes(data);
82
}
83
84