-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck.c
More file actions
108 lines (100 loc) · 2.55 KB
/
check.c
File metadata and controls
108 lines (100 loc) · 2.55 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bguzel <bguzel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/09 15:43:59 by bguzel #+# #+# */
/* Updated: 2023/09/09 21:14:14 by bguzel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int check_quote(char *str)
{
int i;
char c;
int flag;
flag = 0;
i = 0;
while (str[i])
{
if (str[i] == '"' || str[i] == 39)
{
c = str[i++];
flag = 1;
while (str[i] && str[i] != c)
i++;
if (flag == 1 && str[i] != c)
{
printf("minishell: syntax error token `%c'\n", c);
g_var.exit_code = 258;
return (1);
}
}
i++;
}
return (0);
}
int rdr_pipe_check(void)
{
t_list *tmp;
tmp = g_var.list;
if (!tmp)
return (1);
if (tmp->flag == '<' || tmp->flag == '>')
if (tmp->next == NULL)
return (rdr_pipe_return());
if (tmp->content[0] == '<' || tmp->content[0] == '>')
if (tmp->next != NULL)
if (tmp->next->content[0] == '|')
return (rdr_pipe_return_v2("|"));
if (tmp->content[0] == '<' && tmp->content[1] == '<')
if (tmp->next == NULL)
return (rdr_pipe_return());
if (tmp->content[0] == '>' && tmp->content[1] == '>')
if (tmp->next == NULL)
return (rdr_pipe_return());
if (rdr_pipe_ctrl(tmp) != 0)
return (1);
return (0);
}
int rdr_pipe_check_v3(void)
{
t_list *tmp;
tmp = g_var.list;
if (tmp)
if (tmp->flag == '|')
return (rdr_pipe_return_v2("|"));
while (tmp)
{
if (tmp->flag == '<')
{
if (tmp->next != NULL)
{
if (tmp->next->flag == '>' || tmp->next->flag == '<')
return (rdr_pipe_return_v2("<"));
}
else
return (rdr_pipe_return());
}
if (rdr_pipe_check_v4(tmp) != 0)
return (1);
tmp = tmp->next;
}
return (0);
}
int rdr_pipe_check_v4(t_list *tmp)
{
if (tmp->flag == '>')
{
if (tmp->next != NULL)
{
if (tmp->next->flag == '<' || tmp->next->flag == '>')
return (rdr_pipe_return_v2(">"));
}
else
return (rdr_pipe_return());
}
return (0);
}