diff --git a/42sh/Makefile b/42sh/Makefile index 1f8b85d0..dbbdd149 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -270,7 +270,6 @@ main/data_singleton.c\ main/ft_putast.c\ main/instruction_free.c\ main/main.c\ -main/shell_get_avdata.c\ main/shell_get_opts.c\ main/shell_init.c\ parser/add_bang.c\ diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index 5f27f108..69999869 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -16,6 +16,8 @@ # include "libft.h" # include "builtin_read.h" +# define BT_EXPORT_LP (1 << 0) + t_execf *is_builtin(t_process *p); int builtin_export(const char *path, char *const av[], char *const envp[]); int builtin_unset(const char *path, char *const av[], char *const envp[]); diff --git a/42sh/includes/builtin_read.h b/42sh/includes/builtin_read.h index e0ebfc9f..1b656655 100644 --- a/42sh/includes/builtin_read.h +++ b/42sh/includes/builtin_read.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */ -/* Updated: 2017/03/13 20:39:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 19:57:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index b6564b2b..83104812 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/13 23:02:23 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 20:34:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 21c50f1b..9a445751 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/12 01:01:44 by ariard ### ########.fr */ +/* Updated: 2017/03/14 19:58:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/types.h b/42sh/includes/types.h index e6f8d640..e35c78d9 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/14 00:49:40 by ariard ### ########.fr */ +/* Updated: 2017/03/14 20:25:53 by jhalford ### ########.fr */ /* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,9 +38,10 @@ typedef struct s_comp t_comp; typedef struct s_exec t_exec; typedef struct s_jobc t_jobc; typedef enum e_mode t_mode; +typedef struct s_data_template t_btexport; /* -** Execution types +** Lexer types */ typedef struct s_lexer t_lexer; diff --git a/42sh/libft b/42sh/libft index b209bb1f..2713f7ab 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6 +Subproject commit 2713f7ab295d895824b22ac39524f85a7e5b7985 diff --git a/42sh/src/builtin/bt_read_get.c b/42sh/src/builtin/bt_read_get.c index 575d694e..24b79c3c 100644 --- a/42sh/src/builtin/bt_read_get.c +++ b/42sh/src/builtin/bt_read_get.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */ -/* Updated: 2017/03/07 11:27:49 by ariard ### ########.fr */ +/* Updated: 2017/03/14 18:11:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_export.c b/42sh/src/builtin/builtin_export.c index bdf78140..03bea7ec 100644 --- a/42sh/src/builtin/builtin_export.c +++ b/42sh/src/builtin/builtin_export.c @@ -6,20 +6,63 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */ -/* Updated: 2017/03/13 19:00:58 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 21:10:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int builtin_export(const char *path, char *const av[], char *const envp[]) +t_cliopts opts[] = { + {'p', NULL, BT_EXPORT_LP, 0, NULL}, + {0, NULL, 0, 0, NULL}, +}; + +int bt_export_print(void) +{ + char **env; char *equal; - if ((equal = ft_strchr(av[1], '='))) + env = data_singleton()->env; + while (*env) { - *equal = 0; - builtin_setenv(path, (char*[]){"setenv", av[1], equal + 1}, envp); + if ((equal = ft_strchr(*env, '='))) + ft_printf("export %s\n", *env); + else + ft_printf("export %s\n", *env); + env++; + } + return (0); +} + +int builtin_export(const char *path, char *const av[], char *const envp[]) +{ + char *equal; + t_btexport data; + int i; + + i = 0; + (void)envp; + (void)path; + if (cliopts_get((char**)av, opts, &data)) + ft_perror(); + if (data.flag & BT_EXPORT_LP) + return (bt_export_print()); + av = cliopts_getdata((char**)av); + while (*av) + { + if ((equal = ft_strchr(*av, '='))) + { + *equal = 0; + builtin_setenv("internal", (char*[]){"global", *av, equal + 1}, NULL); + } + else + { + equal = ft_getenv(data_singleton()->local_var, *av); + builtin_setenv("internal", (char*[]){"global", *av, equal}, NULL); + } + builtin_unsetenv("internal", (char*[]){"local", *av}, NULL); + av++; } return (0); } diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index 264f2b3b..8fdc0361 100644 --- a/42sh/src/builtin/builtin_read.c +++ b/42sh/src/builtin/builtin_read.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */ -/* Updated: 2017/02/06 14:02:17 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 18:08:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index 95316f18..b145cb2c 100644 --- a/42sh/src/builtin/builtin_setenv.c +++ b/42sh/src/builtin/builtin_setenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/03/14 00:44:32 by ariard ### ########.fr */ +/* Updated: 2017/03/14 21:10:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,13 +21,9 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[]) (void)envp; (void)path; i = 0; - DG("in setenv"); env = ft_strcmp(av[0], "local") == 0 ? &data_singleton()->local_var : &data_singleton()->env; - if (ft_strcmp(av[0], "setenv") == 0 - || ft_strcmp(av[0], "export") == 0 - || ft_strcmp(av[0], "local") == 0) - av++; + av++; if (!av[0]) { ft_sstrprint(*env, '\n'); diff --git a/42sh/src/builtin/builtin_unsetenv.c b/42sh/src/builtin/builtin_unsetenv.c index d684462a..2081f600 100644 --- a/42sh/src/builtin/builtin_unsetenv.c +++ b/42sh/src/builtin/builtin_unsetenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:29:17 by jhalford #+# #+# */ -/* Updated: 2016/12/03 11:55:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 21:08:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,8 @@ int builtin_unsetenv(const char *path, char *const av[], char *const envp[]) (void)envp; (void)path; - env = &data_singleton()->env; + env = ft_strcmp(av[0], "local") == 0 ? + &data_singleton()->local_var : &data_singleton()->env; i = 1; while (av[i]) { diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 16b4dd82..1404e6a9 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/13 23:56:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 20:26:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_var.c b/42sh/src/exec/exec_var.c index 578422d2..194309ae 100644 --- a/42sh/src/exec/exec_var.c +++ b/42sh/src/exec/exec_var.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ -/* Updated: 2017/03/07 18:37:38 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 21:09:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,6 @@ int exec_var(t_btree **ast) node = (*ast)->item; av = token_to_argv(node->data.cmd.token, 1); set_var(av[0], &var, &value); - builtin_setenv("setenv", (char*[]){var, value, 0}, data_singleton()->local_var); + builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL); return (0); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 4da9ed74..b93491e2 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/13 23:58:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 20:49:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -82,7 +82,7 @@ int handle_instruction(int fd) return (0); } -int get_input_fd() +int get_input_fd(char **av) { t_data *data; char *file; @@ -96,13 +96,15 @@ int get_input_fd() { pipe(fds); fd = fds[PIPE_READ]; - file = shell_get_avdata(); + /* file = shell_get_avdata(); */ + file = *cliopts_getdata(av); write(fds[PIPE_WRITE], file, ft_strlen(file)); close(fds[PIPE_WRITE]); fcntl(fd, F_SETFD, FD_CLOEXEC); return (fd); } - else if ((file = shell_get_avdata())) + /* else if ((file = shell_get_avdata())) */ + else if ((file = *cliopts_getdata(av))) { if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0) return (-1); @@ -116,12 +118,13 @@ int main(int ac, char **av) { int fd; + g_argv = av; setlocale(LC_ALL, ""); DG("{inv}{bol}{gre}start of shell{eoc}"); shell_init(ac, av); - if ((fd = get_input_fd()) < 0) + if ((fd = get_input_fd(av)) < 0) { - ft_printf("{red}%s: %s: No such file or directory\n{eoc}", SHELL_NAME, shell_get_avdata()); + ft_printf("{red}%s: %s: No such file or directory\n{eoc}", SHELL_NAME, *cliopts_getdata(av)); return (1); } DG("JOBC is %s, fd=[%i]", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd); diff --git a/42sh/src/main/shell_get_avdata.c b/42sh/src/main/shell_get_avdata.c deleted file mode 100644 index 16a34d13..00000000 --- a/42sh/src/main/shell_get_avdata.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* shell_get_avdata.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/11 17:14:52 by jhalford #+# #+# */ -/* Updated: 2017/03/03 17:33:33 by wescande ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -char *shell_get_avdata() -{ - t_data *data; - char **av; - int i; - - data = data_singleton(); - av = data->argv; - i = 1; - while (av[i] && av[i][0] == '-') - { - if (ft_strcmp(av[i], "--") == 0) - { - i++; - break ; - } - i++; - } - return(av[i]); -} diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 1844fe2e..d198c59a 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/14 11:09:31 by gwojda ### ########.fr */ +/* Updated: 2017/03/14 21:10:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */