added function to transform env entry into list element
This commit is contained in:
parent
1edfe5167f
commit
2793aed4e5
4
Makefile
4
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2018/11/22 14:43:33 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
|
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_DIR := objs
|
||||||
OBJS := $(addprefix $(OBJS_DIR)/, $(SRCS:.c=.o))
|
OBJS := $(addprefix $(OBJS_DIR)/, $(SRCS:.c=.o))
|
||||||
INCLS := -Iincludes -Ilibft
|
INCLS := -Iincludes -Ilibft
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/11/18 13:12:34 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);
|
int (*f)(char **argv, char **envp);
|
||||||
} t_builtin;
|
} t_builtin;
|
||||||
|
|
||||||
|
typedef struct s_envelem
|
||||||
|
{
|
||||||
|
char *key;
|
||||||
|
char *val;
|
||||||
|
} t_envelem;
|
||||||
|
|
||||||
int exec_cmd(char **argv, char **env);
|
int exec_cmd(char **argv, char **env);
|
||||||
int cmd_echo(char **argv, char **env);
|
int cmd_echo(char **argv, char **env);
|
||||||
|
int cmd_cd(char **argv, char **env);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/11/27 15:32:29 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"
|
#include "minishell.h"
|
||||||
|
|
||||||
#define S_BIN 1
|
#define S_BIN 2
|
||||||
|
|
||||||
int exec_cmd(char **argv, char **env)
|
int exec_cmd(char **argv, char **env)
|
||||||
{
|
{
|
||||||
|
34
srcs/main.c
34
srcs/main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/11/18 13:09:55 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);
|
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)
|
int main(void)
|
||||||
{
|
{
|
||||||
char *cmd;
|
char *cmd;
|
||||||
@ -96,7 +126,7 @@ int main(void)
|
|||||||
ft_lstdel(&lst_env, &ft_lstdelstr);
|
ft_lstdel(&lst_env, &ft_lstdelstr);
|
||||||
ft_strdel(&cmd);
|
ft_strdel(&cmd);
|
||||||
return (2);
|
return (2);
|
||||||
}
|
}
|
||||||
if (ft_strcmp("exit", cmd) == 0)
|
if (ft_strcmp("exit", cmd) == 0)
|
||||||
{
|
{
|
||||||
ft_lstdel(&lst_env, &ft_lstdelstr);
|
ft_lstdel(&lst_env, &ft_lstdelstr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user