Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/lexer/ft_add_word.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_add_word.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: ssabbaji <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/07/26 18:16:44 by yabtaour #+# #+# */
9
/* Updated: 2022/09/19 16:29:41 by ssabbaji ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../minishell.h"
14
15
int ft_word_len(char *cmd, int i)
16
{
17
int len;
18
char c;
19
20
len = 0;
21
while (cmd[i] && ft_is_word(cmd[i]))
22
{
23
if (cmd[i] == '"' || cmd[i] == '\'')
24
{
25
c = cmd[i];
26
i++;
27
len++;
28
while (cmd[i] && cmd[i] != c)
29
{
30
i++;
31
len++;
32
}
33
}
34
len++;
35
i++;
36
}
37
return (len);
38
}
39
40
int ft_add_word(t_data *data, int i)
41
{
42
char *command;
43
44
command = ft_substr(data->cmd, i, ft_word_len(data->cmd, i));
45
i += ft_word_len(data->cmd, i);
46
data->lst_lexer = ft_add_lexer_back(data->lst_lexer, command, WORD);
47
free(command);
48
return (i);
49
}
50
51