This commit is contained in:
2024-02-16 21:53:38 +01:00
parent 2a2ef1d63c
commit 79f99ce489
14 changed files with 29 additions and 46 deletions

47
srcs/exit.c Executable file
View File

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
/* Updated: 2024/02/16 13:07:01 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void print_numeric_arg_err(char *arg)
{
ft_putstr_fd("minishell: exit: ", 2);
ft_putstr_fd(arg, 2);
ft_putstr_fd(": numeric argument required\n", 2);
}
void exit_bt(t_cmd *args, t_env *env)
{
t_cmd *start;
int exit_code;
start = args;
args = args->next;
ft_printf("exit\n");
if (args && args->next && args->next->type == ARG
&& ft_strisnbr(args->token))
ft_putstr_fd("minishell: exit: too many arguments\n", 2);
else
{
if (args && args->type == ARG && !ft_strisnbr(args->token))
print_numeric_arg_err(args->token);
if (args && args->type == ARG)
exit_code = (unsigned char)ft_atoi(args->token);
else if (args && args->type == ARG && !ft_strisnbr(args->token))
exit_code = 2;
else
exit_code = g_return_code;
free_cmd(start);
free_env(env);
exit(exit_code);
}
}