From 694951f903e48a9aa78243dfb872daef3460cef1 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 28 Jun 2024 14:36:54 -0300 Subject: [PATCH 1/7] LIBFT - updating functions to boolean mode --- program_to_test/libs/libft/includes/libft.h | 14 ++++++++------ program_to_test/libs/libft/src/ft_isalnum.c | 12 ++++++++---- program_to_test/libs/libft/src/ft_isalpha.c | 10 +++++++--- program_to_test/libs/libft/src/ft_isascii.c | 10 +++++++--- program_to_test/libs/libft/src/ft_isdigit.c | 8 +++++--- program_to_test/libs/libft/src/ft_isprint.c | 10 +++++++--- 6 files changed, 42 insertions(+), 22 deletions(-) diff --git a/program_to_test/libs/libft/includes/libft.h b/program_to_test/libs/libft/includes/libft.h index 474af5c..3c12993 100644 --- a/program_to_test/libs/libft/includes/libft.h +++ b/program_to_test/libs/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/07/26 20:30:01 by umeneses #+# #+# */ -/* Updated: 2024/05/17 17:55:58 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 14:34:02 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,8 @@ # include /* Headers for ft_printf */ +# include + # define DEC "0123456789" # define HEXL "0123456789abcdef" # define HEXU "0123456789ABCDEF" @@ -71,11 +73,11 @@ typedef struct s_file_container int ft_atoi(const char *str); void ft_bzero(void *s, size_t n); void *ft_calloc(size_t n_items, size_t size); -int ft_isalnum(int content); -int ft_isalpha(int c); -int ft_isascii(int content); -int ft_isdigit(int input); -int ft_isprint(int content); +bool ft_isalnum(int content); +bool ft_isalpha(int c); +bool ft_isascii(int content); +bool ft_isdigit(int input); +bool ft_isprint(int content); void *ft_memchr(const void *str, int c, size_t n); int ft_memcmp(const void *str1, const void *str2, size_t n); void *ft_memcpy(void *dest, const void *src, size_t n); diff --git a/program_to_test/libs/libft/src/ft_isalnum.c b/program_to_test/libs/libft/src/ft_isalnum.c index 485a846..e9dd50a 100644 --- a/program_to_test/libs/libft/src/ft_isalnum.c +++ b/program_to_test/libs/libft/src/ft_isalnum.c @@ -6,13 +6,17 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/08/03 15:10:22 by bira #+# #+# */ -/* Updated: 2023/09/03 16:48:24 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 14:32:01 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ -int ft_isalnum(int content) +#include "libft.h" + +bool ft_isalnum(int content) { - return ((content >= '0' && content <= '9') || \ + if ((content >= '0' && content <= '9') || \ (content >= 'a' && content <= 'z') || \ - (content >= 'A' && content <= 'Z')); + (content >= 'A' && content <= 'Z')) + return (true); + return (false); } diff --git a/program_to_test/libs/libft/src/ft_isalpha.c b/program_to_test/libs/libft/src/ft_isalpha.c index 24f27e8..a4de27b 100644 --- a/program_to_test/libs/libft/src/ft_isalpha.c +++ b/program_to_test/libs/libft/src/ft_isalpha.c @@ -6,11 +6,15 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/08/03 15:10:22 by bira #+# #+# */ -/* Updated: 2023/09/03 16:48:21 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 14:28:23 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ -int ft_isalpha(int c) +#include "libft.h" + +bool ft_isalpha(int c) { - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) + return (true); + return (false); } diff --git a/program_to_test/libs/libft/src/ft_isascii.c b/program_to_test/libs/libft/src/ft_isascii.c index 276f617..10e50e9 100644 --- a/program_to_test/libs/libft/src/ft_isascii.c +++ b/program_to_test/libs/libft/src/ft_isascii.c @@ -6,11 +6,15 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/08/03 17:31:09 by bira #+# #+# */ -/* Updated: 2023/09/03 16:48:17 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 14:33:14 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ -int ft_isascii(int content) +#include "libft.h" + +bool ft_isascii(int content) { - return (content >= 0 && content <= 127); + if (content >= 0 && content <= 127) + return (true); + return (false); } diff --git a/program_to_test/libs/libft/src/ft_isdigit.c b/program_to_test/libs/libft/src/ft_isdigit.c index bda2f45..e1438df 100644 --- a/program_to_test/libs/libft/src/ft_isdigit.c +++ b/program_to_test/libs/libft/src/ft_isdigit.c @@ -6,13 +6,15 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/08/01 17:36:38 by bira #+# #+# */ -/* Updated: 2023/09/03 16:52:45 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 14:19:23 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -int ft_isdigit(int input) +bool ft_isdigit(int input) { - return (input >= '0' && input <= '9'); + if (input >= '0' && input <= '9') + return (true); + return (false); } diff --git a/program_to_test/libs/libft/src/ft_isprint.c b/program_to_test/libs/libft/src/ft_isprint.c index 858d23c..524a434 100644 --- a/program_to_test/libs/libft/src/ft_isprint.c +++ b/program_to_test/libs/libft/src/ft_isprint.c @@ -6,11 +6,15 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/08/03 18:07:03 by bira #+# #+# */ -/* Updated: 2023/09/03 16:48:12 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 14:33:46 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ -int ft_isprint(int content) +#include "libft.h" + +bool ft_isprint(int content) { - return (content >= 32 && content <= 126); + if (content >= 32 && content <= 126) + return (true); + return (false); } From 8506224169c2ff3cd1d6eb33495d09312413eae0 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 28 Jun 2024 14:37:17 -0300 Subject: [PATCH 2/7] fix non numbers validation --- program_to_test/src/ft_argv_validation.c | 60 +++++++++++++----------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/program_to_test/src/ft_argv_validation.c b/program_to_test/src/ft_argv_validation.c index 5cae5c2..d9cf76c 100644 --- a/program_to_test/src/ft_argv_validation.c +++ b/program_to_test/src/ft_argv_validation.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/03 11:43:20 by umeneses #+# #+# */ -/* Updated: 2024/06/28 12:36:40 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 14:30:12 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,38 +25,18 @@ int ft_argv_size(char **argv) return (size - 1); } -bool ft_argv_is_not_duplicated(char **argv) -{ - int after_atoi; - int index; - int future_pos; - char **compare; - - after_atoi = 0; - index = 0; - compare = argv; - while ((argv[++index] != NULL) && (index <= ft_argv_size(argv))) - { - after_atoi = ft_atoi(argv[index]); - future_pos = 1; - while ((++future_pos <= ft_argv_size(argv)) && (future_pos != index) - && compare[future_pos] != NULL) - { - if (ft_atoi(compare[future_pos]) == after_atoi) - return (false); - } - } - return (true); -} - bool ft_argv_signs_and_nbrs(char **argv) { - int index; + int index; index = 0; while (argv[++index] != NULL) { - if (ft_is_sign(*argv[index]) || ft_is_space(*argv[index])) + if (ft_isalpha(*argv[index])) + return (false); + if (ft_isdigit(*(argv[index])) && argv[index] == NULL) + return (true); + if ((ft_is_sign(*argv[index]) || ft_is_space(*argv[index]))) { if (ft_is_sign(*(argv[index] + 1))) return (false); @@ -64,7 +44,7 @@ bool ft_argv_signs_and_nbrs(char **argv) return (false); } } - return (true); + return (false); } bool ft_argv_inside_range_intmin_intmax(char **argv) @@ -86,6 +66,30 @@ bool ft_argv_inside_range_intmin_intmax(char **argv) return (true); } +bool ft_argv_is_not_duplicated(char **argv) +{ + int after_atoi; + int index; + int future_pos; + char **compare; + + after_atoi = 0; + index = 0; + compare = argv; + while ((argv[++index] != NULL) && (index <= ft_argv_size(argv))) + { + after_atoi = ft_atoi(argv[index]); + future_pos = 1; + while ((++future_pos <= ft_argv_size(argv)) && (future_pos != index) + && compare[future_pos] != NULL) + { + if (ft_atoi(compare[future_pos]) == after_atoi) + return (false); + } + } + return (true); +} + bool ft_argv_validation(char **argv) { if (!ft_argv_signs_and_nbrs(argv)) From e2e2bf57593b2f59846a3b757792421ae317e824 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 28 Jun 2024 16:45:51 -0300 Subject: [PATCH 3/7] fixing pointer access --- program_to_test/src/ft_argv_validation.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/program_to_test/src/ft_argv_validation.c b/program_to_test/src/ft_argv_validation.c index d9cf76c..c1438f8 100644 --- a/program_to_test/src/ft_argv_validation.c +++ b/program_to_test/src/ft_argv_validation.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/03 11:43:20 by umeneses #+# #+# */ -/* Updated: 2024/06/28 14:30:12 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 16:44:47 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,11 +32,11 @@ bool ft_argv_signs_and_nbrs(char **argv) index = 0; while (argv[++index] != NULL) { - if (ft_isalpha(*argv[index])) + if (ft_isalpha(*(argv[index]))) return (false); - if (ft_isdigit(*(argv[index])) && argv[index] == NULL) + if (ft_isdigit(*(argv[index]))) return (true); - if ((ft_is_sign(*argv[index]) || ft_is_space(*argv[index]))) + if (ft_is_sign(*(argv[index])) || ft_is_space(*(argv[index]))) { if (ft_is_sign(*(argv[index] + 1))) return (false); From a682fa6ac7955f871b7592ef9070f6c2c539ff82 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 28 Jun 2024 18:31:18 -0300 Subject: [PATCH 4/7] moving argv_size --- program_to_test/src/ft_argv_utils.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/program_to_test/src/ft_argv_utils.c b/program_to_test/src/ft_argv_utils.c index f45d708..6ef6cde 100644 --- a/program_to_test/src/ft_argv_utils.c +++ b/program_to_test/src/ft_argv_utils.c @@ -6,12 +6,25 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/26 15:35:16 by umeneses #+# #+# */ -/* Updated: 2024/06/27 14:33:27 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 17:08:28 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" +int ft_argv_size(char **argv) +{ + int size; + + size = 0; + while (argv[++size] != NULL) + { + if (ft_is_sign(*argv[size]) || ft_is_space(*argv[size])) + size++; + } + return (size - 1); +} + bool ft_is_sign(int c) { if (c == '-' || c == '+') From 212f4aa94e67da9360c9dc9cef2dda68b35724ef Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 28 Jun 2024 18:31:49 -0300 Subject: [PATCH 5/7] rebuilding numbers validation --- program_to_test/src/ft_argv_validation.c | 54 +++++++++++++++--------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/program_to_test/src/ft_argv_validation.c b/program_to_test/src/ft_argv_validation.c index c1438f8..f2f4e75 100644 --- a/program_to_test/src/ft_argv_validation.c +++ b/program_to_test/src/ft_argv_validation.c @@ -6,42 +6,53 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/03 11:43:20 by umeneses #+# #+# */ -/* Updated: 2024/06/28 16:44:47 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 18:28:33 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -int ft_argv_size(char **argv) +bool ft_argv_valid_sign_and_not_alpha(char **argv) { - int size; + int index; - size = 0; - while (argv[++size] != NULL) + index = 0; + while (argv[++index] != NULL) { - if (ft_is_sign(*argv[size]) || ft_is_space(*argv[size])) - size++; + if (ft_isalpha(*(argv[index]))) + return (false); + if (ft_is_sign(*(argv[index])) || ft_is_space(*(argv[index]))) + { + if (ft_is_sign(*(argv[index] + 1)) + || !ft_isdigit(*(argv[index] + 1))) + return (false); + } } - return (size - 1); + return (true); } -bool ft_argv_signs_and_nbrs(char **argv) +bool ft_argv_only_nbrs_per_string(char **argv) { int index; + int c_counter; index = 0; while (argv[++index] != NULL) { - if (ft_isalpha(*(argv[index]))) - return (false); - if (ft_isdigit(*(argv[index]))) - return (true); if (ft_is_sign(*(argv[index])) || ft_is_space(*(argv[index]))) + continue ; + if (ft_isdigit(*(argv[index]))) { - if (ft_is_sign(*(argv[index] + 1))) - return (false); - if (!ft_isdigit(*(argv[index] + 1))) - return (false); + c_counter = 0; + while (argv[index] && ft_isdigit(*(argv[index]))) + { + if (ft_is_space(*(argv[index] + c_counter)) + || (*(argv[index] + c_counter) == '\0')) + return (true); + if (!ft_isdigit(*(argv[index] + c_counter))) + return (false); + c_counter++; + } } } return (false); @@ -92,9 +103,14 @@ bool ft_argv_is_not_duplicated(char **argv) bool ft_argv_validation(char **argv) { - if (!ft_argv_signs_and_nbrs(argv)) + if (!ft_argv_valid_sign_and_not_alpha(argv)) + { + ft_error_msg("1.User's input must be numbers only\n"); + return (false); + } + if (!ft_argv_only_nbrs_per_string(argv)) { - ft_error_msg("User's input must be numbers only\n"); + ft_error_msg("2.User's input must be numbers only\n"); return (false); } if (!ft_argv_inside_range_intmin_intmax(argv)) From 30cf155ee11bbb29d4b2d5ff1f5ac9d36793ec6d Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 28 Jun 2024 18:33:30 -0300 Subject: [PATCH 6/7] removing extra error message --- program_to_test/src/push_main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/program_to_test/src/push_main.c b/program_to_test/src/push_main.c index a207797..5bf9ddf 100644 --- a/program_to_test/src/push_main.c +++ b/program_to_test/src/push_main.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 18:34:31 by umeneses #+# #+# */ -/* Updated: 2024/06/28 13:38:58 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 18:33:36 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,6 @@ int main(int argc, char **argv) { if (ft_argv_validation(argv) == true) return (EXIT_SUCCESS); - else - ft_error_msg("Only number arguments allowed."); } stack_a = NULL; stack_b = NULL; From 0faa8b388040372361ced1627c7871da7be4eecf Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 28 Jun 2024 18:42:24 -0300 Subject: [PATCH 7/7] adding argv new validation functions --- program_to_test/headers/push_swap.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 03b31ec..dbdaea2 100644 --- a/program_to_test/headers/push_swap.h +++ b/program_to_test/headers/push_swap.h @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/08 15:23:33 by umeneses #+# #+# */ -/* Updated: 2024/06/27 14:17:14 by umeneses ### ########.fr */ +/* Updated: 2024/06/28 17:20:40 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,7 +45,8 @@ bool ft_is_sign(int c); bool ft_is_space(int c); bool ft_argv_is_not_duplicated(char **argv); int ft_argv_size(char **argv); -bool ft_argv_signs_and_nbrs(char **argv); +bool ft_argv_valid_sign_and_not_alpha(char **argv); +bool ft_argv_only_nbrs_per_string(char **argv); long int ft_atoi_long_int(const char *str); bool ft_argv_inside_range_intmin_intmax(char **argv); bool ft_argv_validation(char **argv);