|
|
@ -6,26 +6,18 @@ |
|
|
|
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* Created: 2022/05/02 13:44:57 by narnaud #+# #+# */ |
|
|
|
/* Updated: 2022/05/16 08:15:13 by narnaud ### ########.fr */ |
|
|
|
/* Updated: 2022/05/16 10:21:34 by mea ### ########.fr */ |
|
|
|
/* */ |
|
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
|
#include "minishell.h" |
|
|
|
|
|
|
|
static int check_state(t_lexer *lex, char **line); |
|
|
|
|
|
|
|
static int check_register(t_lexer *lex, char **line, char *tmp); |
|
|
|
|
|
|
|
t_token *lexer(t_datas *datas, char *line) |
|
|
|
void tmp_dealer(t_datas *datas, t_lexer *lex, char *line, char *tmp) |
|
|
|
{ |
|
|
|
t_lexer *lex; |
|
|
|
t_token *ret; |
|
|
|
char *tmp; |
|
|
|
int tmp_i; |
|
|
|
int tmp_i; |
|
|
|
|
|
|
|
lex = ft_calloc(1, sizeof(*lex)); |
|
|
|
lex->state = ROOT_ST; |
|
|
|
tmp = ft_calloc(STR_MAX_SIZE, sizeof(*tmp)); |
|
|
|
tmp_i = 0; |
|
|
|
while (*line) |
|
|
|
{ |
|
|
@ -42,6 +34,18 @@ t_token *lexer(t_datas *datas, char *line) |
|
|
|
else |
|
|
|
tmp[tmp_i++] = *(line++); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
t_token *lexer(t_datas *datas, char *line) |
|
|
|
{ |
|
|
|
t_lexer *lex; |
|
|
|
t_token *ret; |
|
|
|
char *tmp; |
|
|
|
|
|
|
|
lex = ft_calloc(1, sizeof(*lex)); |
|
|
|
lex->state = ROOT_ST; |
|
|
|
tmp = ft_calloc(STR_MAX_SIZE, sizeof(*tmp)); |
|
|
|
tmp_dealer(datas, lex, line, tmp); |
|
|
|
if (lex->type == WORD && lex->wc) |
|
|
|
create_wc(lex, tmp); |
|
|
|
else |
|
|
@ -52,37 +56,6 @@ t_token *lexer(t_datas *datas, char *line) |
|
|
|
return (ret); |
|
|
|
} |
|
|
|
|
|
|
|
static int check_state(t_lexer *lex, char **line) |
|
|
|
{ |
|
|
|
t_state new; |
|
|
|
|
|
|
|
new = OLD_ST; |
|
|
|
if (**line == '"' && lex->state == D_QUOTE_ST) |
|
|
|
new = ROOT_ST; |
|
|
|
else if (**line == '"' && lex->state == ROOT_ST) |
|
|
|
new = D_QUOTE_ST; |
|
|
|
else if (**line == '\'' && lex->state == S_QUOTE_ST) |
|
|
|
new = ROOT_ST; |
|
|
|
else if (**line == '\'' && lex->state == ROOT_ST) |
|
|
|
new = S_QUOTE_ST; |
|
|
|
else if (**line == '(' && lex->state == ROOT_ST) |
|
|
|
lex->deep++; |
|
|
|
else if (**line == ')' && lex->state == ROOT_ST) |
|
|
|
lex->deep--; |
|
|
|
else if (**line == '*' && lex->state == ROOT_ST && !lex->deep) |
|
|
|
lex->wc = 1; |
|
|
|
if (new) |
|
|
|
{ |
|
|
|
lex->state = new; |
|
|
|
if (lex->deep == 0) |
|
|
|
{ |
|
|
|
(*line)++; |
|
|
|
return (1); |
|
|
|
} |
|
|
|
} |
|
|
|
return (0); |
|
|
|
} |
|
|
|
|
|
|
|
int create_token(t_lexer *lex, char str[]) |
|
|
|
{ |
|
|
|
t_token *tok; |
|
|
@ -146,12 +119,8 @@ static int check_register(t_lexer *lex, char **line, char *tmp) |
|
|
|
spaces = 0; |
|
|
|
if (!*tmp && (*(*line - 1) == '"' || *(*line - 1) == '\'')) |
|
|
|
lex->empty = 1; |
|
|
|
if (ft_isspace(**line)) |
|
|
|
{ |
|
|
|
while (ft_isspace(**line)) |
|
|
|
(*line)++; |
|
|
|
spaces = 1; |
|
|
|
} |
|
|
|
while (ft_isspace(**line) && ++spaces) |
|
|
|
(*line)++; |
|
|
|
if (set_redir(lex, line, '>') || set_redir(lex, line, '<')) |
|
|
|
return (create_token(lex, tmp)); |
|
|
|
if (check_ope(lex, line, tmp)) |
|
|
|