🏗️」 wip: Work in progress

This commit is contained in:
2024-06-18 12:21:40 +02:00
parent f70c506fed
commit 6ae7296237
13 changed files with 270 additions and 42 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 10:48:41 by adjoly #+# #+# */
/* Updated: 2024/05/31 19:16:41 by adjoly ### ########.fr */
/* Updated: 2024/06/04 15:35:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,48 +18,55 @@
t_cmd *get_redir_fd(void *content)
{
t_token *token;
t_list *tmp;
t_redirection *tmp_redir;
t_redirection out;
t_redirection in;
t_cmd *cmd;
t_token *token;
t_list *tmp;
t_redirection *tmp_redir;
t_redirection_sign out;
t_redirection_sign in;
t_cmd *cmd;
token = (t_token *)content;
tmp = token->redirection;
cmd = NULL;
out.sign = INFILE;
in.sign = OUTFILE;
out = INFILE;
in = OUTFILE;
cmd = ft_calloc(sizeof(t_cmd), 1);
while (tmp)
{
tmp_redir = (t_redirection *)tmp->content;
if (tmp_redir->sign == (t_redirection_sign)HEREDOC)
{
in.file_name = NULL;
in.sign = HEREDOC;
close(cmd->infile);
if (cmd->infile != 0)
close(cmd->infile);
in = HEREDOC;
cmd->infile = ft_heredoc(tmp_redir->file_name);
}
else if (tmp_redir->sign == INFILE)
{
in.sign = INFILE;
in.file_name = tmp_redir->file_name;
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);
}
tmp = tmp->next;
}
if (in.sign == OUTFILE)
if (in == OUTFILE)
cmd->infile = STDIN_FILENO;
else if (in.sign == INFILE)
{
cmd->infile = open(in.file_name, O_RDONLY);
ft_putendl_fd(in.file_name, STDOUT_FILENO);
}
if (out.sign == INFILE)
if (out == INFILE)
cmd->outfile = STDOUT_FILENO;
cmd = split_cmd(token->argv, cmd);
return (cmd);