」 feat: Did a lot of things, don't know what but it work

This commit is contained in:
2024-06-30 18:03:58 +02:00
parent 3d7669d056
commit f0c0830c4d
19 changed files with 188 additions and 111 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 10:48:41 by adjoly #+# #+# */
/* Updated: 2024/06/29 15:32:44 by adjoly ### ########.fr */
/* Updated: 2024/06/30 17:34:47 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,63 +14,30 @@
#include "tokenizer.h"
#include "execution.h"
#include <fcntl.h>
#include "minishell.h"
#include <stdio.h>
#include "libft.h"
t_cmd *get_redir_fd(void *content, t_env *env)
t_cmd *get_redir_fd(void *content)
{
t_token *token;
t_list *tmp;
t_redirection *tmp_redir;
t_redirection_sign out;
t_redirection_sign in;
t_cmd *cmd;
t_list *tmp;
t_redir_sign sign[2];
t_cmd *cmd;
(void)env;
token = (t_token *)content;
tmp = token->redirection;
tmp = ((t_token *)content)->redirection;
cmd = NULL;
out = INFILE;
in = OUTFILE;
sign[0] = INFILE;
sign[1] = OUTFILE;
cmd = ft_calloc(sizeof(t_cmd), 1);
while (tmp)
{
tmp_redir = (t_redirection *)tmp->content;
if (tmp_redir->sign == (t_redirection_sign)HEREDOC)
{
if (cmd->infile != 0)
close(cmd->infile);
in = HEREDOC;
cmd->infile = ft_heredoc(tmp_redir->file_name);
}
else if (tmp_redir->sign == INFILE)
{
if (cmd->infile != 0)
close(cmd->infile);
cmd->infile = open(tmp_redir->file_name, O_RDONLY);
in = INFILE;
}
else if (tmp_redir->sign == OUTFILE)
{
if (cmd->infile != 0)
close(cmd->outfile);
out = OUTFILE;
cmd->outfile = open(tmp_redir->file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644);
}
else if (tmp_redir->sign == OUT_APPEND)
{
if (cmd->infile != 0)
close(cmd->outfile);
out = OUT_APPEND;
cmd->outfile = open(tmp_redir->file_name, O_CREAT | O_APPEND | O_WRONLY, 0644);
}
open_redir((t_redirection *)tmp->content, cmd, sign);
tmp = tmp->next;
}
if (in == OUTFILE)
cmd->infile = STDIN_FILENO;
if (out == INFILE)
if (sign[0] == INFILE)
cmd->outfile = STDOUT_FILENO;
// char *ll = env_var_replace(token->argv, env);
cmd = split_cmd(token->argv, cmd);
if (sign[1] == OUTFILE)
cmd->infile = STDIN_FILENO;
cmd = split_cmd(((t_token *)content)->argv, cmd);
return (cmd);
}