rectif setenv et mise a la norme. Ajout data init des IFS + data init du SHLVL
This commit is contained in:
parent
39d5b25084
commit
d4c4722884
3 changed files with 39 additions and 28 deletions
|
|
@ -6,51 +6,53 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/15 10:47:33 by gwojda ### ########.fr */
|
/* Updated: 2017/03/15 16:29:51 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int builtin_setenv(const char *path, char *const av[], char *const envp[])
|
static int assign_var(char *const av[], char ***env)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
char ***env;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
str = ft_str3join(av[1], "=", av[2]);
|
||||||
|
while ((*env) && (*env)[++i])
|
||||||
|
{
|
||||||
|
if (ft_strcmp((*env)[i], av[1]) == '='
|
||||||
|
&& ft_strlen(av[1]) == ft_strlenchr((*env)[i], '='))
|
||||||
|
{
|
||||||
|
ft_strdel(&(*env)[i]);
|
||||||
|
(*env)[i] = str;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*env = ft_sstradd(*env, str);
|
||||||
|
ft_strdel(&str);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int builtin_setenv(const char *path,
|
||||||
|
char *const av[], char *const envp[])
|
||||||
|
{
|
||||||
|
char ***env;
|
||||||
|
|
||||||
(void)envp;
|
(void)envp;
|
||||||
(void)path;
|
(void)path;
|
||||||
i = 0;
|
if (!av || !av[0])
|
||||||
|
return (1);
|
||||||
if (ft_strcmp(av[0], "local") == 0)
|
if (ft_strcmp(av[0], "local") == 0)
|
||||||
{
|
|
||||||
env = &data_singleton()->local_var;
|
env = &data_singleton()->local_var;
|
||||||
av++;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
env = &data_singleton()->env;
|
env = &data_singleton()->env;
|
||||||
av++;
|
if (!av[1])
|
||||||
if (!av[0])
|
|
||||||
{
|
{
|
||||||
ft_sstrprint(*env, '\n');
|
ft_sstrprint(*env, '\n');
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
}
|
}
|
||||||
else if (!av[1])
|
|
||||||
ft_putendl_fd("usage : name [space] value", 2);
|
|
||||||
else
|
else
|
||||||
{
|
return (assign_var(av, env));
|
||||||
str = ft_str3join(av[0], "=", av[1]);
|
|
||||||
while ((*env) && (*env)[i])
|
|
||||||
{
|
|
||||||
if (ft_strcmp((*env)[i], av[0]) == '=')
|
|
||||||
{
|
|
||||||
ft_strdel(&(*env)[i]);
|
|
||||||
(*env)[i] = str;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
*env = ft_sstradd(*env, str);
|
|
||||||
ft_strdel(&str);
|
|
||||||
}
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/14 22:32:24 by ariard ### ########.fr */
|
/* Updated: 2017/03/15 15:58:53 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,6 +19,7 @@ t_stof g_builtin[] =
|
||||||
{"export", &builtin_export},
|
{"export", &builtin_export},
|
||||||
{"unset", &builtin_unset},
|
{"unset", &builtin_unset},
|
||||||
{"setenv", &builtin_setenv},
|
{"setenv", &builtin_setenv},
|
||||||
|
{"local", &builtin_setenv},
|
||||||
{"unsetenv", &builtin_unsetenv},
|
{"unsetenv", &builtin_unsetenv},
|
||||||
{"env", &builtin_env},
|
{"env", &builtin_env},
|
||||||
{"exit", &builtin_exit},
|
{"exit", &builtin_exit},
|
||||||
|
|
@ -40,7 +41,10 @@ t_execf *is_builtin(t_process *p)
|
||||||
while (g_builtin[++i].name)
|
while (g_builtin[++i].name)
|
||||||
{
|
{
|
||||||
if (ft_strcmp(g_builtin[i].name, p->data.cmd.av[0]) == 0)
|
if (ft_strcmp(g_builtin[i].name, p->data.cmd.av[0]) == 0)
|
||||||
|
{
|
||||||
|
DG();
|
||||||
return (g_builtin[i].f);
|
return (g_builtin[i].f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/14 21:39:13 by jhalford ### ########.fr */
|
/* Updated: 2017/03/15 16:23:18 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,13 +18,18 @@ int data_init(int ac, char **av)
|
||||||
{
|
{
|
||||||
t_data *data;
|
t_data *data;
|
||||||
char *term_name;
|
char *term_name;
|
||||||
|
char* shlvl;
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
data->argc = ac;
|
data->argc = ac;
|
||||||
data->argv = ft_sstrdup(av);
|
data->argv = ft_sstrdup(av);
|
||||||
data->env = ft_sstrdup(environ);
|
data->env = ft_sstrdup(environ);
|
||||||
data->local_var = NULL;
|
data->local_var = NULL;
|
||||||
|
builtin_setenv(NULL, (char *[]){"local", "IFS", "\n ", 0}, NULL);
|
||||||
set_exitstatus(0, 1);
|
set_exitstatus(0, 1);
|
||||||
|
shlvl = ft_itoa(ft_atoi(ft_getenv(data->env, "SHLVL")) + 1);
|
||||||
|
builtin_setenv(NULL, (char *[]){"setenv", "SHLVL", shlvl, 0}, NULL);
|
||||||
|
ft_strdel(&shlvl);
|
||||||
data->comp = NULL;
|
data->comp = NULL;
|
||||||
data->opts = 0;
|
data->opts = 0;
|
||||||
exec_reset();
|
exec_reset();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue