-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtokenization.c
57 lines (53 loc) · 1.77 KB
/
tokenization.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tokenization.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: csweetin <csweetin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/25 15:19:47 by csweetin #+# #+# */
/* Updated: 2024/03/29 17:26:34 by csweetin ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
static int exec_toke(t_input **input, t_env **env, char *line, size_t *i)
{
while (line[*i] && ((line[*i] >= '\t' && line[*i] <= '\r')
|| line[*i] == ' '))
*i += 1;
if (line[*i] && line[*i] == '<')
return (tok_inredir(input, env, line, i));
else if (line[*i] && line[*i] == '>')
return (tok_outredir(input, env, line, i));
else if (line[*i] && line[*i] == '|')
return (tok_pipe(input, env, line, i));
else if (line[*i])
return (tok_command(input, env, line, i));
return (0);
}
int tokenization(t_input **input, t_env **env, char *line, int *status)
{
size_t i;
int rv;
i = 0;
rv = 0;
if (check_quote(line))
{
print_error(0, "minishell : syntax error missing quote");
*status = 2;
return (1);
}
while (line[i])
{
rv = exec_toke(input, env, line, &i);
if (rv != 0)
{
if (rv == 2)
*status = 2;
else
*status = 1;
return (1);
}
}
return (0);
}