diff --git a/built-in.c b/built-in.c index 039e301..30267c5 100755 --- a/built-in.c +++ b/built-in.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/06 09:02:57 by narnaud #+# #+# */ -/* Updated: 2022/05/18 13:45:47 by narnaud@stude ### ########.fr */ +/* Updated: 2022/05/18 16:26:51 by narnaud@stude ### ########.fr */ /* */ /* ************************************************************************** */ @@ -107,8 +107,14 @@ int ft_exit(t_datas *datas, t_command *cmd) if (cmd->argc == 1) halt(datas, EXIT_SUCCESS, 0); else if (cmd->argc == 2) - halt(datas, ft_atoi(cmd->argv[1]), 0); - else - ft_putstr_fd("minishell: exit: too many arguments\n", 2); - return (1); + { + if (!ft_isnumber(cmd->argv[1])) + { + cmd_error("exit", "numeric argument required"); + halt(datas, 2, 0); + } + halt(datas, ft_atoi(cmd->argv[1]) % 255, 0); + } + cmd_error("exit", "too many arguments"); + return (EXIT_FAILURE); } diff --git a/errors.c b/errors.c index 27f9cfa..2c9132c 100644 --- a/errors.c +++ b/errors.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/06 13:15:59 by narnaud #+# #+# */ -/* Updated: 2022/05/17 17:24:09 by narnaud ### ########.fr */ +/* Updated: 2022/05/18 14:45:53 by narnaud@stude ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/Makefile b/libft/Makefile index 8a7ca8f..e3f3af6 100755 --- a/libft/Makefile +++ b/libft/Makefile @@ -1,7 +1,7 @@ NAME = libft.a SRCS = is/ft_isalpha.c is/ft_isdigit.c is/ft_isascii.c is/ft_isprint.c \ - is/ft_isalnum.c is/ft_isspace.c + is/ft_isalnum.c is/ft_isspace.c is/ft_isnumber.c SRCS += str/ft_len.c str/ft_lcpy.c str/ft_lcat.c str/ft_chr.c \ str/ft_rchr.c str/ft_ncmp.c str/ft_nstr.c str/ft_dup.c \ diff --git a/libft/is/ft_isnumber.c b/libft/is/ft_isnumber.c new file mode 100644 index 0000000..6053f7a --- /dev/null +++ b/libft/is/ft_isnumber.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isnumber.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud@student.42nice.fr +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/05/18 16:18:15 by narnaud@stude #+# #+# */ +/* Updated: 2022/05/18 16:21:52 by narnaud@stude ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +int ft_isnumber(char *str) +{ + if (*str == '-' || *str == '+') + str++; + while (*str) + { + if (!ft_isdigit(*str)) + return (0); + str++; + } + return (1); +} diff --git a/libft/libft.h b/libft/libft.h index b9d3edf..de7b0c1 100755 --- a/libft/libft.h +++ b/libft/libft.h @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/19 14:42:45 by narnaud #+# #+# */ -/* Updated: 2022/05/17 09:55:08 by narnaud ### ########.fr */ +/* Updated: 2022/05/18 16:25:27 by narnaud@stude ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,7 @@ int ft_isdigit(int ch); int ft_isprint(int ch); int ft_isalnum(int ch); int ft_isspace(int ch); +int ft_isnumber(char *str); void *ft_memchr(const void *b, int c, size_t n); int ft_memcmp(const void *s1, const void *s2, size_t n); void *ft_memcpy(void *dst, const void *src, size_t n);