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.

73 lines
1.8 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 16:09:25 by narnaud #+# #+# */
3 years ago
/* Updated: 2022/05/03 12:43:48 by narnaud ### ########.fr */
3 years ago
/* */
/* ************************************************************************** */
#include "minishell.h"
void push_heredoc(char *str, int fd)
{
char *line;
while(1)
{
line = readline(">");
if (!ft_strncmp(line, str, ft_strlen(str) + 1))
break;
ft_putstr_fd(line, fd);
write(fd, "\n", 1);
}
}
3 years ago
size_t count_arguments(t_token *tok)
{
size_t ret;
ret = 0;
3 years ago
while (tok && tok->type != PIPE)
3 years ago
{
3 years ago
if (!tok->type)
3 years ago
ret++;
3 years ago
tok = tok->next;
3 years ago
}
return (ret);
}
void update_redir(t_command *cmd, t_token *tok)
{
if (tok->type == OUT)
{
if (cmd->fd[1])
close(cmd->fd[1]);
cmd->fd[1] = open(tok->value, O_CREAT | O_TRUNC | O_WRONLY, 0644);
3 years ago
}
else if (tok->type == ADD)
{
if (cmd->fd[1])
close(cmd->fd[1]);
cmd->fd[1] = open(tok->value, O_CREAT | O_APPEND | O_WRONLY, 0644);
3 years ago
}
else if (tok->type == IN)
{
if (cmd->fd[0])
close(cmd->fd[0]);
cmd->fd[0] = open(tok->value, O_RDONLY);
3 years ago
}
else if (tok->type == HD)
{
if (cmd->fd[0])
close(cmd->fd[0]);
cmd->fd[0] = 0;
cmd->heredoc = tok->value;
}
}