export finished, added cliopts
This commit is contained in:
parent
9545cb5e00
commit
4572a81c5a
17 changed files with 77 additions and 66 deletions
|
|
@ -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\
|
||||
|
|
|
|||
|
|
@ -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[]);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6
|
||||
Subproject commit 2713f7ab295d895824b22ac39524f85a7e5b7985
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,20 +6,63 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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');
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* shell_get_avdata.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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]);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue