-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_parsecommands.c
More file actions
50 lines (46 loc) · 1.72 KB
/
ft_parsecommands.c
File metadata and controls
50 lines (46 loc) · 1.72 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_parsecommands.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: makbulut <makbulut@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/02 13:03:24 by makbulut #+# #+# */
/* Updated: 2022/09/05 13:55:52 by makbulut ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "42-Libft/libft.h"
static void *erroroccured(t_command **commands, t_token *token)
{
ft_freearr_command(commands);
if (token)
ft_syntaxerror(token);
return (NULL);
}
t_command **ft_parsecommands(t_token **tokens, int start, int end)
{
t_command *cmd;
t_command **commands;
int i;
commands = NULL;
i = start;
while (i < end)
{
if (tokens[start]->type == LPAR)
i = ft_skipbrackets(tokens, start, end);
if (i == -1)
return (erroroccured(commands, NULL));
while (i < end && tokens[i] && tokens[i]->type != PIPE)
i++;
cmd = ft_parsecommand(tokens, start, i);
if (!cmd)
return (erroroccured(commands, NULL));
ft_addarr_command(&commands, cmd);
if (tokens[i] && tokens[i]->type == PIPE)
if (!tokens[++i])
return (erroroccured(commands, tokens[i - 1]));
start = i;
}
return (commands);
}