Skip to content

Commit

Permalink
Merge pull request #15 from biralavor/14-fix-non-numbers-list-verific…
Browse files Browse the repository at this point in the history
…ation

14 fix non numbers list verification
  • Loading branch information
biralavor authored Jun 28, 2024
2 parents 50c3bf3 + 0faa8b3 commit b026b71
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 65 deletions.
5 changes: 3 additions & 2 deletions program_to_test/headers/push_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions program_to_test/libs/libft/includes/libft.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -19,6 +19,8 @@
# include <stdarg.h>
/* Headers for ft_printf */

# include <stdbool.h>

# define DEC "0123456789"
# define HEXL "0123456789abcdef"
# define HEXU "0123456789ABCDEF"
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions program_to_test/libs/libft/src/ft_isalnum.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
10 changes: 7 additions & 3 deletions program_to_test/libs/libft/src/ft_isalpha.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
10 changes: 7 additions & 3 deletions program_to_test/libs/libft/src/ft_isascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
8 changes: 5 additions & 3 deletions program_to_test/libs/libft/src/ft_isdigit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
10 changes: 7 additions & 3 deletions program_to_test/libs/libft/src/ft_isprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
15 changes: 14 additions & 1 deletion program_to_test/src/ft_argv_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 == '+')
Expand Down
94 changes: 57 additions & 37 deletions program_to_test/src/ft_argv_validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,56 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/03 11:43:20 by umeneses #+# #+# */
/* Updated: 2024/06/28 12:36:40 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)
{
if (ft_is_sign(*argv[size]) || ft_is_space(*argv[size]))
size++;
}
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)))
while (argv[++index] != NULL)
{
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_isalpha(*(argv[index])))
return (false);
if (ft_is_sign(*(argv[index])) || ft_is_space(*(argv[index])))
{
if (ft_atoi(compare[future_pos]) == after_atoi)
if (ft_is_sign(*(argv[index] + 1))
|| !ft_isdigit(*(argv[index] + 1)))
return (false);
}
}
return (true);
}

bool ft_argv_signs_and_nbrs(char **argv)
bool ft_argv_only_nbrs_per_string(char **argv)
{
int index;
int index;
int c_counter;

index = 0;
while (argv[++index] != NULL)
{
if (ft_is_sign(*argv[index]) || ft_is_space(*argv[index]))
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 (true);
return (false);
}

bool ft_argv_inside_range_intmin_intmax(char **argv)
Expand All @@ -86,11 +77,40 @@ 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))
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))
Expand Down
4 changes: 1 addition & 3 deletions program_to_test/src/push_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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;
Expand Down

0 comments on commit b026b71

Please sign in to comment.