aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/collect_redirs.c36
-rw-r--r--src/parse_cmd.c16
2 files changed, 29 insertions, 23 deletions
diff --git a/src/collect_redirs.c b/src/collect_redirs.c
index db4ab00..e5bc8f6 100644
--- a/src/collect_redirs.c
+++ b/src/collect_redirs.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/02 13:49:31 by dkaiser #+# #+# */
-/* Updated: 2025/01/20 17:12:42 by dkaiser ### ########.fr */
+/* Updated: 2025/01/20 17:30:00 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,17 +14,18 @@
#include <stdlib.h>
static void collect_and_check_redir(t_redirection *result,
- t_token **cur, t_env *env, t_list **create_files);
+ t_token **cur, t_minidata *data, t_token **tokens);
static t_redirection *set_redir(t_redirection *redir, int type, char *spec,
t_env *env);
static int set_heredoc_data(t_token *cur, t_redirection *result,
t_env *env);
t_redirection *collect_redirs(t_token **tokens, t_env *env,
- t_list **create_files)
+ t_list **create_files)
{
t_redirection *result;
t_token *cur;
+ t_minidata data;
cur = *tokens;
result = malloc(sizeof(t_redirection) * 2);
@@ -32,10 +33,12 @@ t_redirection *collect_redirs(t_token **tokens, t_env *env,
return (free_tokens(*tokens), NULL);
set_redir(&result[0], 0, NULL, env);
set_redir(&result[1], 0, NULL, env);
+ data.create_files = create_files;
+ data.env = env;
while (cur != NULL)
{
if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN)
- collect_and_check_redir(result, &cur, env, create_files);
+ collect_and_check_redir(result, &cur, &data, tokens);
else if (cur->type == REDIR_TOKEN)
return (free(result), NULL);
else
@@ -47,7 +50,7 @@ t_redirection *collect_redirs(t_token **tokens, t_env *env,
}
static void collect_and_check_redir(t_redirection *result, t_token **cur,
- t_env *env, t_list **create_files)
+ t_minidata *data, t_token **tokens)
{
t_token *next_token;
char *str;
@@ -56,22 +59,27 @@ static void collect_and_check_redir(t_redirection *result, t_token **cur,
str = ft_strdup((*cur)->next->content.string);
if ((*cur)->content.redir_type == INPUT_LIMITER)
{
- if (!set_heredoc_data(*cur, result, env))
+ if (!set_heredoc_data(*cur, result, data->env))
return ;
}
else if ((*cur)->content.redir_type == INPUT_FILE)
- ft_lstadd_back(create_files, ft_lstnew(set_redir(&result[0], INPUT_FILE, format_string(str, env, 0), env)));
+ ft_lstadd_back(data->create_files, ft_lstnew(set_redir(&result[0],
+ INPUT_FILE, format_string(str, data->env, 0), data->env)));
else if ((*cur)->content.redir_type == OUTPUT_OVERRIDE)
- ft_lstadd_back(create_files, ft_lstnew(set_redir(&result[1],
- OUTPUT_OVERRIDE, format_string(str, env, 0), env)));
+ ft_lstadd_back(data->create_files, ft_lstnew(set_redir(&result[1],
+ OUTPUT_OVERRIDE, format_string(str, data->env, 0),
+ data->env)));
else if ((*cur)->content.redir_type == OUTPUT_APPEND)
- ft_lstadd_back(create_files, ft_lstnew(set_redir(&result[1],
- OUTPUT_APPEND, format_string(str, env, 0), env)));
+ ft_lstadd_back(data->create_files, ft_lstnew(set_redir(&result[1],
+ OUTPUT_APPEND, format_string(str, data->env, 0),
+ data->env)));
next_token = (*cur)->next;
- // free_token_and_connect(*cur);
+ free_token_and_connect(*cur);
if (next_token)
{
- free_token_and_connect(*cur);
+ if (next_token->previous == NULL)
+ *tokens = next_token->next;
+ // free_token_and_connect(*cur);
*cur = next_token->next;
free_token_and_connect(next_token);
}
@@ -101,8 +109,6 @@ static t_redirection *set_redir(t_redirection *redir, int type, char *spec,
return (NULL);
}
-
-
static int set_heredoc_data(t_token *cur, t_redirection *result, t_env *env)
{
char *heredoc_data;
diff --git a/src/parse_cmd.c b/src/parse_cmd.c
index d13bf3f..5502f74 100644
--- a/src/parse_cmd.c
+++ b/src/parse_cmd.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */
-/* Updated: 2025/01/20 12:44:44 by chuhlig ### ########.fr */
+/* Updated: 2025/01/20 17:30:06 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -35,10 +35,10 @@ t_node *parse_cmd(t_token *tokens, t_env **env)
static char **collect_args(t_token **tokens, t_env **env)
{
- t_token *cur;
- t_token *next;//2
- char **result;
- int i;
+ t_token *cur;
+ t_token *next; // 2
+ char **result;
+ int i;
cur = *tokens;
i = 0;
@@ -51,14 +51,14 @@ static char **collect_args(t_token **tokens, t_env **env)
i = 0;
while (cur != NULL && cur->type == STRING_TOKEN)
{
- next = cur->next;//2
+ next = cur->next; // 2
if (cur->previous)
free_token(cur->previous);
result[i] = format_string(cur->content.string, *env, ft_atoi("0"));
i++;
// cur = cur->next;
- cur = next;//2
+ cur = next; // 2
}
result[i] = NULL;
return (result);
-} \ No newline at end of file
+}