aboutsummaryrefslogtreecommitdiff
path: root/src/parse_cmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse_cmd.c')
-rw-r--r--src/parse_cmd.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/parse_cmd.c b/src/parse_cmd.c
index 6505384..578601c 100644
--- a/src/parse_cmd.c
+++ b/src/parse_cmd.c
@@ -6,13 +6,14 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */
-/* Updated: 2025/01/20 19:09:21 by chuhlig ### ########.fr */
+/* Updated: 2025/01/25 15:00:55 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static char **collect_args(t_token **tokens, t_env **env);
+static void setup_vars(t_token **tokens, t_token **cur, int *i);
t_node *parse_cmd(t_token *tokens, t_env **env)
{
@@ -40,24 +41,29 @@ static char **collect_args(t_token **tokens, t_env **env)
int i;
t_token *next;
- cur = *tokens;
- i = 0;
+ setup_vars(tokens, &cur, &i);
while (cur != NULL && ++i)
cur = cur->next;
result = malloc(sizeof(char *) * (i + 1));
if (result == NULL)
return (free_tokens(*tokens), NULL);
- cur = *tokens;
- i = 0;
+ setup_vars(tokens, &cur, &i);
while (cur != NULL && cur->type == STRING_TOKEN)
{
next = cur->next;
if (cur->previous)
- free_token(cur->previous);
- result[i] = format_string(cur->content.string, *env, ft_atoi("0"));
- i++;
+ free_token2(cur->previous);
+ result[i++] = format_string(cur->content.string, *env, ft_atoi("0"));
+ if (cur->next == NULL)
+ free_token2(cur);
cur = next;
}
result[i] = NULL;
return (result);
}
+
+static void setup_vars(t_token **tokens, t_token **cur, int *i)
+{
+ *cur = *tokens;
+ *i = 0;
+}