From: Dominik Kaiser Date: Tue, 17 Sep 2024 17:25:13 +0000 (+0200) Subject: Fix error message printing X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=1fec66236f1811a3eeac673d0002fe8d9d3d8835;p=42%2Fminishell.git Fix error message printing --- diff --git a/src/collect_redirs.c b/src/collect_redirs.c index 79ae95c..60f197b 100644 --- a/src/collect_redirs.c +++ b/src/collect_redirs.c @@ -6,7 +6,7 @@ /* By: dkaiser next != NULL) { if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) + { + is_redir_only = 0; + if (cur->previous == NULL && cur->next->next == NULL) + is_redir_only = 1; cur = collect_redir(tokens, result, cur); + if (is_redir_only) + *tokens = NULL; + } else if (cur->type == REDIR_TOKEN) - { - printf("Parsing error.\n"); return (free(result), NULL); - } else cur = cur->next; } if (cur && cur->type == REDIR_TOKEN) - { - printf("Parsing error.\n"); return (free(result), NULL); - } return (result); } diff --git a/src/new_node.c b/src/new_node.c index 5c770aa..c58d291 100644 --- a/src/new_node.c +++ b/src/new_node.c @@ -6,7 +6,7 @@ /* By: dkaiser next = ft_lstnew(parse_statement(current_tokens)); - current = current->next; - } - if (current == NULL) - return (ft_lstclear(&result, free_node_wrapper), NULL); - current_tokens = split_at_first(&tokens, NEWLINE_TOKEN); - } - return (result); + if ((*tokens).type == PIPE_TOKEN) + result = NULL; + else + result = parse_statement(tokens); + if (result == NULL) + printf("Parsing error.\n"); + return (ft_lstnew(result)); } static t_node *parse_statement(t_token *tokens) @@ -53,7 +39,6 @@ static t_node *parse_statement(t_token *tokens) if (left_side_tokens == NULL) { free_tokens(tokens); - printf("Parsing error.\n"); return (NULL); } else if (tokens != NULL) @@ -97,8 +82,3 @@ static t_token *find_token_by_type(t_token *tokens, int type) } return (NULL); } - -static void free_node_wrapper(void *node) -{ - free_node((t_node *)node); -}