des trucs

This commit is contained in:
2024-04-02 17:55:30 +02:00
parent b4c9665dd3
commit c9bd04d42c
6 changed files with 55 additions and 19 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/04/02 13:28:32 by babonnet ### ########.fr */
/* Updated: 2024/04/02 17:40:33 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,13 +29,19 @@ void redirect_input(t_msh *msh)
void open_input_file(t_msh *msh, t_cmd **cur_token)
{
t_token *filename;
if ((*cur_token)->cmd_type == HERE_DOC)
handle_here_doc(msh, (*cur_token)->next->value);
handle_here_doc(msh, (*cur_token)->value);
if ((*cur_token)->cmd_type == RED_I)
{
if (msh->in_fd != 0)
close(msh->in_fd);
msh->in_fd = open((*cur_token)->next->value, O_RDONLY);
filename = parse_command((*cur_token)->value, msh->env);
if(!filename)
ft_exit(msh, 1);
msh->in_fd = open(filename->value, O_RDONLY);
free_token(filename);
if (msh->in_fd == -1 && !g_return_code)
{
ft_printf_fd(2, "minishell: %s: ", (*cur_token)->next->value);
@ -50,17 +56,14 @@ void get_in_type(t_msh *msh, t_cmd *tokens)
t_cmd *cur_token;
cur_token = tokens;
while (cur_token && cur_token->next && cur_token->cmd_type == CMD)
while (cur_token && (cur_token->cmd_type == CMD || cur_token->cmd_type == PAREN))
cur_token = cur_token->next;
if (/*cur_token->type && */cur_token->cmd_type == HERE_DOC || cur_token->cmd_type == RED_I)
if (cur_token && is_input_type(cur_token))
{
msh->in_type = cur_token->cmd_type;
open_input_file(msh, &cur_token);
}
while (cur_token && cur_token->next && cur_token->next->cmd_type == CMD)
cur_token = cur_token->next;
if (cur_token->next && (cur_token->next->cmd_type == HERE_DOC
|| cur_token->next->cmd_type == RED_I))
if(cur_token && cur_token->next && !is_operand_type(cur_token->next))
get_in_type(msh, cur_token);
}
@ -71,7 +74,7 @@ int first_is_in_type(t_cmd *cmd)
cur_token = cmd;
while (cur_token && cur_token->cmd_type == CMD && cur_token->next)
cur_token = cur_token->next;
if (cur_token->cmd_type == RED_I || cur_token->cmd_type == HERE_DOC)
if ( is_input_type(cur_token) || cur_token->cmd_type == PIPE)
return (1);
return (0);
}