Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/syntax/ft_quotes.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_quotes.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: ssabbaji <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/07/26 18:17:25 by yabtaour #+# #+# */
9
/* Updated: 2022/09/29 11:02:57 by ssabbaji ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../minishell.h"
14
15
int ft_check_which(int double_num, int single_num)
16
{
17
if (double_num % 2)
18
{
19
printf ("Syntax error near unexpected token `\"'\n");
20
return (258);
21
}
22
if (single_num % 2)
23
{
24
printf ("Syntax error near unexpected token `\''\n");
25
return (258);
26
}
27
return (0);
28
}
29
30
int ft_change_double(t_data *data, char c, int quote)
31
{
32
if (c == '"' && data->flag_s == 0)
33
{
34
quote++;
35
data->flag_d = ft_change_flag(data->flag_d);
36
}
37
return (quote);
38
}
39
40
int ft_change_single(t_data *data, char c, int quote)
41
{
42
if (c == '\'' && data->flag_d == 0)
43
{
44
quote++;
45
data->flag_s = ft_change_flag(data->flag_s);
46
}
47
return (quote);
48
}
49
50
int ft_check_the_quotes(t_data *data)
51
{
52
int do_num;
53
int si_num;
54
t_lexer *lexer_clone;
55
int i;
56
57
data->flag_d = 0;
58
data->flag_s = 0;
59
do_num = 0;
60
si_num = 0;
61
lexer_clone = data->lst_lexer;
62
while (lexer_clone)
63
{
64
if (lexer_clone->type == WORD)
65
{
66
i = 0;
67
while (lexer_clone->val[i])
68
{
69
do_num = ft_change_double(data, lexer_clone->val[i], do_num);
70
si_num = ft_change_single(data, lexer_clone->val[i], si_num);
71
i++;
72
}
73
}
74
lexer_clone = lexer_clone->next;
75
}
76
return (ft_check_which(do_num, si_num));
77
}
78
79
int ft_check_quotes(t_data *data)
80
{
81
int quotes_f;
82
83
quotes_f = ft_check_the_quotes(data);
84
return (quotes_f);
85
}
86
87