blob: e0e1132284685e6f58951ca1020e275725382b49 (
plain)
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
|
#include "lexer.h"
int lexer_count_len_element(char *input, int i)
{
int j = -1;
if (input[i] == '"' || input[i] == '\'')
{
return(j = lexer_verif_entre_cote(input,i));
}
else if (lexer_sep(input[i]) || input[i] == ' ')
{
while(lexer_sep(input[i]) || input[i] == ' ')
{
if(input[j] == '\0')
return(j);
++i;
++j;
}
}
else
{
while (!lexer_sep(input[i]) && input[i] != ' ')
{
if(input[j] == '\0')
return(j);
++i;
++j;
}
}
++j;
return(j);
}
char **lexer_malloc_len_elem(char *input, int i, char **out)
{
int j = 0;
int k = 0;
int temp = 0;
(void)i;
j += lexer_count_len_element(&input[j], 0);
k = j;
out[temp] = malloc(sizeof(char) * k);
ft_strlcpy(out[temp], input, k + 1);
while (input[j] != '\0')
{
temp++;
j += lexer_count_len_element(&input[j], 0);
k -= j;
if (k < 0)
k *= -1;
out[temp] = malloc(sizeof(char) * j - k + 1);
ft_strlcpy(out[temp], &input[j - k], k + 1);
k = j;
}
return(out);
}
|