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.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/parse_cmd.c b/src/parse_cmd.c
index 2755cae..6505384 100644
--- a/src/parse_cmd.c
+++ b/src/parse_cmd.c
@@ -3,32 +3,42 @@
/* ::: :::::::: */
/* parse_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */
-/* Updated: 2024/08/11 12:20:06 by dkaiser ### ########.fr */
+/* Updated: 2025/01/20 19:09:21 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
-static char **collect_args(t_token **tokens);
+static char **collect_args(t_token **tokens, t_env **env);
-t_node *parse_cmd(t_token *tokens)
+t_node *parse_cmd(t_token *tokens, t_env **env)
{
char **args;
t_redirection *redirs;
+ t_list *create_files;
- redirs = collect_redirs(&tokens);
- args = collect_args(&tokens);
- return (new_cmd_node(args, redirs));
+ create_files = NULL;
+ redirs = collect_redirs(&tokens, *env, &create_files);
+ if (redirs == NULL)
+ return (NULL);
+ args = collect_args(&tokens, env);
+ if (args == NULL)
+ {
+ free(redirs);
+ return (NULL);
+ }
+ return (new_cmd_node(args, redirs, create_files));
}
-static char **collect_args(t_token **tokens)
+static char **collect_args(t_token **tokens, t_env **env)
{
t_token *cur;
char **result;
int i;
+ t_token *next;
cur = *tokens;
i = 0;
@@ -41,11 +51,12 @@ static char **collect_args(t_token **tokens)
i = 0;
while (cur != NULL && cur->type == STRING_TOKEN)
{
+ next = cur->next;
if (cur->previous)
free_token(cur->previous);
- result[i] = cur->content.string;
+ result[i] = format_string(cur->content.string, *env, ft_atoi("0"));
i++;
- cur = cur->next;
+ cur = next;
}
result[i] = NULL;
return (result);