fix 0 with cat | ls

This commit is contained in:
kinou-p 2022-04-15 00:21:36 +02:00
parent cc07376040
commit 0413133db9
4 changed files with 27 additions and 23 deletions

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 22:33:49 by apommier #+# #+# */ /* Created: 2022/03/09 22:33:49 by apommier #+# #+# */
/* Updated: 2022/04/14 10:30:52 by apommier ### ########.fr */ /* Updated: 2022/04/15 00:20:25 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,18 +33,18 @@
// Describes a simple command and arguments // Describes a simple command and arguments
typedef struct s_simple { typedef struct s_simple {
struct s_command *big_cmd; struct s_command *big_cmd;
int fd[2]; int fd[2];
int pipe[2]; int pipe[2];
int last; int last;
int last_pipe[2]; int last_pipe[2];
int child; int child;
int nb_args; int nb_args;
char *infile; char *infile;
int in_type; int in_type;
int out_type; int out_type;
char *outfile; char *outfile;
char **args; char **args;
char *cmd; char *cmd;
} t_s_cmd; } t_s_cmd;
// Describes a complete command with the multiple pipes if any // Describes a complete command with the multiple pipes if any
@ -58,7 +58,6 @@ typedef struct s_command {
int err_var; int err_var;
struct s_simple *current_s_cmd; struct s_simple *current_s_cmd;
char **path; char **path;
int pid;
} t_cmd; } t_cmd;
//main.c //main.c
@ -87,6 +86,7 @@ char **ft_split_with_quote(char const *s, char c);
//signals //signals
void crtl_c(int num); void crtl_c(int num);
void sig_heredoc(int num);
//redirection.c set redirection and input good //redirection.c set redirection and input good
char *set_redirection(t_s_cmd *cmd, char *line, int index); char *set_redirection(t_s_cmd *cmd, char *line, int index);
@ -96,7 +96,7 @@ char next_space(char *str, int i);
int parse_quote(t_cmd *cmd); int parse_quote(t_cmd *cmd);
char *get_str(char *str, int start, int end); char *get_str(char *str, int start, int end);
char *cut_str(char *str, int start, int end); char *cut_str(char *str, int start, int end);
int double_size(char **tab); int double_size(char **tab);
void print_double_fd(char **tab, int fd); void print_double_fd(char **tab, int fd);
void free_double(char **tab); void free_double(char **tab);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */ /* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
/* Updated: 2022/04/14 10:35:08 by apommier ### ########.fr */ /* Updated: 2022/04/15 00:13:24 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,7 +53,7 @@ void print_prompt(char **path)
{ {
char *input; char *input;
t_cmd *cmd; t_cmd *cmd;
int i; int i;
input = 0; input = 0;
i = 0; i = 0;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/02 18:51:31 by apommier #+# #+# */ /* Created: 2022/04/02 18:51:31 by apommier #+# #+# */
/* Updated: 2022/04/14 11:27:29 by apommier ### ########.fr */ /* Updated: 2022/04/15 00:14:04 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -47,19 +47,23 @@ int wait_exit(t_cmd *cmd)
{ {
close(cmd->s_cmds[i]->fd[0]); close(cmd->s_cmds[i]->fd[0]);
close(cmd->s_cmds[i]->fd[1]); close(cmd->s_cmds[i]->fd[1]);
}
if (WIFEXITED(status)) if (WIFEXITED(status))
{ {
if (!cmd->err_var) //printf("return normally cmd = -%s-\n", cmd->s_cmds[i]->cmd);
cmd->err_var = WEXITSTATUS(status); //if (!cmd->err_var)
cmd->err_var = WEXITSTATUS(status);
//printf("err_var= %d\n", cmd->err_var);
//printf("code= %d\n", cmd->err_var); //printf("code= %d\n", cmd->err_var);
} }
else if (WIFSIGNALED(status)) else if (WIFSIGNALED(status))
{ {
cmd->err_var = WTERMSIG(status); //printf("return by signal cmd = -%s-\n", cmd->s_cmds[i]->cmd);
if (WTERMSIG(status) != 13)
cmd->err_var = WTERMSIG(status);
//if (cmd->err_var == 2) //if (cmd->err_var == 2)
ft_putstr_fd("\b\b\b\b\b", 1); ft_putstr_fd("\b\b\b\b\b", 1);
} }
}
i++; i++;
} }
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */ /* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
/* Updated: 2022/04/14 11:28:30 by apommier ### ########.fr */ /* Updated: 2022/04/15 00:13:27 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */