signaux
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/03/25 19:14:46 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/25 20:38:21 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -85,7 +85,6 @@ void get_here_doc_input(t_msh *msh, char *eof)
|
||||
|
||||
line = NULL;
|
||||
signal(SIGINT, signal_handler_here_doc);
|
||||
signal(SIGQUIT, signal_handler_here_doc);
|
||||
while (1)
|
||||
{
|
||||
free(line);
|
||||
@ -131,7 +130,7 @@ void handle_here_doc(t_msh *msh, char *eof)
|
||||
else
|
||||
{
|
||||
signal(SIGINT, signal_handler_command);
|
||||
signal(SIGQUIT, signal_handler_command);
|
||||
signal(SIGQUIT, signal_handler_here_doc);
|
||||
waitpid(pid, &status , 0);
|
||||
signal(SIGINT, signal_handler_interactive);
|
||||
signal(SIGQUIT, signal_handler_interactive);
|
||||
|
30
srcs/main.c
30
srcs/main.c
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/25 13:19:26 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/25 20:04:03 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -71,8 +71,31 @@ t_env *get_env(char **envp)
|
||||
return (env);
|
||||
}
|
||||
|
||||
void print_binary(unsigned int num)
|
||||
{
|
||||
if (num == 0) {
|
||||
printf("0");
|
||||
return;
|
||||
}
|
||||
|
||||
// Taille d'un unsigned int en bits
|
||||
int size = sizeof(unsigned int) * 8;
|
||||
int i;
|
||||
|
||||
// Parcours de chaque bit de droite à gauche
|
||||
for (i = size - 1; i >= 0; i--) {
|
||||
// Vérifie si le bit est 1 ou 0
|
||||
if (num & (1u << i))
|
||||
printf("1");
|
||||
else
|
||||
printf("0");
|
||||
}
|
||||
}
|
||||
|
||||
int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
|
||||
{
|
||||
struct termios t_p;
|
||||
|
||||
*msh = ft_calloc(1, sizeof(t_msh));
|
||||
if (!*msh)
|
||||
ft_exit(*msh, 1);
|
||||
@ -81,6 +104,11 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
|
||||
(*msh)->env = get_env(envp);
|
||||
signal(SIGINT, signal_handler_interactive);
|
||||
signal(SIGQUIT, signal_handler_interactive);
|
||||
if(tcgetattr(1, &t_p))
|
||||
ft_printf_fd(2, "an error occured while setting the flags");
|
||||
t_p.c_lflag = t_p.c_lflag & (~ECHOCTL);
|
||||
if(tcsetattr(1, TCSANOW, &t_p))
|
||||
ft_printf_fd(2, "an error occured while setting the flags");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/25 18:42:00 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/25 19:37:11 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
# include <sys/stat.h>
|
||||
# include <signal.h>
|
||||
# include <stdint.h>
|
||||
# include <termios.h>
|
||||
|
||||
typedef enum e_token_type
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/25 19:10:39 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/25 20:39:21 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,19 +14,16 @@
|
||||
|
||||
void signal_handler_interactive(int signum)
|
||||
{
|
||||
if (signum == 2)
|
||||
if (signum == SIGINT)
|
||||
{
|
||||
g_return_code = 130;
|
||||
ft_putstr_fd("\n", 1);
|
||||
printf("%s%s^C\n",rl_prompt, rl_line_buffer);
|
||||
rl_replace_line("", 0);
|
||||
rl_on_new_line();
|
||||
rl_redisplay();
|
||||
}
|
||||
if (signum == 3)
|
||||
{
|
||||
rl_redisplay();
|
||||
ft_putstr_fd("filsdeup", 1);
|
||||
}
|
||||
else if (signum == SIGQUIT)
|
||||
printf("%s%s", rl_prompt, rl_line_buffer);
|
||||
}
|
||||
|
||||
void *here_doc_variables(int write, int index, void *data)
|
||||
@ -45,9 +42,9 @@ void signal_handler_here_doc(int signum)
|
||||
t_msh *msh;
|
||||
char *here_doc_file;
|
||||
|
||||
if(signum == 2)
|
||||
if(signum == SIGINT)
|
||||
{
|
||||
write(1,"\n",1);
|
||||
printf("%s%s^C\n",rl_prompt, rl_line_buffer);
|
||||
msh = here_doc_variables(0, 0, 0);
|
||||
here_doc_file = here_doc_variables(0, 1, 0);
|
||||
close(msh->in_fd);
|
||||
@ -59,5 +56,6 @@ void signal_handler_here_doc(int signum)
|
||||
|
||||
void signal_handler_command(int signum)
|
||||
{
|
||||
(void)signum;
|
||||
if(signum == SIGQUIT)
|
||||
printf("^\\Quit (core dumped)\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user