/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/26 13:11:47 by ljiriste #+# #+# */
-/* Updated: 2024/08/29 17:17:15 by ljiriste ### ########.fr */
+/* Updated: 2024/08/31 09:08:57 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include <termios.h>
#include <unistd.h>
+#ifndef NOLEAKS
+# include <stdio.h> // readline
+# include <readline/readline.h> // readline
+# include <readline/history.h> // readline
+#endif // NOLEAKS
+
volatile sig_atomic_t g_last_signal;
void handler(int sig_num)
return ;
}
-void setup_signal_hadling(void)
+#ifndef NOLEAKS
+void rl_handler(int sig_num)
+{
+ if (sig_num != SIGINT)
+ return ;
+ write(1, "\n", 1);
+ rl_on_new_line();
+ rl_replace_line("", 0);
+ rl_redisplay();
+ return ;
+}
+
+void set_input_handler(void)
{
struct sigaction sa;
- g_last_signal = 0;
ft_memset(&sa, 0, sizeof(sa));
- sa.sa_handler = handler;
+ sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
- sigaction(SIGINT, &sa, NULL);
- sa.sa_handler = SIG_IGN;
sigaction(SIGQUIT, &sa, NULL);
+ sa.sa_handler = rl_handler;
+ sigaction(SIGINT, &sa, NULL);
return ;
}
-
-void catch_sigquit(void)
+#else
+void set_input_handler(void)
{
struct sigaction sa;
ft_memset(&sa, 0, sizeof(sa));
- sa.sa_handler = handler;
+ sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGQUIT, &sa, NULL);
+ sa.sa_handler = handler;
+ sigaction(SIGINT, &sa, NULL);
return ;
}
-void ignore_sigquit(void)
+#endif // NOLEAKS
+
+void set_execution_handler(void)
{
struct sigaction sa;
ft_memset(&sa, 0, sizeof(sa));
- sa.sa_handler = SIG_IGN;
+ sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGQUIT, &sa, NULL);
+ sigaction(SIGINT, &sa, NULL);
return ;
}
return ;
}
+#ifdef NOLEAKS
void minishell_flush(void)
{
struct termios termios;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &termios);
return ;
}
+#endif // NOLEAKS
/*
// This would be more portable than the main with 3 input args
char *line;
t_execution_env env;
- setup_signal_hadling();
if (argc > 1)
{
print_help();
while (env.exit == 0)
{
setup_terminal();
- ignore_sigquit();
+ set_input_handler();
line = get_line();
if (!line)
{
env.ret_val = 0;
break ;
}
- catch_sigquit();
+ set_execution_handler();
regenerate_terminal();
handle_input(&line, &env);
free(line);