-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtoken_utils3.c
56 lines (51 loc) · 1.71 KB
/
token_utils3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* token_utils3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmachado <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/26 16:15:59 by bmachado #+# #+# */
/* Updated: 2022/02/23 11:25:33 by bmachado ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void pass_to_token(char *input, int i, t_token **token_lst)
{
int start;
int type;
char *tmp;
if (i < 0)
return ;
start = i;
if (input[i] == '$' && define_type(input[i + 1]) != QUOTES)
{
add_token(token_lst, create_token(ft_strdup("$"), CHAR));
return ;
}
if (!not_var_name(input, i))
return ;
while (start > 0)
{
type = define_type(input[start]);
if (type != define_type(input[start - 1]))
break ;
start--;
}
tmp = ft_substr(input, start, i - start + 1);
add_token(token_lst, create_token(tmp, define_type(input[start])));
}
void var_to_token(char *input, int i, t_token **token_lst)
{
int end;
char *tmp;
end = i + 1;
while (input[end])
{
if (define_type(input[end]) != CHAR)
break ;
end++;
}
tmp = ft_substr(input, i, end - i);
add_token(token_lst, create_token(tmp, DOLLAR));
}