summaryrefslogtreecommitdiffstats
path: root/src/b_sqb.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-25 23:25:07 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-25 23:25:07 +0200
commit441295b57b9892267841840d8d7166b9306f8501 (patch)
tree5488d26656c2812686b9bc15a8efdc5c9ec58b70 /src/b_sqb.c
parentTODO update (diff)
download42-minishell-441295b57b9892267841840d8d7166b9306f8501.tar.gz
42-minishell-441295b57b9892267841840d8d7166b9306f8501.tar.bz2
42-minishell-441295b57b9892267841840d8d7166b9306f8501.tar.xz
42-minishell-441295b57b9892267841840d8d7166b9306f8501.tar.zst
42-minishell-441295b57b9892267841840d8d7166b9306f8501.zip
In progress
Diffstat (limited to 'src/b_sqb.c')
-rw-r--r--src/b_sqb.c50
1 files changed, 42 insertions, 8 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));
}