Browse Source

fix exit

master
narnaud 3 years ago
parent
commit
3c061c211a
  1. 16
      built-in.c
  2. 2
      errors.c
  3. 2
      libft/Makefile
  4. 26
      libft/is/ft_isnumber.c
  5. 3
      libft/libft.h

16
built-in.c

@ -6,7 +6,7 @@
/* By: mea <mea@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

2
errors.c

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

2
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 \

26
libft/is/ft_isnumber.c

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isnumber.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud@student.42nice.fr <marvin@42.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);
}

3
libft/libft.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

Loading…
Cancel
Save