-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenizer_utils2.c
executable file
·97 lines (89 loc) · 2.24 KB
/
tokenizer_utils2.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tokenizer_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mazaroua <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/03 16:40:48 by mazaroua #+# #+# */
/* Updated: 2023/05/16 13:12:30 by mazaroua ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *is_wspace(t_token_list **tokens, char *line)
{
int i;
if (!line)
return (NULL);
i = 0;
while (ft_strchr(" \t\v\f\r", line[i]) && line[i])
i++;
addback(tokens, " ", SPACE);
return (line + i);
}
char *is_dollar_pipe(t_token_list **tokens, char *line)
{
if (!line)
return (NULL);
if (*line == '$')
{
if (*(line + 1) == '?')
{
addback(tokens, ft_itoa_free(g_var.exit_state), WORD);
return (line + 2);
}
if (*(line + 1) == '$')
{
addback(tokens, "$$", WORD);
return (line + 2);
}
addback(tokens, "$", DOLLAR);
line = afdollar(tokens, line + 1);
return (line);
}
else if (*line == '|')
{
addback(tokens, "|", PIPE);
return (line + 1);
}
return (0);
}
char *is_word(t_token_list **tokens, char *line)
{
int i;
char *word;
if (!line)
return (NULL);
i = 0;
while (!ft_strchr(" \t\v\f\r><|$\'\"", line[i]))
i++;
word = ft_strndup(line, i);
addback(tokens, word, WORD);
return (line + i);
}
char *afdollar(t_token_list **tokens, char *line)
{
int i;
int j;
char *afdollar;
if (!line)
return (NULL);
i = 0;
j = 0;
while (line[i])
{
if ((line[i] != 34) && (ft_isalnum(line[i]) || line[i] == '_'))
i++;
else
break ;
}
afdollar = (char *)ft_malloc(1, i + 1);
while (j < i)
{
afdollar[j] = line[j];
j++;
}
afdollar[j] = '\0';
addback(tokens, afdollar, AFDOLLAR);
return (line + i);
}