summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-26 17:54:40 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-26 17:54:40 +0200
commit63d4df1fbb5ac13cd388a1a0069ab82a13f81069 (patch)
tree12c4ef5371b2f2e5d7435bf51fa406a5d4d45060
parentNew comparison strings stuff (diff)
download42-minishell-63d4df1fbb5ac13cd388a1a0069ab82a13f81069.tar.gz
42-minishell-63d4df1fbb5ac13cd388a1a0069ab82a13f81069.tar.bz2
42-minishell-63d4df1fbb5ac13cd388a1a0069ab82a13f81069.tar.xz
42-minishell-63d4df1fbb5ac13cd388a1a0069ab82a13f81069.tar.zst
42-minishell-63d4df1fbb5ac13cd388a1a0069ab82a13f81069.zip
Numbers are goodio, now errcheck
Diffstat (limited to '')
-rw-r--r--Makefile1
-rw-r--r--src/b_sqb.c3
-rw-r--r--src/b_sqb_file.c8
-rw-r--r--src/b_sqb_nbr.c45
-rw-r--r--src/b_sqb_nbr.h20
-rw-r--r--src/b_sqb_str.c8
6 files changed, 77 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 95a5d4a..f0ed77d 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,7 @@ SRCS_NAME += b_export_mute
SRCS_NAME += b_pwd
SRCS_NAME += b_sqb
SRCS_NAME += b_sqb_file
+SRCS_NAME += b_sqb_nbr
SRCS_NAME += b_sqb_str
SRCS_NAME += b_type
SRCS_NAME += b_unset
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);
}