-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare_nodes_1.c
More file actions
123 lines (112 loc) · 2.76 KB
/
prepare_nodes_1.c
File metadata and controls
123 lines (112 loc) · 2.76 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
116
117
118
119
120
121
122
123
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* prepare_nodes_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jklocker <jklocker@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/30 14:12:16 by jklocker #+# #+# */
/* Updated: 2023/01/30 14:12:16 by jklocker ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void create_redircets(t_info *info)
{
int i;
t_node *cur;
cur = info->head;
i = -1;
while (info->cmd_input[++i])
{
if (info->cmd_input[i][0] == '|')
cur = cur->next;
if (info->cmd_input[i][0] == '>')
create_fd_out(info, &i, cur);
if (info->cmd_input[i][0] == '<' && info->cmd_input[i][1] == '\0')
create_fd_in(info, &i, cur);
if (info->cmd_input[i][0] == '<' && info->cmd_input[i][1] == '<')
heredoc(info, &i, cur);
}
}
//Test function
void init_nodes(t_info *info)
{
t_node *tmp;
tmp = info->head;
while (tmp)
{
tmp->full_path = NULL;
tmp->heredoc = NULL;
tmp->in = 0;
tmp->out = 1;
tmp = tmp->next;
}
}
void create_full_cmd(t_info *info)
{
int i;
int j;
t_node *tmp;
tmp = info->head;
i = 0;
j = 0;
while (info->cmd_input[i])
{
if (info->cmd_input[i][0] == '|')
{
tmp = tmp->next;
i++;
j = 0;
continue ;
}
else if (info->cmd_input[i][0] == '<' || info->cmd_input[i][0] == '>')
{
i = i + 2;
continue ;
}
tmp->full_cmd[j] = info->cmd_input[i];
j++;
i++;
}
}
void malloc_2d_nodes(t_info *info)
{
int i;
int words;
t_node *cur;
cur = info->head;
i = 0;
while (info->cmd_input[i])
{
words = get_words_for_node(info->cmd_input, i);
cur->full_cmd = malloc((words + 1) * sizeof(char *));
if (!cur->full_cmd)
call_perror_free(info);
cur->full_cmd[words] = NULL;
while (info->cmd_input[i] && info->cmd_input[i][0] != '|')
i++;
cur = cur->next;
if (info->cmd_input[i])
i++;
}
}
int check_valid_redirects(t_info *info)
{
int i;
i = 0;
while (info->cmd_input[i])
{
if (info->cmd_input[i][0] == '<' || info->cmd_input[i][0] == '>')
{
if (!info->cmd_input[i + 1] || info->cmd_input[i + 1][0] == '<'
|| info->cmd_input[i + 1][0] == '>' || info->cmd_input[i
+ 1][0] == '|')
{
ft_printf("zsh: parse error near `\\n'\n");
return (0);
}
}
i++;
}
return (1);
}