mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-11 06:58:47 +02:00
「✨」 feat(builtins/ft_exit): ft_exit is there ! :D
This commit is contained in:
@ -3,31 +3,55 @@
|
||||
/* ::: :::::::: */
|
||||
/* ft_exit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/14 13:46:57 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/14 14:24:47 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/07/15 15:14:57 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int check_exit_value(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (str[i] == '-' || str[i] == '+')
|
||||
i++;
|
||||
while (str[i])
|
||||
{
|
||||
if (!ft_isdigit(str[i]))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
if (!i)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ft_exit(char **argv, int ac)
|
||||
{
|
||||
char **tmp;
|
||||
char *tmp_arg;
|
||||
|
||||
(void)tmp;
|
||||
(void)tmp_arg;
|
||||
(void)argv;
|
||||
(void)ac;
|
||||
exit(727);
|
||||
// if (ac > 2)
|
||||
// exit
|
||||
// while (*tmp)
|
||||
// {
|
||||
//
|
||||
// tmp++;
|
||||
// }
|
||||
|
||||
int return_value;
|
||||
|
||||
if (ac < 2)
|
||||
exit(get_exit_code(-1));
|
||||
if (check_exit_value(argv[1]))
|
||||
{
|
||||
printf("minishell: exit: %s: numeric argument required\n", argv[1]);
|
||||
exit(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ac > 2)
|
||||
printf("minishell: exit: too many arguments\n");
|
||||
else
|
||||
{
|
||||
return_value = atoi(argv[1]);
|
||||
if (return_value == -1)
|
||||
return_value += 255;
|
||||
exit(get_exit_code(return_value));
|
||||
}
|
||||
}
|
||||
get_exit_code(1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user