-
Notifications
You must be signed in to change notification settings - Fork 0
/
quotes1.c
94 lines (87 loc) · 1.8 KB
/
quotes1.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* quotes1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/03 19:01:11 by zwalad #+# #+# */
/* Updated: 2022/08/24 19:36:19 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int single_inqts(char *line)
{
int i;
int d;
i = 0;
d = 0;
while (line[i])
{
if (line[i] == '"')
{
i++;
while (line[i] != '"' && line[i])
{
if (line[i] == '\'')
d++;
i++;
}
if (line[i] == '\0')
d = 0;
}
if (line[i])
i++;
}
return (d);
}
int double_inqts(char *line)
{
int i;
int d;
i = 0;
d = 0;
while (line[i])
{
if (line[i] == '\'')
{
i++;
while (line[i] != '\'' && line[i])
{
if (line[i] == '"')
d++;
i++;
}
if (line[i] == '\0')
d = 0;
}
if (line[i])
i++;
}
return (d);
}
t_list *qts_check(t_list *p)
{
int i;
int s;
int d;
s = 0;
d = 0;
i = 0;
while (p->line[i])
{
if (p->line[i] == '\'')
s++;
if (p->line[i] == '"')
d++;
i++;
}
d -= double_inqts(p->line);
s -= single_inqts(p->line);
if (d % 2 || s % 2)
{
ft_err("Minishell :", " unclosed", " quotes\n", 1);
p->error = 1;
}
return (p);
}