diff options
| author | Dominik Kaiser | 2024-06-25 14:02:02 +0200 |
|---|---|---|
| committer | GitHub | 2024-06-25 14:02:02 +0200 |
| commit | 97cca528658e5b811a56600b7c0b4f9c11bf83fc (patch) | |
| tree | 38120dd91e74a8f5073a5af414245ccbf4fbd417 /src/signal_handling.c | |
| parent | 0d7a57a7bc14831d6d7076ccb0ea7a7213ddd7fb (diff) | |
| download | minishell-97cca528658e5b811a56600b7c0b4f9c11bf83fc.tar.gz minishell-97cca528658e5b811a56600b7c0b4f9c11bf83fc.zip | |
Add basic command line
* Initialize terminal and signal handling
* Add basic repl that doesn't do anything yet
* Add handling for Ctrl-C, Ctrl-D and Ctrl-\ in interactive mode
Diffstat (limited to 'src/signal_handling.c')
| -rw-r--r-- | src/signal_handling.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/signal_handling.c b/src/signal_handling.c new file mode 100644 index 0000000..a19fa94 --- /dev/null +++ b/src/signal_handling.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* signal_handling.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/24 15:08:43 by dkaiser #+# #+# */ +/* Updated: 2024/06/25 13:33:26 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static void handle_sigint(int status); +static void handle_sigquit(int status); + +int init_signal_handling(void) +{ + if (signal(SIGINT, &handle_sigint) == SIG_ERR) + return (1); + if (signal(SIGQUIT, &handle_sigquit) == SIG_ERR) + return (1); + return (0); +} + +static void handle_sigint(__attribute__((unused)) int status) +{ + write(1, "\n", 1); + rl_replace_line("", 0); + rl_on_new_line(); + rl_redisplay(); +} + +static void handle_sigquit(__attribute__((unused)) int status) +{ + rl_redisplay(); +} |
