/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* parser.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; } }