diff options
| author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-12-01 21:35:53 +0100 | 
|---|---|---|
| committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-12-01 21:35:53 +0100 | 
| commit | 314f8f2c501322717c247fe512093a894244b702 (patch) | |
| tree | 7542a204ffd719f639624f33cfa079063fc98e8c | |
| parent | commit (diff) | |
| download | 42-minishell-314f8f2c501322717c247fe512093a894244b702.tar.gz 42-minishell-314f8f2c501322717c247fe512093a894244b702.tar.bz2 42-minishell-314f8f2c501322717c247fe512093a894244b702.tar.xz 42-minishell-314f8f2c501322717c247fe512093a894244b702.tar.zst 42-minishell-314f8f2c501322717c247fe512093a894244b702.zip | |
Merged shotgunfixes
Diffstat (limited to '')
| -rw-r--r-- | libft/Makefile | 1 | ||||
| -rw-r--r-- | libft/include/libft.h | 1 | ||||
| -rw-r--r-- | libft/src/ft_isfulldigit.c | 23 | ||||
| -rw-r--r-- | src/b_exit.c | 12 | ||||
| -rw-r--r-- | src/b_type.c | 2 | ||||
| -rw-r--r-- | src/f_fail.c | 6 | ||||
| -rw-r--r-- | src/f_fail.h | 1 | 
7 files changed, 40 insertions, 6 deletions
| diff --git a/libft/Makefile b/libft/Makefile index 4024b3e..66b8081 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -28,6 +28,7 @@ SRCS_NAME	+= ft_strclen.c  SRCS_NAME	+= ft_strnlen.c  SRCS_NAME	+= ft_isalpha.c  SRCS_NAME	+= ft_isdigit.c +SRCS_NAME	+= ft_isfulldigit.c  SRCS_NAME	+= ft_isalnum.c  SRCS_NAME	+= ft_isascii.c  SRCS_NAME	+= ft_isprint.c diff --git a/libft/include/libft.h b/libft/include/libft.h index 47992c0..265d87c 100644 --- a/libft/include/libft.h +++ b/libft/include/libft.h @@ -145,6 +145,7 @@ int						ft_memcmp(const void *s1, const void *s2, size_t n);  t_bool					ft_isspace(int c);  t_bool					ft_iswhitespace(int c);  t_bool					ft_ischarset(const char *charset, int c); +t_bool					ft_isfulldigit(char *str);  t_bool					ft_isupper(int c);  t_bool					ft_islower(int c);  t_bool					ft_isalpha(int c); diff --git a/libft/src/ft_isfulldigit.c b/libft/src/ft_isfulldigit.c new file mode 100644 index 0000000..d7b7d1e --- /dev/null +++ b/libft/src/ft_isfulldigit.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   ft_isdigit.c                                       :+:      :+:    :+:   */ +/*                                                    +:+ +:+         +:+     */ +/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */ +/*                                                +#+#+#+#+#+   +#+           */ +/*   Created: 2020/02/14 17:06:39 by rbousset          #+#    #+#             */ +/*   Updated: 2020/02/14 17:06:39 by rbousset         ###   ########lyon.fr   */ +/*                                                                            */ +/* ************************************************************************** */ + +#include <libft.h> + +t_bool	ft_isfulldigit(char *str) +{ +	unsigned int i; + +	i = 0; +	while (ft_isdigit(str[i])) +		i++; +	return (i == ft_strlen(str)); +} diff --git a/src/b_exit.c b/src/b_exit.c index aa3360d..4f395cf 100644 --- a/src/b_exit.c +++ b/src/b_exit.c @@ -20,10 +20,6 @@  #include "s_struct.h"  #include "u_utils.h" -/* -** TODO: handle non-numeric args[0] -*/ -  unsigned char	b_exit(char *args[], t_msh *msh)  {  	unsigned char		ret; @@ -36,7 +32,13 @@ unsigned char	b_exit(char *args[], t_msh *msh)  	}  	if (argc == 1)  	{ -		ret = ft_atoi(args[0]); +		if (ft_isfulldigit(args[0])) +			ret = ft_atoi(args[0]); +		else +		{ +			f_fail_non_numeric_arg("exit", args[0]); +			ret = 2; +		}  	}  	else  		ret = msh->ret; diff --git a/src/b_type.c b/src/b_type.c index 5904742..789071f 100644 --- a/src/b_type.c +++ b/src/b_type.c @@ -47,7 +47,7 @@ static char				b_absolute_path_exists(char com[])  static void				b_type_get_path(char fullpath[], char com[], t_msh *msh)  { -	if (ft_ischarset("/.", com[0]) == TRUE) +	if (ft_strchr(com, '/') != NULL)  	{  		if (b_absolute_path_exists(com))  		{ diff --git a/src/f_fail.c b/src/f_fail.c index 7b48b03..d7ac4c4 100644 --- a/src/f_fail.c +++ b/src/f_fail.c @@ -39,3 +39,9 @@ void		f_fail_too_many_args(const char concern[], t_msh *msh)  {  	f_write_fail(concern, F_TOO_MANY_ARGS, msh);  } + +void		f_fail_non_numeric_arg(const char concern[], char *arg) +{ +	ft_dprintf(STDERR_FILENO, +		"minishell: %s: `%s': numerical argument required\n", concern, arg); +} diff --git a/src/f_fail.h b/src/f_fail.h index 4cc9973..6bf248c 100644 --- a/src/f_fail.h +++ b/src/f_fail.h @@ -27,5 +27,6 @@  void	f_fail_no_options(const char concern[], t_msh *msh);  void	f_fail_too_many_args(const char concern[], t_msh *msh);  void	f_fail_identifier(const char concern[], const char identifier[]); +void	f_fail_non_numeric_arg(const char concern[], char *arg);  #endif | 
