You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

61 lines
1.7 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 16:09:25 by narnaud #+# #+# */
/* Updated: 2022/05/02 17:43:27 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
size_t count_arguments(t_token *tok)
{
size_t ret;
ret = 0;
while (tok->value)
{
if (tok->type == WORD && tok->value[0] != '|')
ret++;
if (tok->next)
tok = tok->next;
else
break ;
}
return (ret);
}
void update_redir(t_command *cmd, t_token *tok)
{
if (tok->type == OUT)
{
if (cmd->fd[1])
close(cmd->fd[1]);
cmd->output = init_file(tok->value, O_TRUNC | O_WRONLY);
}
else if (tok->type == ADD)
{
if (cmd->fd[1])
close(cmd->fd[1]);
cmd->fd[1] = init_file(tok->value, O_APPEND | O_WRONLY);
}
else if (tok->type == IN)
{
if (cmd->fd[0])
close(cmd->fd[0]);
cmd->fd[0] = init_file(tok->value, O_RDONLY);
}
else if (tok->type == HD)
{
if (cmd->fd[0])
close(cmd->fd[0]);
cmd->fd[0] = 0;
cmd->heredoc = tok->value;
}
}