Compare commits
4 Commits
97d8a6838f
...
63dd69b01c
| Author | SHA1 | Date | |
|---|---|---|---|
| 63dd69b01c | |||
| 609a644fa9 | |||
| 3d97d6506a | |||
| 1f0f38e42f |
@@ -6,7 +6,7 @@
|
|||||||
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/02/09 18:56:41 by sede-san #+# #+# */
|
/* Created: 2026/02/09 18:56:41 by sede-san #+# #+# */
|
||||||
/* Updated: 2026/02/10 08:40:13 by sede-san ### ########.fr */
|
/* Updated: 2026/02/10 09:11:23 by sede-san ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
static t_token *tokenize(const char *line, size_t *start);
|
static t_token *tokenize(const char *line, size_t *start);
|
||||||
static t_token_type get_token_type(const char *str);
|
static t_token_type get_token_type(const char *str);
|
||||||
static t_token *token_new(t_token_type type, const char *text);
|
static t_token *token_new(t_token_type type, char *text);
|
||||||
static void token_clear(t_token *token);
|
static void token_clear(t_token *token);
|
||||||
static t_token *read_token(t_token_type type, const char *line, size_t *i);
|
static t_token *read_token(t_token_type type, const char *line, size_t *i);
|
||||||
static t_token *read_word(const char *line, size_t *i);
|
static t_token *read_word(const char *line, size_t *i);
|
||||||
@@ -97,14 +97,13 @@ static t_token_type get_token_type(
|
|||||||
|
|
||||||
static t_token *token_new(
|
static t_token *token_new(
|
||||||
t_token_type type,
|
t_token_type type,
|
||||||
const char *text)
|
char *text)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (t_token *)malloc(sizeof(t_token));
|
token = (t_token *)malloc(sizeof(t_token));
|
||||||
if (token == NULL)
|
if (token == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
ft_putendl("malloc");
|
|
||||||
token->type = type;
|
token->type = type;
|
||||||
token->value = text;
|
token->value = text;
|
||||||
if (token->type == TOKEN_WORD && token->value == NULL)
|
if (token->type == TOKEN_WORD && token->value == NULL)
|
||||||
@@ -120,13 +119,8 @@ static void token_clear(
|
|||||||
{
|
{
|
||||||
if (token != NULL)
|
if (token != NULL)
|
||||||
{
|
{
|
||||||
if (token->value != NULL)
|
free(token->value);
|
||||||
{
|
|
||||||
free(token->value);
|
|
||||||
ft_putendl("free");
|
|
||||||
}
|
|
||||||
free(token);
|
free(token);
|
||||||
ft_putendl("free");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,9 +129,15 @@ static t_token *read_token(
|
|||||||
const char *line,
|
const char *line,
|
||||||
size_t *i)
|
size_t *i)
|
||||||
{
|
{
|
||||||
while (ft_isspace(line[*i]) || is_meta(line[*i]))
|
const size_t start = *i;
|
||||||
|
size_t end;
|
||||||
|
|
||||||
|
while (is_meta(line[*i]))
|
||||||
(*i)++;
|
(*i)++;
|
||||||
return (token_new(type, NULL));
|
end = *i;
|
||||||
|
while (ft_isspace(line[*i]))
|
||||||
|
(*i)++;
|
||||||
|
return (token_new(type, ft_substr(line, start, end - start)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static t_token *read_word(
|
static t_token *read_word(
|
||||||
|
|||||||
Reference in New Issue
Block a user