Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/syntax/ft_pipe.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_pipe.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: ssabbaji <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/07/26 18:17:23 by yabtaour #+# #+# */
9
/* Updated: 2022/09/23 17:20:16 by ssabbaji ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../minishell.h"
14
15
int ft_check_num(t_data *data, t_lexer *lexer_clone, int num)
16
{
17
(void)data;
18
if (lexer_clone && lexer_clone->type == PIPE && num == 0)
19
{
20
printf("Syntax error near unexpected token `|'\n");
21
g_vars.g_exit_stat = 258;
22
}
23
return (0);
24
}
25
26
int ft_check_between_pipes(t_data *data)
27
{
28
t_lexer *lexer_clone;
29
int num;
30
31
lexer_clone = data->lst_lexer;
32
while (lexer_clone)
33
{
34
num = 0;
35
if (lexer_clone->type == PIPE)
36
{
37
lexer_clone = lexer_clone->next;
38
while (lexer_clone && lexer_clone->type != PIPE)
39
{
40
num++;
41
lexer_clone = lexer_clone->next;
42
}
43
if (!lexer_clone)
44
break ;
45
if (ft_check_num(data, lexer_clone, num))
46
break ;
47
}
48
if (lexer_clone->type != PIPE)
49
lexer_clone = lexer_clone->next;
50
}
51
return (g_vars.g_exit_stat);
52
}
53
54