norminette made me do it

This commit is contained in:
Quinten Mennen 2025-02-27 18:11:44 +01:00
parent 3cc3dff55c
commit 05b7ae3a6a
5 changed files with 119 additions and 118 deletions

View File

@ -1,27 +1,27 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* redirect.h :+: :+: */
/* +:+ */
/* By: Quinten <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/23 12:26:29 by Quinten #+# #+# */
/* Updated: 2025/02/23 12:26:29 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef REDIRECT_H
# define REDIRECT_H
# include "minishell.h"
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);
t_list *redirect_get_inputs(t_minishell *msh, t_list *list);
t_list *redirect_get_outputs(t_minishell *msh, t_list *list);
int redirect_is_valid(t_list *lst, t_token *token, int mode);
int redirect_token_type(t_token *token);
int redirect_is_delimiter(t_token *token);
int process_heredoc(t_minishell *msh, t_token *heredoc, t_token *delim);
#endif
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirect.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/23 12:26:29 by Quinten #+# #+# */
/* Updated: 2025/02/27 18:09:47 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef REDIRECT_H
# define REDIRECT_H
# include "minishell.h"
t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value);
void redirect_new_error(t_minishell *msh, t_list **redirects, int flag);
int 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_outputs(t_minishell *msh, t_list *list);
int redirect_is_valid(t_list *lst, t_token *token, int mode);
int redirect_token_type(t_token *token);
int redirect_is_delimiter(t_token *token);
int process_heredoc(t_minishell *msh, t_token *heredoc, t_token *delim);
#endif

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/23 12:29:05 by Quinten #+# #+# */
/* Updated: 2025/02/26 17:38:59 by qmennen ### ########.fr */
/* Updated: 2025/02/27 18:09:15 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,10 +39,9 @@ t_list *redirect_get_inputs(t_minishell *msh, t_list *list)
}
check_heredoc(msh, current, token);
flag = redirect_is_valid(current, token, F_OK | R_OK);
redirect_create(msh, &current, &redirects, token->type);
flag && (redirect_create(msh, &current, &redirects, token->type));
current = current->next;
}
if (flag <= 0)
redirect_new_error(msh, &redirects);
redirect_new_error(msh, &redirects, flag);
return (redirects);
}

View File

@ -1,41 +1,40 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* redirect_get_outputs.c :+: :+: */
/* +:+ */
/* By: Quinten <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/23 12:37:24 by Quinten #+# #+# */
/* Updated: 2025/02/23 12:37:24 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_list *redirect_get_outputs(t_minishell *msh, t_list *list)
{
t_list *current;
t_list *redirects;
t_token *token;
int flag;
flag = 1;
redirects = NULL;
current = list;
token = (t_token *)current->content;
while (current && flag && !redirect_is_delimiter(token))
{
token = (t_token *)current->content;
if (token->type != T_REDIRECT_OUT && token->type != T_APPEND_OUT)
{
current = current->next;
continue ;
}
flag = redirect_is_valid(current, token, -1);
redirect_create(msh, &current, &redirects, token->type);
current = current->next;
}
if (flag <= 0)
redirect_new_error(msh, &redirects);
return (redirects);
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirect_get_outputs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/23 12:37:24 by Quinten #+# #+# */
/* Updated: 2025/02/27 18:10:57 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_list *redirect_get_outputs(t_minishell *msh, t_list *list)
{
t_list *current;
t_list *redirects;
t_token *token;
int flag;
flag = 1;
redirects = NULL;
current = list;
token = (t_token *)current->content;
while (current && !redirect_is_delimiter(token))
{
token = (t_token *)current->content;
if (token->type != T_REDIRECT_OUT && token->type != T_APPEND_OUT)
{
current = current->next;
continue;
}
flag = redirect_is_valid(current, token, -1);
flag && (redirect_create(msh, &current, &redirects, token->type));
current = current->next;
}
redirect_new_error(msh, &redirects, flag);
return (redirects);
}

View File

@ -1,44 +1,45 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* redirect_new.c :+: :+: */
/* +:+ */
/* By: Quinten <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/23 12:27:33 by Quinten #+# #+# */
/* Updated: 2025/02/23 12:27:33 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value)
{
t_redirect *result;
result = malloc_safe(msh, sizeof(t_redirect));
result->type = type;
result->value = NULL;
if (value)
result->value = value;
return (result);
}
void redirect_create(t_minishell *msh, t_list **tokens, t_list **redirects,
t_token_type type)
{
t_list *new;
t_redirect *redir;
t_token *file_token;
char *file_name;
file_token = (t_token *)((*tokens)->next->content);
file_name = NULL;
if (file_token)
file_name = ft_strdup_safe(msh, file_token->value);
redir = redirect_new(msh, type, file_name);
new = ft_lstnew_safe(msh, redir);
ft_lstadd_back(redirects, new);
if (tokens)
*tokens = (*tokens)->next;
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirect_new.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/23 12:27:33 by Quinten #+# #+# */
/* Updated: 2025/02/27 18:11:25 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value)
{
t_redirect *result;
result = malloc_safe(msh, sizeof(t_redirect));
result->type = type;
result->value = NULL;
if (value)
result->value = value;
return (result);
}
int redirect_create(t_minishell *msh, t_list **tokens, t_list **redirects,
t_token_type type)
{
t_list *new;
t_redirect *redir;
t_token *file_token;
char *file_name;
file_token = (t_token *)((*tokens)->next->content);
file_name = NULL;
if (file_token)
file_name = ft_strdup_safe(msh, file_token->value);
redir = redirect_new(msh, type, file_name);
new = ft_lstnew_safe(msh, redir);
ft_lstadd_back(redirects, new);
if (tokens)
*tokens = (*tokens)->next;
return (1);
}

View File

@ -6,17 +6,19 @@
/* 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 */
/* Updated: 2025/02/27 18:07:25 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void redirect_new_error(t_minishell *msh, t_list **redirects)
void redirect_new_error(t_minishell *msh, t_list **redirects, int flag)
{
t_list *new;
t_redirect *redir;
if (flag)
return ;
redir = redirect_new(msh, T_ERROR, NULL);
new = ft_lstnew_safe(msh, redir);
ft_lstadd_back(redirects, new);