From 2793aed4e589f556160a0c67338464baa110b659 Mon Sep 17 00:00:00 2001 From: Tanguy MAZE Date: Tue, 8 Jan 2019 18:34:22 +0100 Subject: [PATCH] added function to transform env entry into list element --- Makefile | 4 ++-- includes/minishell.h | 9 ++++++++- srcs/exec.c | 4 ++-- srcs/main.c | 34 ++++++++++++++++++++++++++++++++-- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 1e9a7cd..d9706a8 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: tmaze +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2018/11/22 14:43:33 by tmaze #+# #+# # -# Updated: 2018/11/28 14:55:43 by tmaze ### ########.fr # +# Updated: 2019/01/07 18:06:46 by tmaze ### ########.fr # # # #******************************************************************************# @@ -16,7 +16,7 @@ CCSTD := NAME := minishell -SRCS := main.c exec.c cmd_echo.c +SRCS := main.c exec.c cmd_echo.c cmd_cd.c OBJS_DIR := objs OBJS := $(addprefix $(OBJS_DIR)/, $(SRCS:.c=.o)) INCLS := -Iincludes -Ilibft diff --git a/includes/minishell.h b/includes/minishell.h index 58799ab..8f14843 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/11/18 13:12:34 by tmaze #+# #+# */ -/* Updated: 2018/11/27 16:23:49 by tmaze ### ########.fr */ +/* Updated: 2019/01/08 17:38:25 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,14 @@ typedef struct s_builtin int (*f)(char **argv, char **envp); } t_builtin; +typedef struct s_envelem +{ + char *key; + char *val; +} t_envelem; + int exec_cmd(char **argv, char **env); int cmd_echo(char **argv, char **env); +int cmd_cd(char **argv, char **env); #endif diff --git a/srcs/exec.c b/srcs/exec.c index 33a574c..f1dbe40 100644 --- a/srcs/exec.c +++ b/srcs/exec.c @@ -6,13 +6,13 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/11/27 15:32:29 by tmaze #+# #+# */ -/* Updated: 2018/11/28 16:42:22 by tmaze ### ########.fr */ +/* Updated: 2019/01/07 18:57:22 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -#define S_BIN 1 +#define S_BIN 2 int exec_cmd(char **argv, char **env) { diff --git a/srcs/main.c b/srcs/main.c index d1859ef..f3ff73d 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/11/18 13:09:55 by tmaze #+# #+# */ -/* Updated: 2018/11/28 15:10:45 by tmaze ### ########.fr */ +/* Updated: 2019/01/08 18:33:40 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,6 +62,36 @@ t_list *ft_strtabtolst(char **tab) return (ret); } +t_envelem *ft_envtoenvelem(char *env) +{ + size_t i; + t_envelem *ret; + + i = 0; + if ((ret = (t_envelem*)ft_memalloc(sizeof(t_envelem))) == NULL) + return (NULL); + while (env[i] && env[i] != '=') + i++; + if ((ret->key = (char*)ft_strnew(i)) = NULL) + { + ft_memdel((void**)&ret); + return (NULL); + } + if ((ret->value = (char*)ft_strnew(ft_strlen(ft_strrlen(env) - i - 1))) = NULL) + { + ft_memdel((void**)&ret); + return (NULL); + } + ft_strlcpy(ret->key, env, i); + ft_strlcpy(ret->key, env + i + 1, ft_strrlen(env) - i - 1); + return (&ret); +} + +t_list *ft_envtolst(char **env) +{ + +} + int main(void) { char *cmd; @@ -96,7 +126,7 @@ int main(void) ft_lstdel(&lst_env, &ft_lstdelstr); ft_strdel(&cmd); return (2); - } + } if (ft_strcmp("exit", cmd) == 0) { ft_lstdel(&lst_env, &ft_lstdelstr);