redirect norminette
This commit is contained in:
parent
d96b23ca02
commit
ce2c50e753
@ -15,6 +15,7 @@
|
|||||||
# include "minishell.h"
|
# include "minishell.h"
|
||||||
|
|
||||||
t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value);
|
t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value);
|
||||||
|
void redirect_new_error(t_minishell *msh, t_list **redirects);
|
||||||
void redirect_create(t_minishell *msh, t_list **tokens, t_list **redirects, t_token_type type);
|
void redirect_create(t_minishell *msh, t_list **tokens, t_list **redirects, t_token_type type);
|
||||||
t_list *redirect_get_inputs(t_minishell *msh, t_list *list);
|
t_list *redirect_get_inputs(t_minishell *msh, t_list *list);
|
||||||
t_list *redirect_get_outputs(t_minishell *msh, t_list *list);
|
t_list *redirect_get_outputs(t_minishell *msh, t_list *list);
|
||||||
|
|||||||
24
sources.mk
24
sources.mk
@ -1,24 +0,0 @@
|
|||||||
VPATH = src:src/prompt:src/utils:src/lexer:src/token:src/environment:src/executor:src/parser:src/debug:src/expander:src/builtin:src/signal:src/redirect:
|
|
||||||
SOURCES = history_load.c history_write.c prompt.c print_banner.c \
|
|
||||||
init_minishell.c ft_substr_safe.c check_malloc.c error_msg.c \
|
|
||||||
free_command_list.c free_freelist.c free_lexer.c free_minishell.c \
|
|
||||||
free_minishell_line.c free_safe.c free_token.c free_token_list.c \
|
|
||||||
ft_lstclear_safe.c ft_lstnew_safe.c ft_strdup_safe.c \
|
|
||||||
ft_strjoin_safe.c malloc_safe.c lexer_read_char.c lexer_new.c \
|
|
||||||
lexer_parse_input.c lexer_read_word.c lexer_token_next.c token_new.c \
|
|
||||||
token_parse.c environment_add.c environment_del.c environment_free.c \
|
|
||||||
environment_free_list.c environment_get.c environment_get_arr.c \
|
|
||||||
environment_parse.c environment_print.c executor_close_fds.c \
|
|
||||||
executor_absolute_path.c executor_child.c executor_count_fds.c \
|
|
||||||
executor_create_pipes.c executor_create_redirects.c \
|
|
||||||
executor_execute_pipeline.c executor_fork.c executor_open_fds.c \
|
|
||||||
parser_get_arguments.c parser_new_command.c parser_get_commands.c \
|
|
||||||
print_commands.c print_freelist.c expander_is_character.c \
|
|
||||||
expander_expand_dollar.c expander_allocate_memory.c \
|
|
||||||
expander_parse_string.c expander_parse_variables.c \
|
|
||||||
expander_get_variable.c builtin_cd.c builtin_echo.c builtin_env.c \
|
|
||||||
builtin_exit.c builtin_export.c builtin_pwd.c builtin_router.c \
|
|
||||||
builtin_unset.c is_builtin.c simple_builtins.c signal.c \
|
|
||||||
signal_init.c.c redirect_get_outputs.c redirect_new.c \
|
|
||||||
redirect_get_inputs.c redirect_valid_type.c \
|
|
||||||
redirect_process_heredoc.c main.c \
|
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/23 12:29:05 by Quinten #+# #+# */
|
/* Created: 2025/02/23 12:29:05 by Quinten #+# #+# */
|
||||||
/* Updated: 2025/02/26 17:24:53 by qmennen ### ########.fr */
|
/* Updated: 2025/02/26 17:38:59 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -43,6 +43,6 @@ t_list *redirect_get_inputs(t_minishell *msh, t_list *list)
|
|||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
if (flag <= 0)
|
if (flag <= 0)
|
||||||
ft_lstadd_front(&redirects, ft_lstnew_safe(msh, redirect_new(msh, T_ERROR, NULL)));
|
redirect_new_error(msh, &redirects);
|
||||||
return (redirects);
|
return (redirects);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,6 @@ t_list *redirect_get_outputs(t_minishell *msh, t_list *list)
|
|||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
if (flag <= 0)
|
if (flag <= 0)
|
||||||
ft_lstadd_front(&redirects, ft_lstnew_safe(msh, redirect_new(msh, T_ERROR, NULL)));
|
redirect_new_error(msh, &redirects);
|
||||||
return (redirects);
|
return (redirects);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,9 @@ t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value)
|
|||||||
result->value = value;
|
result->value = value;
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
void redirect_create(t_minishell *msh, t_list **tokens, t_list **redirects, t_token_type type)
|
|
||||||
|
void redirect_create(t_minishell *msh, t_list **tokens, t_list **redirects,
|
||||||
|
t_token_type type)
|
||||||
{
|
{
|
||||||
t_list *new;
|
t_list *new;
|
||||||
t_redirect *redir;
|
t_redirect *redir;
|
||||||
@ -31,9 +33,12 @@ void redirect_create(t_minishell *msh, t_list **tokens, t_list **redirects, t_to
|
|||||||
char *file_name;
|
char *file_name;
|
||||||
|
|
||||||
file_token = (t_token *)((*tokens)->next->content);
|
file_token = (t_token *)((*tokens)->next->content);
|
||||||
file_name = ft_strdup_safe(msh, file_token->value);
|
file_name = NULL;
|
||||||
|
if (file_token)
|
||||||
|
file_name = ft_strdup_safe(msh, file_token->value);
|
||||||
redir = redirect_new(msh, type, file_name);
|
redir = redirect_new(msh, type, file_name);
|
||||||
new = ft_lstnew_safe(msh, redir);
|
new = ft_lstnew_safe(msh, redir);
|
||||||
ft_lstadd_back(redirects, new);
|
ft_lstadd_back(redirects, new);
|
||||||
*tokens = (*tokens)->next;
|
if (tokens)
|
||||||
|
*tokens = (*tokens)->next;
|
||||||
}
|
}
|
||||||
23
src/redirect/redirect_new_error.c
Normal file
23
src/redirect/redirect_new_error.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redirect_new_error.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/02/26 17:37:12 by qmennen #+# #+# */
|
||||||
|
/* Updated: 2025/02/26 17:44:49 by qmennen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void redirect_new_error(t_minishell *msh, t_list **redirects)
|
||||||
|
{
|
||||||
|
t_list *new;
|
||||||
|
t_redirect *redir;
|
||||||
|
|
||||||
|
redir = redirect_new(msh, T_ERROR, NULL);
|
||||||
|
new = ft_lstnew_safe(msh, redir);
|
||||||
|
ft_lstadd_back(redirects, new);
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/23 12:30:18 by Quinten #+# #+# */
|
/* Created: 2025/02/23 12:30:18 by Quinten #+# #+# */
|
||||||
/* Updated: 2025/02/26 17:12:40 by qmennen ### ########.fr */
|
/* Updated: 2025/02/26 17:40:44 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,9 +20,9 @@ int redirect_token_type(t_token *token)
|
|||||||
|| token->type == T_APPEND_OUT);
|
|| token->type == T_APPEND_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int redirect_is_valid(t_list *lst, t_token *token, int mode)
|
int redirect_is_valid(t_list *lst, t_token *token, int mode)
|
||||||
{
|
{
|
||||||
t_token *next;
|
t_token *next;
|
||||||
|
|
||||||
if (!lst->next)
|
if (!lst->next)
|
||||||
return (0);
|
return (0);
|
||||||
@ -39,7 +39,7 @@ int redirect_is_valid(t_list *lst, t_token *token, int mode)
|
|||||||
return (redirect_token_type(token) && next->type < 3);
|
return (redirect_token_type(token) && next->type < 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
int redirect_is_delimiter(t_token *token)
|
int redirect_is_delimiter(t_token *token)
|
||||||
{
|
{
|
||||||
return (token->type == T_PIPE
|
return (token->type == T_PIPE
|
||||||
|| token->type == T_AND
|
|| token->type == T_AND
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user