add: add ctrl + C support, but not work in heredoc

This commit is contained in:
Camille Chauvet 2023-02-22 00:26:32 +01:00
parent 2b66ce5bc3
commit 94f48602d1
4 changed files with 13 additions and 10 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */ /* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
/* Updated: 2023/02/21 22:26:54 by cchauvet ### ########.fr */ /* Updated: 2023/02/21 23:34:37 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -108,7 +108,7 @@ static int ft_own_cmd(t_list **env, t_cmd *cmd)
else if (ft_strcmp(cmd->executable, "export") == 0) else if (ft_strcmp(cmd->executable, "export") == 0)
return_code = (print_export(env, cmd->fd_out)); return_code = (print_export(env, cmd->fd_out));
else if (ft_strcmp(cmd->executable, "cd") == 0) else if (ft_strcmp(cmd->executable, "cd") == 0)
return_code = (move_folder(cmd->args[0], cmd->fd_out)); return_code = (move_folder(cmd->args[1], cmd->fd_out));
/* if (ft_strcmp(cmd->executable, "unset") == 0) */ /* if (ft_strcmp(cmd->executable, "unset") == 0) */
/* return_code = (unset(env, cmd->args, cmd->fd_out)); */ /* return_code = (unset(env, cmd->args, cmd->fd_out)); */
else if (ft_strcmp(cmd->executable, "echo") == 0) else if (ft_strcmp(cmd->executable, "echo") == 0)

11
main.c
View File

@ -10,10 +10,7 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h" #include "minishell.h"
#include "utils/utils.h"
#include <stdlib.h>
static char *ft_get_user_input(t_list **env) static char *ft_get_user_input(t_list **env)
{ {
@ -104,11 +101,19 @@ int main(int ac, char **av, char **env)
#else #else
void ft_ctrlc(int num)
{
rl_on_new_line();
ft_putchar_fd('\n', 1);
rl_redisplay();
}
int main(int ac, char **av, char **env) int main(int ac, char **av, char **env)
{ {
t_data data; t_data data;
char *line; char *line;
signal(SIGINT, ft_ctrlc);
data.env = init_env(env); data.env = init_env(env);
if (data.env == NULL) if (data.env == NULL)
return (1); return (1);

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */ /* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */
/* Updated: 2023/02/21 13:00:06 by cchauvet ### ########.fr */ /* Updated: 2023/02/21 23:40:20 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@ static int ft_quote_verif(const char *str)
{ {
if (ft_is_in_quote(str, ft_strlen(str))) if (ft_is_in_quote(str, ft_strlen(str)))
{ {
ft_eprintf("minishell: Quote is note closed"); ft_eprintf("minishell: Quote is not closed\n");
return (1); return (1);
} }
else else
@ -78,7 +78,7 @@ static int ft_special_char_dub(const char *str)
if ((y > 2 && (str[i] == '>' || str[i] == '<')) if ((y > 2 && (str[i] == '>' || str[i] == '<'))
|| (y > 1 && str[i] == '|')) || (y > 1 && str[i] == '|'))
{ {
ft_eprintf("minishell: to many %c in a row", str, str[i]); ft_eprintf("minishell: too many %c in a row\n", str, str[i]);
return (1); return (1);
} }
i = i + y; i = i + y;
@ -96,8 +96,6 @@ int ft_empty_verif(const char *str)
i = 0; i = 0;
while (str[i] == ' ') while (str[i] == ' ')
i++; i++;
if (str[i] == '\0')
ft_eprintf("minishell: %s: command not found \n", str);
return (str[i] == '\0'); return (str[i] == '\0');
} }