working on bonus execution

This commit is contained in:
mdev9
2024-03-30 18:58:39 +01:00
parent eda077e34b
commit bd6fba08fe
11 changed files with 190 additions and 86 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
/* Updated: 2024/03/28 13:26:42 by tomoron ### ########.fr */
/* Updated: 2024/03/30 17:09:09 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,53 +27,52 @@ void redirect_input(t_msh *msh, int i)
}
}
void open_input_file(t_msh *msh, t_token **cur_cmd)
void open_input_file(t_msh *msh, t_token **cur_token)
{
if ((*cur_cmd)->type == HERE_DOC)
handle_here_doc(msh, (*cur_cmd)->next->value);
if ((*cur_cmd)->type == RED_I)
if ((*cur_token)->type == HERE_DOC)
handle_here_doc(msh, (*cur_token)->next->value);
if ((*cur_token)->type == RED_I)
{
if (msh->in_fd != 0)
close(msh->in_fd);
msh->in_fd = open((*cur_cmd)->next->value, O_RDONLY);
msh->in_fd = open((*cur_token)->next->value, O_RDONLY);
if (msh->in_fd == -1 && !g_return_code)
{
ft_printf_fd(2, "minishell: %s: ", (*cur_cmd)->next->value);
ft_printf_fd(2, "minishell: %s: ", (*cur_token)->next->value);
perror("");
g_return_code = 1;
}
}
}
void get_in_type(t_msh *msh, t_token *cmds)
void get_in_type(t_msh *msh, t_token *tokens)
{
t_token *cur_cmd;
t_token *cur_token;
cur_cmd = cmds;
while (cur_cmd && cur_cmd->next && cur_cmd->type == ARG)
cur_cmd = cur_cmd->next;
if (cur_cmd->type)
cur_token = tokens;
while (cur_token && cur_token->next && cur_token->type == ARG)
cur_token = cur_token->next;
if (cur_token->type)
{
msh->in_type = cur_cmd->type;
if (cur_cmd->type == HERE_DOC || cur_cmd->type == RED_I)
open_input_file(msh, &cur_cmd);
msh->in_type = cur_token->type;
if (cur_token->type == HERE_DOC || cur_token->type == RED_I)
open_input_file(msh, &cur_token);
}
while (cur_cmd && cur_cmd->next && cur_cmd->next->type == ARG)
cur_cmd = cur_cmd->next;
if (cur_cmd->next && (cur_cmd->next->type == HERE_DOC
|| cur_cmd->next->type == RED_I))
get_in_type(msh, cur_cmd);
while (cur_token && cur_token->next && cur_token->next->type == ARG)
cur_token = cur_token->next;
if (cur_token->next && (cur_token->next->type == HERE_DOC
|| cur_token->next->type == RED_I))
get_in_type(msh, cur_token);
}
int first_is_in_type(t_msh *msh)
{
t_token *cur_cmd;
t_token *cur_token;
cur_cmd = msh->cmds;
while (cur_cmd && cur_cmd->type == ARG && cur_cmd->next)
cur_cmd = cur_cmd->next;
if (/*cur_cmd->type == PIPE || */cur_cmd->type == RED_I
|| cur_cmd->type == HERE_DOC)
cur_token = msh->tokens;
while (cur_token && cur_token->type == ARG && cur_token->next)
cur_token = cur_token->next;
if (cur_token->type == RED_I || cur_token->type == HERE_DOC)
return (1);
return (0);
}