-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_parse_token.c
67 lines (62 loc) · 1.81 KB
/
utils_parse_token.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_parse_token.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dselmy <dselmy@student.21-school.ru> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/01 16:39:46 by dselmy #+# #+# */
/* Updated: 2022/02/02 20:27:07 by dselmy ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/parser.h"
int get_arg_len(int quoted_flag, char *token)
{
char *ptr;
int i;
ptr = token;
i = 0;
while (*ptr)
{
if ((*ptr == '"' && quoted_flag == DOUBLE_QUOTE) || \
(*ptr == '\'' && quoted_flag == SINGLE_QUOTE))
break ;
if (((*ptr == ' ' || is_redirect(*ptr)) && !quoted_flag) || \
(*ptr == '$' && quoted_flag != SINGLE_QUOTE))
break ;
i += 1;
ptr += 1;
}
return (i);
}
void make_new_cmd_arg(int *i, int *cmd_i, t_token *cur_token, t_data *all)
{
*cmd_i += 1;
cur_token->cmd = ft_realloc_charmtrx(cur_token->cmd, *cmd_i + 1);
if (!cur_token->cmd)
error_exit(all);
skip_whitespaces(i, cur_token->token);
}
int get_type_of_redirect(char *line, int *i)
{
if (line[*i] == '>')
{
*i += 1;
if (line[*i] == '>')
{
*i += 1;
return (DOUBLE_OUT);
}
return (SIMPLE_OUT);
}
else
{
*i += 1;
if (line[*i] == '<')
{
*i += 1;
return (DOUBLE_IN);
}
return (SIMPLE_IN);
}
}