fixed echo and some return code issues from redirections

This commit is contained in:
mdev9
2024-03-04 13:04:33 +01:00
parent 6d02d62f94
commit e3d93a1262
2 changed files with 10 additions and 9 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */ /* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
/* Updated: 2024/03/04 11:17:02 by marde-vr ### ########.fr */ /* Updated: 2024/03/04 13:02:28 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,8 +16,10 @@
int echo(t_cmd *args) int echo(t_cmd *args)
{ {
int put_nl; int put_nl;
int first;
put_nl = 1; put_nl = 1;
first = 1;
while (args && args->token && !strcmp(args->token, "-n")) while (args && args->token && !strcmp(args->token, "-n"))
{ {
put_nl = 0; put_nl = 0;
@ -29,16 +31,14 @@ int echo(t_cmd *args)
args = args->next; args = args->next;
else else
{ {
ft_putstr_fd(args->token, STDOUT_FILENO); if (!first)
if (args->next)
{
ft_printf_fd(2, "yes\n");
ft_putchar_fd(' ', STDOUT_FILENO); ft_putchar_fd(' ', STDOUT_FILENO);
} ft_putstr_fd(args->token, STDOUT_FILENO);
first = 0;
} }
args = args->next; args = args->next;
} }
if (put_nl) if (put_nl && !first)
ft_putchar_fd('\n', STDOUT_FILENO); ft_putchar_fd('\n', STDOUT_FILENO);
return (0); return (0);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */ /* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
/* Updated: 2024/03/04 11:03:53 by marde-vr ### ########.fr */ /* Updated: 2024/03/04 13:00:21 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -375,7 +375,7 @@ void get_in_type(t_msh *msh, t_cmd *cmds)
close(msh->in_fd); close(msh->in_fd);
msh->in_fd = open(cur_cmd->next->token, O_RDONLY); msh->in_fd = open(cur_cmd->next->token, O_RDONLY);
//ft_printf_fd(2, "opened %s: %d\n", cur_cmd->next->token, msh->in_fd); //ft_printf_fd(2, "opened %s: %d\n", cur_cmd->next->token, msh->in_fd);
if (msh->in_fd == -1) if (msh->in_fd == -1 && !g_return_code)
{ {
ft_printf_fd(2, "minishell: %s: ", cur_cmd->next->token); ft_printf_fd(2, "minishell: %s: ", cur_cmd->next->token);
perror(""); perror("");
@ -440,6 +440,7 @@ void exec_command(t_msh *msh)
ft_exit(msh, 1); ft_exit(msh, 1);
while (i < cmd_count) while (i < cmd_count)
{ {
g_return_code = 0;
msh->fds[i] = ft_calloc(2, sizeof(int *)); msh->fds[i] = ft_calloc(2, sizeof(int *));
if (!msh->fds[i]) if (!msh->fds[i])
ft_exit(msh, 1); ft_exit(msh, 1);