|
|
@ -6,7 +6,7 @@ |
|
|
|
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* Created: 2022/05/02 13:44:57 by narnaud #+# #+# */ |
|
|
|
/* Updated: 2022/05/07 23:12:25 by narnaud@stude ### ########.fr */ |
|
|
|
/* Updated: 2022/05/09 09:59:11 by narnaud ### ########.fr */ |
|
|
|
/* */ |
|
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
@ -31,7 +31,7 @@ t_token *lexer(t_datas *datas, char *line) |
|
|
|
{ |
|
|
|
if (check_state(lex, &line)) |
|
|
|
continue ; |
|
|
|
if (lex->state != S_QUOTE_ST && *line == '$') |
|
|
|
if (lex->state != S_QUOTE_ST && lex->deep == 0 && *line == '$') |
|
|
|
tmp_i = replace_var(datas, &line, tmp, tmp_i); |
|
|
|
else if (check_register(lex, &line, tmp)) |
|
|
|
tmp_i = (ft_bzero(tmp, STR_MAX_SIZE), 0); |
|
|
@ -50,25 +50,26 @@ static int check_state(t_lexer *lex, char **line) |
|
|
|
t_state new; |
|
|
|
|
|
|
|
new = OLD_ST; |
|
|
|
if (**line == '"') |
|
|
|
{ |
|
|
|
if (lex->state == D_QUOTE_ST) |
|
|
|
new = ROOT_ST; |
|
|
|
else if (lex->state == ROOT_ST) |
|
|
|
new = D_QUOTE_ST; |
|
|
|
} |
|
|
|
else if (**line == '\'') |
|
|
|
{ |
|
|
|
if (lex->state == S_QUOTE_ST) |
|
|
|
new = ROOT_ST; |
|
|
|
else if (lex->state == ROOT_ST) |
|
|
|
new = S_QUOTE_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--; |
|
|
|
if (new) |
|
|
|
{ |
|
|
|
(*line)++; |
|
|
|
lex->state = new; |
|
|
|
return (1); |
|
|
|
if (lex->deep == 0) |
|
|
|
{ |
|
|
|
(*line)++; |
|
|
|
return (1); |
|
|
|
} |
|
|
|
} |
|
|
|
return (0); |
|
|
|
} |
|
|
@ -100,13 +101,39 @@ static int create_token(t_lexer *lex, char str[]) |
|
|
|
return (1); |
|
|
|
} |
|
|
|
|
|
|
|
static int check_ope(t_lexer *lex, char **line, char *tmp) |
|
|
|
{ |
|
|
|
if (!ft_strncmp(*line, "&&", 2)) |
|
|
|
{ |
|
|
|
(*line) += 2; |
|
|
|
lex->next_type = AND; |
|
|
|
create_token(lex, tmp); |
|
|
|
return (create_token(lex, "&&")); |
|
|
|
} |
|
|
|
if (!ft_strncmp(*line, "||", 2)) |
|
|
|
{ |
|
|
|
(*line) += 2; |
|
|
|
lex->next_type = OR; |
|
|
|
create_token(lex, tmp); |
|
|
|
return (create_token(lex, "||")); |
|
|
|
} |
|
|
|
if (**line == '|') |
|
|
|
{ |
|
|
|
(*line)++; |
|
|
|
lex->next_type = PIPE; |
|
|
|
create_token(lex, tmp); |
|
|
|
return (create_token(lex, "|")); |
|
|
|
} |
|
|
|
return (0); |
|
|
|
|
|
|
|
} |
|
|
|
static int set_redir(t_lexer *lex, char **line, char ch); |
|
|
|
|
|
|
|
static int check_register(t_lexer *lex, char **line, char *tmp) |
|
|
|
{ |
|
|
|
int spaces; |
|
|
|
|
|
|
|
if (lex->state != ROOT_ST) |
|
|
|
if (lex->state != ROOT_ST || lex->deep > 0) |
|
|
|
return (0); |
|
|
|
spaces = 0; |
|
|
|
if (ft_isspace(**line)) |
|
|
@ -115,19 +142,13 @@ static int check_register(t_lexer *lex, char **line, char *tmp) |
|
|
|
(*line)++; |
|
|
|
spaces = 1; |
|
|
|
} |
|
|
|
if (set_redir(lex, line, '>') \ |
|
|
|
|| set_redir(lex, line, '<')) |
|
|
|
if (set_redir(lex, line, '>') || set_redir(lex, line, '<')) |
|
|
|
return (create_token(lex, tmp)); |
|
|
|
else if (**line == '|') |
|
|
|
{ |
|
|
|
(*line)++; |
|
|
|
lex->next_type = PIPE; |
|
|
|
create_token(lex, tmp); |
|
|
|
return (create_token(lex, "|")); |
|
|
|
} |
|
|
|
if (!spaces || !*tmp) |
|
|
|
return (0); |
|
|
|
return (create_token(lex, tmp)); |
|
|
|
if (check_ope(lex, line, tmp)) |
|
|
|
return (1); |
|
|
|
if ((**line == '(' || spaces) && *tmp) |
|
|
|
return (create_token(lex, tmp)); |
|
|
|
return (0); |
|
|
|
} |
|
|
|
|
|
|
|
static int set_redir(t_lexer *lex, char **line, char ch) |
|
|
|