summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-20 17:04:59 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-20 17:04:59 +0200
commit386c44e541af7aa1ba594d2f0a9665199b3dffb4 (patch)
treecf5ef3cfeca4348c76aa97ffa5c00849ef9ee24a
parentGood (diff)
download42-minishell-386c44e541af7aa1ba594d2f0a9665199b3dffb4.tar.gz
42-minishell-386c44e541af7aa1ba594d2f0a9665199b3dffb4.tar.bz2
42-minishell-386c44e541af7aa1ba594d2f0a9665199b3dffb4.tar.xz
42-minishell-386c44e541af7aa1ba594d2f0a9665199b3dffb4.tar.zst
42-minishell-386c44e541af7aa1ba594d2f0a9665199b3dffb4.zip
Nice prompt
Diffstat (limited to '')
-rw-r--r--Makefile5
-rw-r--r--src/ft_m_loop.c33
-rw-r--r--src/ft_m_loop.h21
-rw-r--r--src/ft_s_destroy.c1
-rw-r--r--src/ft_s_init.c7
-rw-r--r--src/ft_s_init.h2
-rw-r--r--src/ft_s_struct.h3
-rw-r--r--src/minishell.c13
8 files changed, 72 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 5be0b78..580ca63 100644
--- a/Makefile
+++ b/Makefile
@@ -16,14 +16,15 @@ LFT_SRCS_DIR = ${LFT_DIR}src/
#==============================================================================#
SRCS_NAME = minishell.c
SRCS_NAME += ft_m_prompt.c
+SRCS_NAME += ft_m_loop.c
SRCS_NAME += ft_s_init.c
SRCS_NAME += ft_s_destroy.c
#------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR}, ${SRCS_NAME})
#------------------------------------------------------------------------------#
-INCS_NAME = ft_s_struct.h
-INCS_NAME += ft_d_enum.h
+INCS_NAME = ft_d_enum.h
INCS_NAME += ft_d_define.h
+INCS_NAME += ft_s_struct.h
INCS_NAME += $(patsubst %.c,%.h,${SRCS_NAME})
#------------------------------------------------------------------------------#
INCS = $(addprefix ${SRCS_DIR}, ${INCS_NAME})
diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c
new file mode 100644
index 0000000..1e2efc0
--- /dev/null
+++ b/src/ft_m_loop.c
@@ -0,0 +1,33 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_m_loop.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 <unistd.h>
+#include "ft_d_enum.h"
+#include "ft_m_loop.h"
+#include "ft_m_prompt.h"
+
+int32_t
+ ft_m_loop(t_msh *msh)
+{
+ int8_t gnl;
+ char *line;
+
+ gnl = 1;
+ while (gnl > 0)
+ {
+ ft_m_prompt(msh);
+ gnl = get_next_line(STDIN_FILENO, &line);
+ }
+ return (FT_RET_FINE);
+}
diff --git a/src/ft_m_loop.h b/src/ft_m_loop.h
new file mode 100644
index 0000000..564d447
--- /dev/null
+++ b/src/ft_m_loop.h
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_m_loop.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_M_LOOP
+#define FT_M_LOOP
+
+#include <stdint.h>
+#include "ft_s_struct.h"
+
+int32_t ft_m_loop(t_msh *msh);
+
+#endif
diff --git a/src/ft_s_destroy.c b/src/ft_s_destroy.c
index ef132ce..23e0737 100644
--- a/src/ft_s_destroy.c
+++ b/src/ft_s_destroy.c
@@ -16,5 +16,6 @@
void
ft_s_destroy(t_msh *msh)
{
+ ft_memdel((void*)&msh->ps_one);
ft_memdel((void*)&msh);
}
diff --git a/src/ft_s_init.c b/src/ft_s_init.c
index 0d27aa7..c4b2667 100644
--- a/src/ft_s_init.c
+++ b/src/ft_s_init.c
@@ -15,7 +15,7 @@
#include "ft_s_init.h"
t_msh
- *ft_init_msh(void)
+ *ft_init_msh(char *envp[])
{
t_msh *msh;
@@ -28,8 +28,9 @@ t_msh
{
return (NULL);
}
- ft_strlcpy(msh->ps_one, FT_PS_ONE, ft_strlen(FT_PS_ONE));
- msh->envp = NULL;
+ ft_strlcpy(msh->ps_one, FT_PS_ONE, ft_strlen(FT_PS_ONE) + 1);
+ msh->envp = envp;
+ msh->ret = 0;
msh->lcom = NULL;
return (msh);
}
diff --git a/src/ft_s_init.h b/src/ft_s_init.h
index ea28b24..c5ce54a 100644
--- a/src/ft_s_init.h
+++ b/src/ft_s_init.h
@@ -16,6 +16,6 @@
#include <stdlib.h>
#include "ft_s_struct.h"
-t_msh *ft_init_msh(void);
+t_msh *ft_init_msh(char *envp[]);
#endif
diff --git a/src/ft_s_struct.h b/src/ft_s_struct.h
index 3bfa76b..8234449 100644
--- a/src/ft_s_struct.h
+++ b/src/ft_s_struct.h
@@ -22,9 +22,10 @@ typedef struct s_com
typedef struct s_msh
{
- struct s_com *lcom;
char *ps_one;
char **envp;
+ int32_t ret;
+ struct s_com *lcom;
} t_msh;
#endif
diff --git a/src/minishell.c b/src/minishell.c
index 5d97ed6..a3b0354 100644
--- a/src/minishell.c
+++ b/src/minishell.c
@@ -11,9 +11,10 @@
/* ************************************************************************** */
#include <libft.h>
+#include <stdint.h>
#include "minishell.h"
#include "ft_d_enum.h"
-#include "ft_m_prompt.h"
+#include "ft_m_loop.h"
#include "ft_s_struct.h"
#include "ft_s_init.h"
#include "ft_s_destroy.h"
@@ -24,23 +25,23 @@ main(int argc,
char *envp[])
{
t_msh *msh;
+ int32_t ret;
(void)argc;
(void)argv;
- (void)envp;
- if (!(msh = ft_init_msh()))
+ if (!(msh = ft_init_msh(envp)))
{
return (FT_RET_ALLOC);
}
- msh->envp = envp;
- ft_m_prompt(msh);
+ 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 (FT_RET_FINE);
+ return (ret);
}
/*