summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_e_lcom.c52
-rw-r--r--src/ft_e_lcom.h22
-rw-r--r--src/ft_m_funptr.c1
-rw-r--r--src/ft_m_loop.c4
-rw-r--r--src/ft_p_lcom.c3
-rw-r--r--src/ft_p_lcom.h23
-rw-r--r--src/ft_p_line.c1
-rw-r--r--src/ft_s_destroy.c2
-rw-r--r--src/ft_s_init.c2
-rw-r--r--src/ft_s_lcom.c20
-rw-r--r--src/ft_s_lcom.h4
-rw-r--r--src/ft_s_struct.h2
12 files changed, 120 insertions, 16 deletions
diff --git a/src/ft_e_lcom.c b/src/ft_e_lcom.c
new file mode 100644
index 0000000..5e37084
--- /dev/null
+++ b/src/ft_e_lcom.c
@@ -0,0 +1,52 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_e_lcom.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 <stdlib.h>
+#include "ft_s_struct.h"
+
+static uint8_t
+ ft_get_builtin_id(const char com[],
+ t_msh *msh)
+{
+ uint8_t i;
+
+ i = 0;
+ while (ft_strncmp(com, msh->bu_ref[i], 7) != 0)
+ {
+ i++;
+ }
+ return (i);
+}
+
+int32_t
+ ft_e_lcom(t_lcom *lcom,
+ t_msh *msh)
+{
+ uint8_t bu_id;
+
+ while (lcom != NULL)
+ {
+ ft_printf("qwe\n");
+ if ((bu_id = ft_get_builtin_id(lcom->com, msh)) < FT_BUILTINS_COUNT)
+ {
+ msh->bu_ptr[bu_id](msh);
+ }
+ else
+ {
+ /* TODO: exec path stuff */
+ }
+ lcom = lcom->next;
+ }
+ return (0);
+}
diff --git a/src/ft_e_lcom.h b/src/ft_e_lcom.h
new file mode 100644
index 0000000..a273388
--- /dev/null
+++ b/src/ft_e_lcom.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_e_lcom.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 FT_E_LCOM_H
+#define FT_E_LCOM_H
+
+#include <stdint.h>
+#include "ft_s_struct.h"
+
+int32_t ft_e_lcom(t_lcom *lcom,
+ t_msh *msh);
+
+#endif
diff --git a/src/ft_m_funptr.c b/src/ft_m_funptr.c
index 4307d3c..ac40491 100644
--- a/src/ft_m_funptr.c
+++ b/src/ft_m_funptr.c
@@ -10,6 +10,7 @@
/* */
/* ************************************************************************** */
+#include <libft.h>
#include <stdlib.h>
#include "ft_b_env.h"
#include "ft_d_enum.h"
diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c
index 3f9488a..d993ac6 100644
--- a/src/ft_m_loop.c
+++ b/src/ft_m_loop.c
@@ -14,8 +14,10 @@
#include <stdint.h>
#include <unistd.h>
#include "ft_d_enum.h"
+#include "ft_e_lcom.h"
#include "ft_m_loop.h"
#include "ft_m_prompt.h"
+#include "ft_p_line.h"
int32_t
ft_m_loop(t_msh *msh)
@@ -30,7 +32,7 @@ int32_t
gnl = get_next_line(STDIN_FILENO, &line);
ft_p_line(line, msh);
ft_memdel((void*)&line);
- ft_e_lcom(msh->lcom, msh);
+ ft_e_lcom(msh->lcom_head, msh);
}
return (FT_RET_FINE);
}
diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c
index 8c3d6d4..3ea6b16 100644
--- a/src/ft_p_lcom.c
+++ b/src/ft_p_lcom.c
@@ -12,6 +12,7 @@
#include <libft.h>
#include <stdint.h>
+#include "ft_s_lcom.h"
#include "ft_s_struct.h"
int8_t
@@ -31,7 +32,7 @@ int8_t
{
return (-1);
}
- msh->lcom = msh->lcom.next;
+ msh->lcom = msh->lcom->next;
i++;
}
return (0);
diff --git a/src/ft_p_lcom.h b/src/ft_p_lcom.h
index e69de29..245e206 100644
--- a/src/ft_p_lcom.h
+++ b/src/ft_p_lcom.h
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_p_lcom.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 FT_P_LCOM_H
+#define FT_P_LCOM_H
+
+#include <stdint.h>
+#include "ft_s_struct.h"
+
+int8_t ft_p_lcom(const char line[],
+ const int64_t count,
+ t_msh *msh);
+
+#endif
diff --git a/src/ft_p_line.c b/src/ft_p_line.c
index 8d75547..8670231 100644
--- a/src/ft_p_line.c
+++ b/src/ft_p_line.c
@@ -13,6 +13,7 @@
#include <libft.h>
#include <stdlib.h>
#include "ft_d_enum.h"
+#include "ft_p_lcom.h"
#include "ft_p_line.h"
#include "ft_s_struct.h"
diff --git a/src/ft_s_destroy.c b/src/ft_s_destroy.c
index 02336d3..8d93250 100644
--- a/src/ft_s_destroy.c
+++ b/src/ft_s_destroy.c
@@ -17,6 +17,6 @@ void
ft_s_destroy(t_msh *msh)
{
ft_memdel((void*)&msh->ps_one);
- ft_memdel((void*)&msh->bu_ref);
+ ft_delwords(msh->bu_ref);
ft_memdel((void*)&msh);
}
diff --git a/src/ft_s_init.c b/src/ft_s_init.c
index c9e4845..c6f22ba 100644
--- a/src/ft_s_init.c
+++ b/src/ft_s_init.c
@@ -32,7 +32,7 @@ t_msh
ft_strlcpy(msh->ps_one, FT_PS_ONE, ft_strlen(FT_PS_ONE) + 1);
msh->envp = envp;
msh->ret = 0;
- ft_m_funptr(msh);
+ ft_init_buptr(msh);
msh->lcom = NULL;
msh->lcom_head = msh->lcom;
return (msh);
diff --git a/src/ft_s_lcom.c b/src/ft_s_lcom.c
index 19e503b..737c6eb 100644
--- a/src/ft_s_lcom.c
+++ b/src/ft_s_lcom.c
@@ -17,19 +17,19 @@
t_lcom
*ft_lcom_new(const char word[])
{
- t_lcom nlcom;
- char **words
+ t_lcom *nlcom;
+ char **words;
- /* if (!(nlcom = (t_lcom*)malloc(sizeof(t_lcom)))) */
- /* { */
- /* return (NULL); */
- /* } */
+ if (!(nlcom = (t_lcom*)malloc(sizeof(t_lcom))))
+ {
+ return (NULL);
+ }
if (!(words = ft_split(word, ' ')))
{
return (NULL);
}
- nlcom.com = words[0];
- nlcom.args = words + 1;
- nlcom.next = NULL;
- return (&nlcom);
+ nlcom->com = words[0];
+ nlcom->args = words + 1;
+ nlcom->next = NULL;
+ return (nlcom);
}
diff --git a/src/ft_s_lcom.h b/src/ft_s_lcom.h
index 186f93d..14a0c39 100644
--- a/src/ft_s_lcom.h
+++ b/src/ft_s_lcom.h
@@ -13,6 +13,8 @@
#ifndef FT_S_LCOM_H
#define FT_S_LCOM_H
-t_com *ft_lcom_new(const char word[]);
+#include "ft_s_struct.h"
+
+t_lcom *ft_lcom_new(const char word[]);
#endif
diff --git a/src/ft_s_struct.h b/src/ft_s_struct.h
index 6f3cf21..750c95b 100644
--- a/src/ft_s_struct.h
+++ b/src/ft_s_struct.h
@@ -20,7 +20,7 @@ typedef struct s_lcom
{
char *com;
char **args;
- struct s_com *next;
+ struct s_lcom *next;
} t_lcom;
typedef struct s_msh