diff --git a/caller.c b/caller.c index 627e35e..e798bed 100755 --- a/caller.c +++ b/caller.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/03 11:48:16 by narnaud #+# #+# */ -/* Updated: 2022/05/12 08:43:04 by narnaud ### ########.fr */ +/* Updated: 2022/05/12 11:34:26 by mea ### ########.fr */ /* */ /* ************************************************************************** */ @@ -80,7 +80,7 @@ int piper(t_datas *datas, t_command *cmd) if (cmd->fd[0]) close(cmd->fd[0]); if (DEBUG) - printf("%s -ope: %d, pid: %d, fdin: %d, fdout: %d\n", cmd->argv[0], cmd->ope, pid, cmd->fd[0], cmd->fd[1]); + printf("%s -ope: %d, argc: %d, pid: %d, fdin: %d, fdout: %d\n", cmd->argv[0], cmd->ope, cmd->argc, pid, cmd->fd[0], cmd->fd[1]); if (cmd->ope == PIPE) pid = piper(datas, cmd->next); waitpid(pid, &status, 0); diff --git a/lexer.c b/lexer.c index d11ecd8..382c8ca 100755 --- a/lexer.c +++ b/lexer.c @@ -6,12 +6,13 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); +} diff --git a/minishell.h b/minishell.h index f4a551d..6a03a36 100755 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */ -/* Updated: 2022/05/12 08:43:53 by narnaud ### ########.fr */ +/* Updated: 2022/05/12 11:33:39 by mea ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ # define ENVP_MAX_SIZE 1024 # define STR_MAX_SIZE 1024 # define PATHS_MAX_SIZE 126 -# define DEBUG 0 +# define DEBUG 1 # include "libft/libft.h" # include @@ -30,6 +30,7 @@ # include # include # include +# include typedef struct s_command { @@ -115,6 +116,7 @@ typedef struct s_lex t_type type; t_type next_type; t_token *tokens; + int wc; int deep; int n_elem; int empty;