clean: norm
This commit is contained in:
parent
e65a9f32c0
commit
be1f7ebf8c
28
cmd/cmd.c
28
cmd/cmd.c
@ -6,10 +6,11 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/31 16:31:41 by alouis-j ### ########.fr */
|
/* Updated: 2023/04/07 15:04:04 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cmd.h"
|
||||||
#include "cmd_private.h"
|
#include "cmd_private.h"
|
||||||
|
|
||||||
void ft_cmddel(void *ptr)
|
void ft_cmddel(void *ptr)
|
||||||
@ -40,3 +41,28 @@ void ft_cmdcloser(void *ptr)
|
|||||||
ft_closer(cmd->fd_in);
|
ft_closer(cmd->fd_in);
|
||||||
ft_closer(cmd->fd_out);
|
ft_closer(cmd->fd_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ft_cmdwaiter(void *ptr)
|
||||||
|
{
|
||||||
|
t_cmd *cmd;
|
||||||
|
int exit_status;
|
||||||
|
|
||||||
|
cmd = ptr;
|
||||||
|
if (cmd->executable != NULL && cmd->own_cmd == 0
|
||||||
|
&& cmd->pid != -1 && cmd->fd_in[0] != -2 && cmd->fd_out[0] != -2)
|
||||||
|
{
|
||||||
|
waitpid(cmd->pid, &exit_status, 0);
|
||||||
|
if (WIFSIGNALED(exit_status))
|
||||||
|
{
|
||||||
|
if (exit_status == 131)
|
||||||
|
{
|
||||||
|
ft_printf("Quit (core dumped)\n");
|
||||||
|
*ft_get_exit_code() = 131;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*ft_get_exit_code() = 130;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*ft_get_exit_code() = WEXITSTATUS(exit_status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/28 15:47:01 by cchauvet #+# #+# */
|
/* Created: 2023/03/28 15:47:01 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/31 16:32:14 by alouis-j ### ########.fr */
|
/* Updated: 2023/04/07 15:03:53 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,6 +26,7 @@ typedef struct s_cmd
|
|||||||
} t_cmd;
|
} t_cmd;
|
||||||
|
|
||||||
void ft_cmddel(void *content);
|
void ft_cmddel(void *content);
|
||||||
|
void ft_cmdwaiter(void *content);
|
||||||
void ft_cmdcloser(void *ptr);
|
void ft_cmdcloser(void *ptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
39
main.c
39
main.c
@ -6,13 +6,14 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
|
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/04/05 15:31:19 by alouis-j ### ########.fr */
|
/* Updated: 2023/04/07 15:04:12 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "data/data.h"
|
#include "data/data.h"
|
||||||
#include "env/env.h"
|
#include "env/env.h"
|
||||||
#include "libftx/libft/libft.h"
|
#include "libftx/libft/libft.h"
|
||||||
|
#include "libftx/libft/list.h"
|
||||||
#include "libftx/libftx.h"
|
#include "libftx/libftx.h"
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
#include "signal/signal.h"
|
#include "signal/signal.h"
|
||||||
@ -43,40 +44,6 @@ static char *ft_get_user_input(void)
|
|||||||
return (line);
|
return (line);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ft_cmds_waiter(t_data *data)
|
|
||||||
{
|
|
||||||
t_list *current;
|
|
||||||
t_cmd *cmd;
|
|
||||||
int exit_status;
|
|
||||||
|
|
||||||
current = *data->cmds;
|
|
||||||
while (current != NULL)
|
|
||||||
{
|
|
||||||
cmd = current->content;
|
|
||||||
if (cmd->executable != NULL && cmd->own_cmd == 0
|
|
||||||
&& cmd->pid != -1 && cmd->fd_in[0] != -2 && cmd->fd_out[0] != -2)
|
|
||||||
{
|
|
||||||
waitpid(cmd->pid, &exit_status, 0);
|
|
||||||
if (WIFSIGNALED(exit_status))
|
|
||||||
{
|
|
||||||
if (exit_status == 131)
|
|
||||||
{
|
|
||||||
ft_printf("Quit (core dumped)\n");
|
|
||||||
*data->exit_code = 131;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ft_putchar_fd('\n', 1);
|
|
||||||
*data->exit_code = 130;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*data->exit_code = WEXITSTATUS(exit_status);
|
|
||||||
}
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_minishell(t_data *data, char *line)
|
static int ft_minishell(t_data *data, char *line)
|
||||||
{
|
{
|
||||||
char *line_clean;
|
char *line_clean;
|
||||||
@ -94,7 +61,7 @@ static int ft_minishell(t_data *data, char *line)
|
|||||||
free(line_clean);
|
free(line_clean);
|
||||||
if (ft_cmds_executor(data) == 1)
|
if (ft_cmds_executor(data) == 1)
|
||||||
return (1);
|
return (1);
|
||||||
ft_cmds_waiter(data);
|
ft_lstiter(*data->cmds, ft_cmdwaiter);
|
||||||
ft_lstclear(data->cmds, ft_cmddel);
|
ft_lstclear(data->cmds, ft_cmddel);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/29 17:32:06 by cchauvet #+# #+# */
|
/* Created: 2023/03/29 17:32:06 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/04/05 14:53:18 by alouis-j ### ########.fr */
|
/* Updated: 2023/04/07 15:06:39 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./redirection_private.h"
|
#include "./redirection_private.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
static bool ft_check_heredoc(t_data *data, t_cmd *cmd,
|
static bool ft_check_heredoc(t_data *data, t_cmd *cmd,
|
||||||
char *redirection_identifier, char *redirection)
|
char *redirection_identifier, char *redirection)
|
||||||
@ -120,8 +121,10 @@ bool ft_check_redirection(t_data *data, t_cmd *cmd,
|
|||||||
char *redirection_identifier, char *redirection)
|
char *redirection_identifier, char *redirection)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
|
bool out;
|
||||||
|
|
||||||
if (ft_is_in("<>", redirection_identifier[0]) && ft_is_in("<>", redirection[0]))
|
if (ft_is_in("<>", redirection_identifier[0])
|
||||||
|
&& ft_is_in("<>", redirection[0]))
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: %s: invalid redirection file\n", redirection);
|
ft_eprintf("minishell: %s: invalid redirection file\n", redirection);
|
||||||
return (1);
|
return (1);
|
||||||
@ -133,16 +136,12 @@ bool ft_check_redirection(t_data *data, t_cmd *cmd,
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
ft_quote_remover(str);
|
ft_quote_remover(str);
|
||||||
|
out = 0;
|
||||||
if (ft_check_heredoc(data, cmd, redirection_identifier, str)
|
if (ft_check_heredoc(data, cmd, redirection_identifier, str)
|
||||||
|| ft_check_infile(data, cmd, redirection_identifier, str)
|
|| ft_check_infile(data, cmd, redirection_identifier, str)
|
||||||
|| ft_check_outfile(data, cmd, redirection_identifier, str)
|
|| ft_check_outfile(data, cmd, redirection_identifier, str)
|
||||||
|| ft_check_outfile_append(data, cmd, redirection_identifier,
|
|| ft_check_outfile_append(data, cmd, redirection_identifier, str))
|
||||||
str))
|
out = 1;
|
||||||
{
|
|
||||||
free(str);
|
free(str);
|
||||||
return (1);
|
return (out);
|
||||||
}
|
|
||||||
;
|
|
||||||
free(str);
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/04/05 14:58:01 by alouis-j ### ########.fr */
|
/* Updated: 2023/04/07 15:11:17 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -31,14 +31,8 @@ static int ft_format_and_write(t_data *data, const char *str, int fd)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ft_heredoc2(t_data *data, char *stop, int fds[2])
|
static int ft_heredoc3(char *stop, int fds[2])
|
||||||
{
|
{
|
||||||
char *line;
|
|
||||||
|
|
||||||
ft_printf("> ");
|
|
||||||
line = get_next_line(*ft_get_heredoc());
|
|
||||||
if (line == NULL)
|
|
||||||
{
|
|
||||||
if (*ft_get_heredoc() == -1)
|
if (*ft_get_heredoc() == -1)
|
||||||
{
|
{
|
||||||
ft_putchar_fd('\n', 1);
|
ft_putchar_fd('\n', 1);
|
||||||
@ -47,9 +41,25 @@ static int ft_heredoc2(t_data *data, char *stop, int fds[2])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: warning: here-document at line 1 delimited by end-of-file (wanted `%s')\n", stop);
|
ft_eprintf("minishell: warning: here-document at line");
|
||||||
|
ft_eprintf("1 delimited by end-of-file (wanted `%s')\n", stop);
|
||||||
return (2);
|
return (2);
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ft_heredoc2(t_data *data, char *stop, int fds[2])
|
||||||
|
{
|
||||||
|
char *line;
|
||||||
|
int out;
|
||||||
|
|
||||||
|
ft_printf("> ");
|
||||||
|
line = get_next_line(*ft_get_heredoc());
|
||||||
|
if (line == NULL)
|
||||||
|
{
|
||||||
|
out = ft_heredoc3(stop, fds);
|
||||||
|
if (out)
|
||||||
|
return (out);
|
||||||
}
|
}
|
||||||
line[ft_strlen(line) - 1] = '\0';
|
line[ft_strlen(line) - 1] = '\0';
|
||||||
if (ft_strcmp(line, stop) == 0)
|
if (ft_strcmp(line, stop) == 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user