diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/b_sqb.c | 3 | ||||
-rw-r--r-- | src/b_sqb_file.c | 8 | ||||
-rw-r--r-- | src/b_sqb_nbr.c | 45 | ||||
-rw-r--r-- | src/b_sqb_nbr.h | 20 | ||||
-rw-r--r-- | src/b_sqb_str.c | 8 |
5 files changed, 76 insertions, 8 deletions
diff --git a/src/b_sqb.c b/src/b_sqb.c index 34d5c06..fb52e00 100644 --- a/src/b_sqb.c +++ b/src/b_sqb.c @@ -15,6 +15,7 @@ #include <unistd.h> #include "b_sqb_file.h" +#include "b_sqb_nbr.h" #include "b_sqb_str.h" #include "d_define.h" #include "s_struct.h" @@ -72,6 +73,8 @@ static uint8_t else if (id == FT_ID_SQB_N || id == FT_ID_SQB_Z || id == FT_ID_SQB_EQUA || id == FT_ID_SQB_DIFF) ret = b_sqb_str(id, argv); + else if (id >= FT_ID_SQB_EQ) + ret = b_sqb_nbr(id, argv); return (ret); } diff --git a/src/b_sqb_file.c b/src/b_sqb_file.c index f0cd374..c3a568d 100644 --- a/src/b_sqb_file.c +++ b/src/b_sqb_file.c @@ -70,14 +70,14 @@ uint8_t static t_bool b_sqb_file_comp_tests(uint8_t id, - struct stat sb_one, - struct stat sb_two) + struct stat sb1, + struct stat sb2) { if (id == FT_ID_SQB_NT && - sb_one.st_mtim.tv_sec > sb_two.st_mtim.tv_sec) + sb1.st_mtim.tv_sec > sb2.st_mtim.tv_sec) return (TRUE); else if (id == FT_ID_SQB_OT && - sb_one.st_mtim.tv_sec < sb_two.st_mtim.tv_sec) + sb1.st_mtim.tv_sec < sb2.st_mtim.tv_sec) return (TRUE); return (FALSE); } diff --git a/src/b_sqb_nbr.c b/src/b_sqb_nbr.c new file mode 100644 index 0000000..6ea2456 --- /dev/null +++ b/src/b_sqb_nbr.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* b_sqb_nbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdint.h> + +#include "d_define.h" + +static t_bool + b_sqb_nbr_tests(uint8_t id, + int32_t n1, + int32_t n2) +{ + if (id == FT_ID_SQB_EQ && n1 == n2) + return (TRUE); + else if (id == FT_ID_SQB_NE && n1 != n2) + return (TRUE); + else if (id == FT_ID_SQB_GT && n1 > n2) + return (TRUE); + else if (id == FT_ID_SQB_GE && n1 >= n2) + return (TRUE); + else if (id == FT_ID_SQB_LT && n1 < n2) + return (TRUE); + else if (id == FT_ID_SQB_LE && n1 <= n2) + return (TRUE); + return (FALSE); +} + +uint8_t + b_sqb_nbr(uint8_t id, + char *argv[]) +{ + if (b_sqb_nbr_tests(id, ft_atoi(argv[0]), ft_atoi(argv[2])) == TRUE) + return (0); + return (1); +} diff --git a/src/b_sqb_nbr.h b/src/b_sqb_nbr.h new file mode 100644 index 0000000..ecdf901 --- /dev/null +++ b/src/b_sqb_nbr.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* b_sqb_nbr.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef B_SQB_NBR_H +#define B_SQB_NBR_H + +#include <stdint.h> + +uint8_t b_sqb_nbr(uint8_t id, char *argv[]); + +#endif diff --git a/src/b_sqb_str.c b/src/b_sqb_str.c index cc7e4ed..d3a1978 100644 --- a/src/b_sqb_str.c +++ b/src/b_sqb_str.c @@ -17,14 +17,14 @@ static t_bool b_sqb_str_comp(uint8_t id, - const char s_one[], - const char s_two[]) + const char s1[], + const char s2[]) { if (id == FT_ID_SQB_EQUA && - ft_strncmp(s_one, s_two, ft_strlen(s_one) + 1) == 0) + ft_strncmp(s1, s2, ft_strlen(s1) + 1) == 0) return (TRUE); else if (id == FT_ID_SQB_EQUA && - ft_strncmp(s_one, s_two, ft_strlen(s_one) + 1) != 0) + ft_strncmp(s1, s2, ft_strlen(s1) + 1) != 0) return (TRUE); return (FALSE); } |