summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/b_sqb.c50
-rw-r--r--src/d_define.h4
-rw-r--r--src/s_init.c42
-rw-r--r--src/s_struct.h1
4 files changed, 87 insertions, 10 deletions
diff --git a/src/b_sqb.c b/src/b_sqb.c
index 9e7015c..91bf7b6 100644
--- a/src/b_sqb.c
+++ b/src/b_sqb.c
@@ -14,24 +14,56 @@
#include <stdint.h>
#include <unistd.h>
+#include "d_define.h"
#include "s_struct.h"
#include "u_utils.h"
-/* static uint8_t */
-/* b_get_sqb_id(uint64_t argc, */
-/* char *argv[],) */
-/* { */
-/* } */
+static void
+ b_sqb_unexpected_operator(const char op[])
+{
+ ft_dprintf(STDERR_FILENO, "[: %s: unexpected operator\n", op);
+}
+
+static uint8_t
+ b_get_sqb_id(uint64_t argc,
+ char *argv[],
+ t_msh *msh)
+{
+ size_t j;
+ uint8_t i;
+
+ i = 0;
+ while (i < FT_ID_SQB_COUNT)
+ {
+ j = 0;
+ while (j < argc)
+ {
+ if (
+ ft_strncmp(argv[j],
+ msh->sqb_ref[i],
+ ft_strlen(msh->sqb_ref[i]) + 1) == 0)
+ return (i);
+ j++;
+ }
+ i++;
+ }
+ return (i);
+}
static uint8_t
b_eval_sqb(uint64_t argc,
char *argv[],
t_msh *msh)
{
- (void)argc;
- (void)argv;
- (void)msh;
+ uint8_t id;
+ id = b_get_sqb_id(argc, argv, msh);
+ if (id == FT_ID_SQB_COUNT)
+ {
+ b_sqb_unexpected_operator(argv[0]);
+ return (2);
+ }
+ ft_printf("[%s]\n", msh->sqb_ref[id]);
return (0);
}
@@ -48,5 +80,7 @@ uint8_t
}
if (argc == 1)
return (1);
+ else if (argc == 2)
+ return (0);
return (b_eval_sqb(argc, args, msh));
}
diff --git a/src/d_define.h b/src/d_define.h
index e094df1..18a60b4 100644
--- a/src/d_define.h
+++ b/src/d_define.h
@@ -90,7 +90,7 @@
#define FT_SQB_S_MAJ "-b"
#define FT_SQB_NT "-nt"
#define FT_SQB_OT "-ot"
-#define FT_SQB_EQUALS "="
+#define FT_SQB_EQUA "="
#define FT_SQB_DIFF "!="
#define FT_SQB_EQ "-eq"
#define FT_SQB_NE "-ne"
@@ -119,7 +119,7 @@ enum
FT_ID_SQB_S_MAJ,
FT_ID_SQB_NT,
FT_ID_SQB_OT,
- FT_ID_SQB_EQUALS,
+ FT_ID_SQB_EQUA,
FT_ID_SQB_DIFF,
FT_ID_SQB_EQ,
FT_ID_SQB_NE,
diff --git a/src/s_init.c b/src/s_init.c
index 7b36653..acef5d6 100644
--- a/src/s_init.c
+++ b/src/s_init.c
@@ -26,6 +26,46 @@
#include "u_vars.h"
#include "u_vars_next.h"
+static void
+ s_init_sqb_ref_one(t_msh *msh)
+{
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_B], FT_SQB_B, ft_strlen(FT_SQB_B) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_C], FT_SQB_C, ft_strlen(FT_SQB_C) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_D], FT_SQB_D, ft_strlen(FT_SQB_D) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_E], FT_SQB_E, ft_strlen(FT_SQB_E) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_F], FT_SQB_F, ft_strlen(FT_SQB_F) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_G], FT_SQB_G, ft_strlen(FT_SQB_G) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_H], FT_SQB_H, ft_strlen(FT_SQB_H) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_K], FT_SQB_K, ft_strlen(FT_SQB_K) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_N], FT_SQB_N, ft_strlen(FT_SQB_N) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_S], FT_SQB_S, ft_strlen(FT_SQB_S) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_U], FT_SQB_U, ft_strlen(FT_SQB_U) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_W], FT_SQB_W, ft_strlen(FT_SQB_W) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_X], FT_SQB_X, ft_strlen(FT_SQB_X) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_Z], FT_SQB_Z, ft_strlen(FT_SQB_Z) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_L_MAJ],
+ FT_SQB_L_MAJ, ft_strlen(FT_SQB_L_MAJ) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_S_MAJ],
+ FT_SQB_S_MAJ, ft_strlen(FT_SQB_S_MAJ) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_NT], FT_SQB_NT, ft_strlen(FT_SQB_NT) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_OT], FT_SQB_OT, ft_strlen(FT_SQB_OT) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_EQUA],
+ FT_SQB_EQUA, ft_strlen(FT_SQB_EQUA) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_DIFF],
+ FT_SQB_DIFF, ft_strlen(FT_SQB_DIFF) + 1);
+}
+
+static void
+ s_init_sqb_ref_two(t_msh *msh)
+{
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_EQ], FT_SQB_EQ, ft_strlen(FT_SQB_EQ) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_NE], FT_SQB_NE, ft_strlen(FT_SQB_NE) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_GT], FT_SQB_GT, ft_strlen(FT_SQB_GT) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_GE], FT_SQB_GE, ft_strlen(FT_SQB_GE) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_LT], FT_SQB_LT, ft_strlen(FT_SQB_LT) + 1);
+ ft_memcpy(msh->sqb_ref[FT_ID_SQB_LE], FT_SQB_LE, ft_strlen(FT_SQB_LE) + 1);
+}
+
static char
**dupenv_del(char **nenvp,
uint64_t i)
@@ -143,5 +183,7 @@ t_msh
msh->cwd = set_cwd(msh);
msh->env_fork_tmp[0][0] = '\0';
inc_shlvl(msh);
+ s_init_sqb_ref_one(msh);
+ s_init_sqb_ref_two(msh);
return (msh);
}
diff --git a/src/s_struct.h b/src/s_struct.h
index 15505d5..54d3af3 100644
--- a/src/s_struct.h
+++ b/src/s_struct.h
@@ -74,6 +74,7 @@ typedef struct s_msh
char **bu_ref;
char *cwd;
char env_fork_tmp[128][1024];
+ char sqb_ref[FT_ID_SQB_COUNT][4];
uint8_t (*bu_ptr[FT_BUILTINS_COUNT])(char **, struct s_msh*);
struct s_line *curr;
struct s_lvars *vars;