exit code on signal in prompt

This commit is contained in:
whaffman 2025-03-19 14:53:44 +01:00
parent 1679624f8d
commit 0e94a5a97a
3 changed files with 21 additions and 35 deletions

View File

@ -6,7 +6,7 @@
/* By: marvin <marvin@student.42.fr> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:13 by whaffman #+# #+# */
/* Updated: 2025/03/06 15:55:50 by whaffman ######## odam.nl */
/* Updated: 2025/03/19 14:46:36 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -33,6 +33,8 @@
# include "debug.h"
# include "utils.h"
extern int g_signum;
# define TRUE 1
# define FALSE 0

View File

@ -6,18 +6,23 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:19:22 by whaffman #+# #+# */
/* Updated: 2025/03/06 11:24:46 by whaffman ######## odam.nl */
/* Updated: 2025/03/19 14:50:28 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "minishell.h"
int g_signum = 0;
static void main_loop(t_minishell *msh)
{
while (TRUE)
{
g_signum = 0;
msh->line = ft_prompt(msh);
if (g_signum != 0)
msh->exit_status = g_signum + 128;
if (msh->line == NULL)
break ;
msh->lexer = ft_lexer_new(msh);
@ -25,45 +30,24 @@ static void main_loop(t_minishell *msh)
ft_lstiter(msh->tokens, token_print);
msh->commands = parser_get_commands(msh);
executor_execute_pipeline(msh);
free_minishell_line(msh);
}
}
static void main_test(t_minishell *msh, char *line)
{
int i;
char **args;
args = ft_split(line, ';');
i = 0;
while (args[i])
{
msh->line = args[i];
msh->lexer = ft_lexer_new(msh);
msh->tokens = ft_parse_input(msh);
ft_lstiter(msh->tokens, token_print);
msh->commands = parser_get_commands(msh);
executor_execute_pipeline(msh);
free_minishell_line(msh);
i++;
}
free(args);
}
int main(int argc, char **argv, char **envp)
{
t_minishell *msh;
int exit_status;
(void)argc;
(void)argv;
print_banner();
history_load();
msh = init_minishell();
signal_init_minishell();
environment_parse(msh, envp);
if (argc > 2 && ft_strcmp(argv[1], "-c") == 0)
main_test(msh, argv[2]);
else
main_loop(msh);
main_loop(msh);
exit_status = msh->exit_status;
free_minishell(&msh);
rl_clear_history();

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* signal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/19 12:18:47 by whaffman #+# #+# */
/* Updated: 2025/03/18 14:17:03 by qmennen ### ########.fr */
/* :::::::: */
/* signal.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/19 12:18:47 by whaffman #+# #+# */
/* Updated: 2025/03/19 14:51:02 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
void sigint_minishell_handler(int signum)
{
(void)signum;
g_signum = signum;
ft_putstr_fd("\n", 1);
rl_on_new_line();
rl_replace_line("", 0);