summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-20 18:46:17 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-20 18:46:17 +0200
commit3349e8a37a9fdf78b82d6df1d310e39c78fcebb2 (patch)
tree88ec7499dbdd45293ae63b5b353c849e50c166e8
parentCool funptr (diff)
download42-minishell-3349e8a37a9fdf78b82d6df1d310e39c78fcebb2.tar.gz
42-minishell-3349e8a37a9fdf78b82d6df1d310e39c78fcebb2.tar.bz2
42-minishell-3349e8a37a9fdf78b82d6df1d310e39c78fcebb2.tar.xz
42-minishell-3349e8a37a9fdf78b82d6df1d310e39c78fcebb2.tar.zst
42-minishell-3349e8a37a9fdf78b82d6df1d310e39c78fcebb2.zip
Trying linked lists
Diffstat (limited to '')
-rw-r--r--Makefile4
-rw-r--r--src/ft_b_env.c27
-rw-r--r--src/ft_b_env.h21
-rw-r--r--src/ft_m_funptr.c19
-rw-r--r--src/ft_m_loop.c1
-rw-r--r--src/ft_p_lcom.c38
-rw-r--r--src/ft_p_lcom.h0
-rw-r--r--src/ft_p_line.c17
-rw-r--r--src/ft_p_line.h3
-rw-r--r--src/ft_s_destroy.c4
-rw-r--r--src/ft_s_lcom.c23
-rw-r--r--src/ft_s_lcom.h0
-rw-r--r--src/ft_s_struct.h7
-rw-r--r--src/minishell.c11
14 files changed, 150 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 005be1d..ea74111 100644
--- a/Makefile
+++ b/Makefile
@@ -15,12 +15,16 @@ LFT_SRCS_DIR = ${LFT_DIR}src/
#--------------------------------- FILES --------------------------------------#
#==============================================================================#
SRCS_NAME = minishell.c
+SRCS_NAME += ft_b_env.c
+SRCS_NAME += ft_e_lcom.c
SRCS_NAME += ft_m_funptr.c
SRCS_NAME += ft_m_loop.c
SRCS_NAME += ft_m_prompt.c
SRCS_NAME += ft_s_destroy.c
SRCS_NAME += ft_s_init.c
+SRCS_NAME += ft_s_lcom.c
SRCS_NAME += ft_p_line.c
+SRCS_NAME += ft_p_lcom.c
#------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR}, ${SRCS_NAME})
#------------------------------------------------------------------------------#
diff --git a/src/ft_b_env.c b/src/ft_b_env.c
new file mode 100644
index 0000000..e3aa710
--- /dev/null
+++ b/src/ft_b_env.c
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_b_env.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 "ft_b_env.h"
+#include "ft_s_struct.h"
+
+int32_t
+ ft_b_env(t_msh *msh)
+{
+ while (*msh->envp)
+ {
+ ft_printf("%s\n", *msh->envp);
+ msh->envp++;
+ }
+ return (0);
+}
diff --git a/src/ft_b_env.h b/src/ft_b_env.h
new file mode 100644
index 0000000..b54bc8e
--- /dev/null
+++ b/src/ft_b_env.h
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_b_env.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_B_ENV_H
+#define FT_B_ENV_H
+
+#include <stdint.h>
+#include "ft_s_struct.h"
+
+int32_t ft_b_env(t_msh *msh);
+
+#endif
diff --git a/src/ft_m_funptr.c b/src/ft_m_funptr.c
index 682472b..4307d3c 100644
--- a/src/ft_m_funptr.c
+++ b/src/ft_m_funptr.c
@@ -10,22 +10,25 @@
/* */
/* ************************************************************************** */
+#include <stdlib.h>
+#include "ft_b_env.h"
+#include "ft_d_enum.h"
#include "ft_m_funptr.h"
#include "ft_s_struct.h"
void
ft_init_buptr(t_msh *msh)
{
- msh->bu_ptr[0] = ft_b_echo;
- msh->bu_ptr[1] = ft_b_cd;
- msh->bu_ptr[2] = ft_b_pwd;
- msh->bu_ptr[3] = ft_b_export;
- msh->bu_ptr[4] = ft_b_unset;
+ /* msh->bu_ptr[0] = ft_b_echo; */
+ /* msh->bu_ptr[1] = ft_b_cd; */
+ /* msh->bu_ptr[2] = ft_b_pwd; */
+ /* msh->bu_ptr[3] = ft_b_export; */
+ /* msh->bu_ptr[4] = ft_b_unset; */
msh->bu_ptr[5] = ft_b_env;
- msh->bu_ptr[6] = ft_b_exit;
- msh->bu_ptr[7] = ft_b_cat;
+ /* msh->bu_ptr[6] = ft_b_exit; */
+ /* msh->bu_ptr[7] = ft_b_cat; */
if (!(msh->bu_ref = ft_split(FT_BUILTINS, '|')))
{
- return ;
+ exit(FT_RET_ALLOC);
}
}
diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c
index d53ae89..3f9488a 100644
--- a/src/ft_m_loop.c
+++ b/src/ft_m_loop.c
@@ -30,6 +30,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);
}
return (FT_RET_FINE);
}
diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c
new file mode 100644
index 0000000..8c3d6d4
--- /dev/null
+++ b/src/ft_p_lcom.c
@@ -0,0 +1,38 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_p_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 "ft_s_struct.h"
+
+int8_t
+ ft_p_lcom(const char line[],
+ const int64_t count,
+ t_msh *msh)
+{
+ char **words;
+ int64_t i;
+
+ i = 0;
+ if (!(words = ft_split(line, ';')))
+ return (-1);
+ while (i < count)
+ {
+ if (!(msh->lcom = ft_lcom_new(words[i])))
+ {
+ return (-1);
+ }
+ msh->lcom = msh->lcom.next;
+ i++;
+ }
+ return (0);
+}
diff --git a/src/ft_p_lcom.h b/src/ft_p_lcom.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/ft_p_lcom.h
diff --git a/src/ft_p_line.c b/src/ft_p_line.c
index 70699a6..8d75547 100644
--- a/src/ft_p_line.c
+++ b/src/ft_p_line.c
@@ -10,12 +10,23 @@
/* */
/* ************************************************************************** */
+#include <libft.h>
+#include <stdlib.h>
+#include "ft_d_enum.h"
#include "ft_p_line.h"
#include "ft_s_struct.h"
void
- ft_p_line(char *line, t_msh *msh)
+ ft_p_line(char line[],
+ t_msh *msh)
{
- (void)line;
- (void)msh;
+ int64_t ret;
+
+ if ((ret = ft_strlchr(line, ';') < 0))
+ {
+ if (ft_p_lcom(line, 1, msh) < 0)
+ {
+ exit(FT_RET_ALLOC);
+ }
+ }
}
diff --git a/src/ft_p_line.h b/src/ft_p_line.h
index 262cb57..076be42 100644
--- a/src/ft_p_line.h
+++ b/src/ft_p_line.h
@@ -15,6 +15,7 @@
#include "ft_s_struct.h"
-void ft_p_line(char *line, t_msh *msh);
+void ft_p_line(char *line,
+ t_msh *msh);
#endif
diff --git a/src/ft_s_destroy.c b/src/ft_s_destroy.c
index 8c82297..02336d3 100644
--- a/src/ft_s_destroy.c
+++ b/src/ft_s_destroy.c
@@ -14,9 +14,9 @@
#include "ft_s_destroy.h"
void
-ft_s_destroy(t_msh *msh)
+ ft_s_destroy(t_msh *msh)
{
ft_memdel((void*)&msh->ps_one);
- ft_memdel((void*)&msh->bu_ptr);
+ ft_memdel((void*)&msh->bu_ref);
ft_memdel((void*)&msh);
}
diff --git a/src/ft_s_lcom.c b/src/ft_s_lcom.c
new file mode 100644
index 0000000..9189113
--- /dev/null
+++ b/src/ft_s_lcom.c
@@ -0,0 +1,23 @@
+#include <libft.h>
+#include <stdlib.h>
+#include "ft_s_struct.h"
+
+t_lcom
+ *ft_lcom_lstnew(const char word[])
+{
+ t_lcom nlcom;
+ char **words
+
+ /* 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);
+}
diff --git a/src/ft_s_lcom.h b/src/ft_s_lcom.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/ft_s_lcom.h
diff --git a/src/ft_s_struct.h b/src/ft_s_struct.h
index 8c02f9f..6f3cf21 100644
--- a/src/ft_s_struct.h
+++ b/src/ft_s_struct.h
@@ -16,12 +16,12 @@
#include <stdint.h>
#include "ft_d_define.h"
-typedef struct s_com
+typedef struct s_lcom
{
char *com;
char **args;
struct s_com *next;
-} t_com;
+} t_lcom;
typedef struct s_msh
{
@@ -30,7 +30,8 @@ typedef struct s_msh
int32_t ret;
char **bu_ref;
int32_t (*bu_ptr[FT_BUILTINS_COUNT])(struct s_msh*);
- struct s_com *lcom;
+ struct s_lcom *lcom_head;
+ struct s_lcom *lcom;
} t_msh;
#endif
diff --git a/src/minishell.c b/src/minishell.c
index a3b0354..4b8e763 100644
--- a/src/minishell.c
+++ b/src/minishell.c
@@ -20,9 +20,9 @@
#include "ft_s_destroy.h"
int
-main(int argc,
- const char *argv[],
- char *envp[])
+ main(int argc,
+ const char *argv[],
+ char *envp[])
{
t_msh *msh;
int32_t ret;
@@ -35,11 +35,6 @@ main(int argc,
}
msh->ret = ft_m_loop(msh);
ret = msh->ret;
- /* while (*msh->envp) */
- /* { */
- /* ft_printf("%s\n", *msh->envp); */
- /* msh->envp++; */
- /* } */
ft_s_destroy(msh);
return (ret);
}