diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-20 17:31:32 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-20 17:31:32 +0200 |
commit | c85c10c0308c565ed0e1c6320a81551f1777b56d (patch) | |
tree | 8f4fbed31da06f4f0716cd37d1b4cfaa43f55685 /src | |
parent | Nice prompt (diff) | |
download | 42-minishell-c85c10c0308c565ed0e1c6320a81551f1777b56d.tar.gz 42-minishell-c85c10c0308c565ed0e1c6320a81551f1777b56d.tar.bz2 42-minishell-c85c10c0308c565ed0e1c6320a81551f1777b56d.tar.xz 42-minishell-c85c10c0308c565ed0e1c6320a81551f1777b56d.tar.zst 42-minishell-c85c10c0308c565ed0e1c6320a81551f1777b56d.zip |
Cool funptr
Diffstat (limited to '')
-rw-r--r-- | src/ft_d_define.h | 4 | ||||
-rw-r--r-- | src/ft_m_funptr.c | 31 | ||||
-rw-r--r-- | src/ft_m_funptr.h | 20 | ||||
-rw-r--r-- | src/ft_m_loop.c | 2 | ||||
-rw-r--r-- | src/ft_p_line.c | 21 | ||||
-rw-r--r-- | src/ft_p_line.h | 20 | ||||
-rw-r--r-- | src/ft_s_destroy.c | 1 | ||||
-rw-r--r-- | src/ft_s_init.c | 2 | ||||
-rw-r--r-- | src/ft_s_struct.h | 5 |
9 files changed, 105 insertions, 1 deletions
diff --git a/src/ft_d_define.h b/src/ft_d_define.h index 06cc2eb..b30be21 100644 --- a/src/ft_d_define.h +++ b/src/ft_d_define.h @@ -13,6 +13,8 @@ #ifndef FT_D_DEFINE_H #define FT_D_DEFINE_H -#define FT_PS_ONE "minishell ~> " +#define FT_PS_ONE "minishell ~> " +#define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|cat" +#define FT_BUILTINS_COUNT 8 #endif diff --git a/src/ft_m_funptr.c b/src/ft_m_funptr.c new file mode 100644 index 0000000..682472b --- /dev/null +++ b/src/ft_m_funptr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_m_funptr.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 "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[5] = ft_b_env; + msh->bu_ptr[6] = ft_b_exit; + msh->bu_ptr[7] = ft_b_cat; + if (!(msh->bu_ref = ft_split(FT_BUILTINS, '|'))) + { + return ; + } +} diff --git a/src/ft_m_funptr.h b/src/ft_m_funptr.h new file mode 100644 index 0000000..889c0af --- /dev/null +++ b/src/ft_m_funptr.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_m_funptr.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_FUNPTR_H +#define FT_M_FUNPTR_H + +#include "ft_s_struct.h" + +void ft_init_buptr(t_msh *msh); + +#endif diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c index 1e2efc0..d53ae89 100644 --- a/src/ft_m_loop.c +++ b/src/ft_m_loop.c @@ -28,6 +28,8 @@ int32_t { ft_m_prompt(msh); gnl = get_next_line(STDIN_FILENO, &line); + ft_p_line(line, msh); + ft_memdel((void*)&line); } return (FT_RET_FINE); } diff --git a/src/ft_p_line.c b/src/ft_p_line.c new file mode 100644 index 0000000..70699a6 --- /dev/null +++ b/src/ft_p_line.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_p_line.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 "ft_p_line.h" +#include "ft_s_struct.h" + +void + ft_p_line(char *line, t_msh *msh) +{ + (void)line; + (void)msh; +} diff --git a/src/ft_p_line.h b/src/ft_p_line.h new file mode 100644 index 0000000..262cb57 --- /dev/null +++ b/src/ft_p_line.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_p_line.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_LINE_H +#define FT_P_LINE_H + +#include "ft_s_struct.h" + +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 23e0737..8c82297 100644 --- a/src/ft_s_destroy.c +++ b/src/ft_s_destroy.c @@ -17,5 +17,6 @@ void ft_s_destroy(t_msh *msh) { ft_memdel((void*)&msh->ps_one); + ft_memdel((void*)&msh->bu_ptr); ft_memdel((void*)&msh); } diff --git a/src/ft_s_init.c b/src/ft_s_init.c index c4b2667..2d55e88 100644 --- a/src/ft_s_init.c +++ b/src/ft_s_init.c @@ -12,6 +12,7 @@ #include <libft.h> #include "ft_d_define.h" +#include "ft_m_funptr.h" #include "ft_s_init.h" t_msh @@ -31,6 +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); msh->lcom = NULL; return (msh); } diff --git a/src/ft_s_struct.h b/src/ft_s_struct.h index 8234449..8c02f9f 100644 --- a/src/ft_s_struct.h +++ b/src/ft_s_struct.h @@ -13,6 +13,9 @@ #ifndef FT_S_STRUCT_H #define FT_S_STRUCT_H +#include <stdint.h> +#include "ft_d_define.h" + typedef struct s_com { char *com; @@ -25,6 +28,8 @@ typedef struct s_msh char *ps_one; char **envp; int32_t ret; + char **bu_ref; + int32_t (*bu_ptr[FT_BUILTINS_COUNT])(struct s_msh*); struct s_com *lcom; } t_msh; |