diff --git a/.vscode/settings.json b/.vscode/settings.json index 828d5ed..6be99c7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "files.associations": { - "minishell.h": "c" + "minishell.h": "c", + "signal.h": "c" } -} \ No newline at end of file +} diff --git a/Makefile b/Makefile index 9108b49..2060049 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ # **************************************************************************** # # # -# ::: :::::::: # -# Makefile :+: :+: :+: # -# +:+ +:+ +:+ # -# By: qmennen +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2024/10/15 11:48:46 by whaffman #+# #+# # -# Updated: 2025/02/11 15:06:22 by qmennen ### ########.fr # +# :::::::: # +# Makefile :+: :+: # +# +:+ # +# By: qmennen +#+ # +# +#+ # +# Created: 2024/10/15 11:48:46 by whaffman #+# #+# # +# Updated: 2025/02/19 12:18:18 by whaffman ######## odam.nl # # # # **************************************************************************** # @@ -22,7 +22,7 @@ LIBFT = $(LIBFT_PATH)/libft.a OBJ_PATH = obj -VPATH = src:src/environment:src/prompt:src/lexer:src/token:src/utils:src/executor:src/parser +VPATH = src:src/environment:src/prompt:src/lexer:src/token:src/utils:src/executor:src/parser:src/signal SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c")) OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o)) diff --git a/inc/minishell.h b/inc/minishell.h index 7c820b9..ce63aa9 100644 --- a/inc/minishell.h +++ b/inc/minishell.h @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/04 16:13:13 by whaffman #+# #+# */ -/* Updated: 2025/02/12 10:59:38 by whaffman ######## odam.nl */ +/* Updated: 2025/02/19 12:38:57 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ # include "allowed.h" # include "libft.h" # include "typedef.h" +# include "signals.h" # include "environment.h" # include "prompt.h" # include "tokenizer.h" diff --git a/inc/signals.h b/inc/signals.h new file mode 100644 index 0000000..658fab8 --- /dev/null +++ b/inc/signals.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* signals.h :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/02/19 12:26:09 by whaffman #+# #+# */ +/* Updated: 2025/02/19 12:32:26 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#ifndef SIGNALS_H +# define SIGNALS_H + +# include "minishell.h" + +void signal_init_minishell(void); +void sigint_minishell_handler(int signum); + +#endif // SIGNALS_H diff --git a/src/main.c b/src/main.c index 78a4813..c634e60 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/04 16:19:22 by whaffman #+# #+# */ -/* Updated: 2025/02/13 13:36:23 by whaffman ######## odam.nl */ +/* Updated: 2025/02/19 12:41:05 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -31,10 +31,13 @@ int main(int argc, char **argv, char **envp) print_banner(); history_load(); minishell = init_minishell(); + signal_init_minishell(); environment_parse(envp, &(minishell->environment)); while (TRUE) { minishell->line = ft_prompt(minishell); + if (minishell->line == NULL) + break ; minishell->lexer = ft_lexer_new(minishell->line); minishell->tokens = ft_parse_input(minishell->lexer); ft_lstiter(minishell->tokens, token_print); diff --git a/src/signal/signal.c b/src/signal/signal.c new file mode 100644 index 0000000..29f3ab0 --- /dev/null +++ b/src/signal/signal.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* signal.c :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/02/19 12:18:47 by whaffman #+# #+# */ +/* Updated: 2025/02/19 12:39:05 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + + +void signal_init_minishell(void) +{ + signal(SIGINT, sigint_minishell_handler); + signal(SIGQUIT, SIG_IGN); +} + +void sigint_minishell_handler(int signum) +{ + (void)signum; + ft_putstr_fd("\n", 1); + rl_on_new_line(); + rl_redisplay(); +}