|
|
@ -6,12 +6,13 @@ |
|
|
|
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* Created: 2022/05/02 13:44:57 by narnaud #+# #+# */ |
|
|
|
/* Updated: 2022/05/11 01:17:45 by narnaud@stude ### ########.fr */ |
|
|
|
/* Updated: 2022/05/12 13:07:38 by narnaud ### ########.fr */ |
|
|
|
/* */ |
|
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
|
#include "minishell.h" |
|
|
|
|
|
|
|
static int create_wc(t_lexer *lex, char *tmp); |
|
|
|
static int check_state(t_lexer *lex, char **line); |
|
|
|
static int create_token(t_lexer *lex, char str[]); |
|
|
|
static int check_register(t_lexer *lex, char **line, char *tmp); |
|
|
@ -38,7 +39,10 @@ t_token *lexer(t_datas *datas, char *line) |
|
|
|
else |
|
|
|
tmp[tmp_i++] = *(line++); |
|
|
|
} |
|
|
|
create_token(lex, tmp); |
|
|
|
if (lex->type == WORD && lex->wc) |
|
|
|
create_wc(lex, tmp); |
|
|
|
else |
|
|
|
create_token(lex, tmp); |
|
|
|
free(tmp); |
|
|
|
ret = lex->tokens; |
|
|
|
free(lex); |
|
|
@ -62,6 +66,8 @@ static int check_state(t_lexer *lex, char **line) |
|
|
|
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; |
|
|
@ -152,7 +158,52 @@ static int check_register(t_lexer *lex, char **line, char *tmp) |
|
|
|
if (**line == '(') |
|
|
|
lex->deep++; |
|
|
|
if (*tmp || lex->empty) |
|
|
|
{ |
|
|
|
if (lex->type == WORD && lex->wc) |
|
|
|
return (create_wc(lex, tmp)); |
|
|
|
return (create_token(lex, tmp)); |
|
|
|
} |
|
|
|
} |
|
|
|
return (0); |
|
|
|
} |
|
|
|
|
|
|
|
int create_wc(t_lexer *lex, char *tmp) |
|
|
|
{ |
|
|
|
int i; |
|
|
|
int j; |
|
|
|
int skip ; |
|
|
|
DIR * direct; |
|
|
|
struct dirent *file; |
|
|
|
|
|
|
|
direct = opendir("."); |
|
|
|
file = readdir(direct); |
|
|
|
file = readdir(direct); |
|
|
|
file = readdir(direct); |
|
|
|
while (file) |
|
|
|
{ |
|
|
|
i = 0; |
|
|
|
j = 0; |
|
|
|
skip = (tmp[0] != '.' && file->d_name[0] == '.'); |
|
|
|
while (tmp[i] && !skip) |
|
|
|
{ |
|
|
|
if (tmp[i] == '*') |
|
|
|
{ |
|
|
|
while (file->d_name[j] && file->d_name[j] != tmp[i + 1]) |
|
|
|
j++; |
|
|
|
} |
|
|
|
if (tmp[i] != '*' && file->d_name[j] != tmp[i]) |
|
|
|
skip = 1; |
|
|
|
else |
|
|
|
{ |
|
|
|
i++; |
|
|
|
j++; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!skip) |
|
|
|
create_token(lex, file->d_name); |
|
|
|
file = readdir(direct); |
|
|
|
} |
|
|
|
closedir(direct); |
|
|
|
lex->wc = 0; |
|
|
|
return (1); |
|
|
|
} |
|
|
|