first signals in minshell

This commit is contained in:
whaffman 2025-02-19 12:47:09 +01:00
parent 2add37e72a
commit 9f5c134517
6 changed files with 66 additions and 12 deletions

View File

@ -1,5 +1,6 @@
{ {
"files.associations": { "files.associations": {
"minishell.h": "c" "minishell.h": "c",
"signal.h": "c"
} }
} }

View File

@ -1,12 +1,12 @@
# **************************************************************************** # # **************************************************************************** #
# # # #
# ::: :::::::: # # :::::::: #
# Makefile :+: :+: :+: # # Makefile :+: :+: #
# +:+ +:+ +:+ # # +:+ #
# By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ # # By: qmennen <qmennen@student.codam.nl> +#+ #
# +#+#+#+#+#+ +#+ # # +#+ #
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# # # Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
# Updated: 2025/02/11 15:06:22 by qmennen ### ########.fr # # Updated: 2025/02/19 12:18:18 by whaffman ######## odam.nl #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -22,7 +22,7 @@ LIBFT = $(LIBFT_PATH)/libft.a
OBJ_PATH = obj 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")) SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c"))
OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o)) OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o))

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/04 16:13:13 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 "allowed.h"
# include "libft.h" # include "libft.h"
# include "typedef.h" # include "typedef.h"
# include "signals.h"
# include "environment.h" # include "environment.h"
# include "prompt.h" # include "prompt.h"
# include "tokenizer.h" # include "tokenizer.h"

21
inc/signals.h Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* signals.h :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* 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

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/04 16:19:22 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(); print_banner();
history_load(); history_load();
minishell = init_minishell(); minishell = init_minishell();
signal_init_minishell();
environment_parse(envp, &(minishell->environment)); environment_parse(envp, &(minishell->environment));
while (TRUE) while (TRUE)
{ {
minishell->line = ft_prompt(minishell); minishell->line = ft_prompt(minishell);
if (minishell->line == NULL)
break ;
minishell->lexer = ft_lexer_new(minishell->line); minishell->lexer = ft_lexer_new(minishell->line);
minishell->tokens = ft_parse_input(minishell->lexer); minishell->tokens = ft_parse_input(minishell->lexer);
ft_lstiter(minishell->tokens, token_print); ft_lstiter(minishell->tokens, token_print);

28
src/signal/signal.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* signal.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* 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();
}