From: Dominik Kaiser Date: Tue, 9 Jul 2024 10:54:35 +0000 (+0200) Subject: Get colllect_args() to work properly X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=389f7c91f0ebd59c80b457fce63ad383dfd27f85;p=42%2Fminishell.git Get colllect_args() to work properly --- diff --git a/src/parse_cmd.c b/src/parse_cmd.c index 981bbbb..739c022 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -64,33 +64,6 @@ static t_assign **collect_assigns(t_token **tokens) return (result); } -static char **collect_args(t_token **tokens) -{ - int i; - char **result; - - i = 0; - while (tokens[i] != NULL) - { - i++; - } - result = malloc(sizeof(char *) * (i + 1)); - if (result == NULL) - { - // free everything in the token - return (NULL); - } - i = 0; - while (tokens[i] != NULL) - { - result[i] = tokens[i]->content.string; - free_token(tokens[i]); - i++; - } - result[i] = NULL; - return (result); -} - static t_assign *to_assign(char *str) { t_assign *result; @@ -107,3 +80,33 @@ static t_assign *to_assign(char *str) result->value = split + 1; return (result); } + +static char **collect_args(t_token **tokens) +{ + t_token *cur; + char **result; + int i; + + cur = *tokens; + i = 0; + while (cur != NULL) { + i++; + cur = cur->next; + } + result = malloc(sizeof(char*) * (i + 1)); + if (!result) + { + //free all tokens; + return (NULL); + } + cur = *tokens; + i = 0; + while(cur != NULL) + { + result[i] = cur->content.string; + // free token + i++; + cur = cur->next; + } + return (result); +}