From cfee8bc477fbdf8138c9087af140b25fa8fbc7c6 Mon Sep 17 00:00:00 2001 From: narnaud Date: Fri, 6 May 2022 20:05:50 +0200 Subject: [PATCH] . --- built-in.c | 1 - caller.c | 2 -- lexer.c | 13 +++++++------ libft/dlist/ft_to_arr.c | 4 ++-- libft/str/ft_split.c | 2 +- minishell.c | 15 +++++++++++++++ minishell.h | 1 - parser.c | 4 +--- 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/built-in.c b/built-in.c index 564000c..931266d 100755 --- a/built-in.c +++ b/built-in.c @@ -21,7 +21,6 @@ int ft_echo(t_command *cmd) fd_out = cmd->fd[1]; else fd_out = 1; - no_nl = 0; if (*(++cmd->argv)) { diff --git a/caller.c b/caller.c index c32dd1f..cb80d78 100755 --- a/caller.c +++ b/caller.c @@ -32,7 +32,6 @@ int builtin_call(t_datas *datas, t_command *cmd) return (-1); } - int is_builtin(char *cmd) { if (!ft_strncmp(cmd, "echo", 5) || @@ -115,4 +114,3 @@ int piper(t_datas *datas, t_command *cmd) close(cmd->fd[0]); return (1); } - diff --git a/lexer.c b/lexer.c index 998c03a..5a130f9 100755 --- a/lexer.c +++ b/lexer.c @@ -36,7 +36,6 @@ int create_token(t_lexer *lex, char str[]) lex->tokens = tok; else tmp->next = tok; - ft_bzero(str, 1024); return (1); } @@ -119,9 +118,10 @@ int check_state(t_lexer *lex, char **line) t_token *lexer(t_datas *datas, char *line) { - t_lexer *lex; - char *tmp; - int tmp_i; + t_lexer *lex; + t_token *ret; + char *tmp; + int tmp_i; lex = ft_calloc(1, sizeof *lex); lex->state = ROOT_ST; @@ -134,12 +134,13 @@ t_token *lexer(t_datas *datas, char *line) if (lex->state != S_QUOTE_ST && *line == '$') tmp_i = replace_var(datas, &line, tmp, tmp_i); if (check_register(lex, &line, tmp)) - tmp_i = 0; + tmp_i = (ft_bzero(tmp, 1024), 0); else tmp[tmp_i++] = *(line++); } create_token(lex, tmp); free(tmp); + ret = lex->tokens; free(lex); - return (lex->tokens); + return (ret); } diff --git a/libft/dlist/ft_to_arr.c b/libft/dlist/ft_to_arr.c index 8eb7752..5b8a16a 100755 --- a/libft/dlist/ft_to_arr.c +++ b/libft/dlist/ft_to_arr.c @@ -33,9 +33,9 @@ char **ft_dlst_to_arr(t_dlist *ptr) while (count--) { ret[count] = last->content; - tmp = last; + tmp = last->previous; free(last); - last = tmp->previous; + last = tmp; } return (ret); } diff --git a/libft/str/ft_split.c b/libft/str/ft_split.c index 026999f..a2e0411 100755 --- a/libft/str/ft_split.c +++ b/libft/str/ft_split.c @@ -38,5 +38,5 @@ char **ft_split(const char *str, char c) word[j++] = str[i]; } words = ft_dlst_add(words, word); - return ((char **)ft_dlst_to_arr(words)); + return (ft_dlst_to_arr(words)); } diff --git a/minishell.c b/minishell.c index d6557d2..a613934 100755 --- a/minishell.c +++ b/minishell.c @@ -36,6 +36,20 @@ void termios(int ctl) tcsetattr(tty, TCSANOW, &termios_p); } +void free_cmd(t_command *cmd) +{ + int i; + + i = 0; + while (cmd->argv[i]) + { + free(cmd->argv[i]); + i++; + } + free(cmd->argv); + free(cmd); +} + void prompt(t_datas *datas) { char *line; @@ -53,6 +67,7 @@ void prompt(t_datas *datas) builtin_call(datas, cmd); else piper(datas, cmd); + free_cmd(cmd); add_history(line); } diff --git a/minishell.h b/minishell.h index 7cbf707..ca45c27 100755 --- a/minishell.h +++ b/minishell.h @@ -37,7 +37,6 @@ typedef struct s_command char **argv; int argc; int fd[2]; - char *heredoc; struct s_command *next; struct s_command *prev; } t_command; diff --git a/parser.c b/parser.c index 1a69a5a..373de7f 100755 --- a/parser.c +++ b/parser.c @@ -86,6 +86,7 @@ t_token *parse_cmd(t_datas *datas, t_token *tok, t_command *cmd) free(prev_tok); return (tok); } + t_command *parser(t_datas *datas, t_token *tok, t_command *prev) { t_command *cmd; @@ -99,7 +100,6 @@ t_command *parser(t_datas *datas, t_token *tok, t_command *prev) cmd->argc = 0; while(tok && tok->type != PIPE) tok = parse_cmd(datas, tok, cmd); - cmd->argv[cmd->argc] = NULL; if (tok && tok->type == PIPE) { cmd->next = parser(datas, tok->next, cmd); @@ -108,5 +108,3 @@ t_command *parser(t_datas *datas, t_token *tok, t_command *prev) } return(cmd); } - -