aboutsummaryrefslogtreecommitdiff
path: root/src/parse_cmd.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-07-09 12:54:35 +0200
committerDominik Kaiser2024-07-09 12:54:35 +0200
commit389f7c91f0ebd59c80b457fce63ad383dfd27f85 (patch)
tree8df760fa7e605a278ccdc3e4b07b56c7fb9b3b95 /src/parse_cmd.c
parenta5dd924bea37a0786dcf2b95690452f7714043f6 (diff)
downloadminishell-389f7c91f0ebd59c80b457fce63ad383dfd27f85.tar.gz
minishell-389f7c91f0ebd59c80b457fce63ad383dfd27f85.zip
Get colllect_args() to work properly
Diffstat (limited to 'src/parse_cmd.c')
-rw-r--r--src/parse_cmd.c57
1 files changed, 30 insertions, 27 deletions
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);
+}