VPATH := src
SRC := main.c debug_tools.c init.c signal_handling.c repl.c new_token.c \
free_token.c new_node.c free_node.c tokenizer.c parser.c \
- parse_cmd.c print_ast.c
+ parse_cmd.c collect_assigns.c collect_redirs.c print_ast.c
OBJ_DIR := _obj
OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o))
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/02 13:49:31 by dkaiser #+# #+# */
-/* Updated: 2024/08/02 15:21:04 by dkaiser ### ########.fr */
+/* Updated: 2024/08/11 12:12:16 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
-static void collect_redir(t_token **tokens, t_redirection *result,
+static t_token *collect_redir(t_token **tokens, t_redirection *result,
t_token *cur);
static void set_redir(t_redirection *redir, int type, char *specifier);
static int is_output_redir(int i);
while (cur != NULL && cur->next != NULL)
{
if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN)
- collect_redir(tokens, result, cur);
+ cur = collect_redir(tokens, result, cur);
else if (cur->type == REDIR_TOKEN)
{
dbg("TODO: Add parsing errmsg");
return (result);
}
-static void collect_redir(t_token **tokens, t_redirection *result, t_token *cur)
+static t_token *collect_redir(t_token **tokens, t_redirection *result,
+ t_token *cur)
{
set_redir(&result[is_output_redir(cur->content.redir_type)],
cur->content.redir_type, cur->next->content.string);
free_token_and_connect(cur->previous);
}
else
+ {
free_token(cur);
+ return (NULL);
+ }
+ return (cur);
}
static void set_redir(t_redirection *redir, int type, char *specifier)
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */
-/* Updated: 2024/08/02 14:22:32 by dkaiser ### ########.fr */
+/* Updated: 2024/08/11 12:14:11 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
cur = *tokens;
i = 0;
- while (cur != NULL)
- {
- i++;
+ while (cur != NULL && ++i)
cur = cur->next;
- }
result = malloc(sizeof(char *) * (i + 1));
if (result == NULL)
return (free_tokens(*tokens), NULL);
i = 0;
while (cur != NULL && cur->type == STRING_TOKEN)
{
+ if (cur->previous)
+ free_token(cur->previous);
result[i] = cur->content.string;
i++;
cur = cur->next;
- free_token(cur->previous);
}
result[i] = NULL;
return (result);
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/28 20:55:50 by chuhlig #+# #+# */
-/* Updated: 2024/08/09 15:40:00 by chuhlig ### ########.fr */
+/* Updated: 2024/08/11 11:40:35 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
pos = i + 1;
}
}
+ while ((*token_list)->previous)
+ *token_list = (*token_list)->previous;
}