From f53acc629b1b3e7f4097eef1e26841ef0b9b24c6 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Sun, 11 Aug 2024 12:15:40 +0200 Subject: Fix parser bugs --- src/collect_redirs.c | 13 +++++++++---- src/parse_cmd.c | 10 ++++------ src/tokenizer.c | 4 +++- 3 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/collect_redirs.c b/src/collect_redirs.c index 76b08da..d50bec4 100644 --- a/src/collect_redirs.c +++ b/src/collect_redirs.c @@ -6,13 +6,13 @@ /* By: dkaiser next != NULL) { if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) - collect_redir(tokens, result, cur); + cur = collect_redir(tokens, result, cur); else if (cur->type == REDIR_TOKEN) { dbg("TODO: Add parsing errmsg"); @@ -43,7 +43,8 @@ t_redirection *collect_redirs(t_token **tokens) return (result); } -static void collect_redir(t_token **tokens, t_redirection *result, t_token *cur) +static t_token *collect_redir(t_token **tokens, t_redirection *result, + t_token *cur) { set_redir(&result[is_output_redir(cur->content.redir_type)], cur->content.redir_type, cur->next->content.string); @@ -57,7 +58,11 @@ static void collect_redir(t_token **tokens, t_redirection *result, t_token *cur) free_token_and_connect(cur->previous); } else + { free_token(cur); + return (NULL); + } + return (cur); } static void set_redir(t_redirection *redir, int type, char *specifier) diff --git a/src/parse_cmd.c b/src/parse_cmd.c index 068a4c1..eb70f0d 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,7 +6,7 @@ /* By: dkaiser next; - } result = malloc(sizeof(char *) * (i + 1)); if (result == NULL) return (free_tokens(*tokens), NULL); @@ -46,10 +43,11 @@ static char **collect_args(t_token **tokens) i = 0; while (cur != NULL && cur->type == STRING_TOKEN) { + if (cur->previous) + free_token(cur->previous); result[i] = cur->content.string; i++; cur = cur->next; - free_token(cur->previous); } result[i] = NULL; return (result); diff --git a/src/tokenizer.c b/src/tokenizer.c index 34685ac..efbf723 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/28 20:55:50 by chuhlig #+# #+# */ -/* Updated: 2024/08/09 15:40:00 by chuhlig ### ########.fr */ +/* Updated: 2024/08/11 11:40:35 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -110,4 +110,6 @@ void tokenizer(char *s, t_token **token_list) pos = i + 1; } } + while ((*token_list)->previous) + *token_list = (*token_list)->previous; } -- cgit v1.2.3