Beispiel #1
0
int		stock_env(t_group *grp, char **env)
{
	int		i;
	char	*pwd;
	char	*old_pwd;
	char	buf[512];

	pwd = JOIN("PWD=", getcwd(buf, 512));
	insert_env(grp, pwd);
	old_pwd = JOIN("OLDPWD=", ft_getenv(grp, "PWD"));
	insert_env(grp, old_pwd);
	insert_env(grp, "SHLVL=1");
	i = -1;
	while (env[++i] != NULL)
		insert_env(grp, env[i]);
	insert_env(grp, "_=/usr/bin/env");
	return (1);
}
Beispiel #2
0
void	shlvl(t_group *grp)
{
	char	*shlvl;
	int		lvl;

	lvl = ft_atoi(ft_getenv(grp, "SHLVL"));
	lvl++;
	shlvl = ft_itoa(lvl);
	shlvl = JOIN("SHLVL=", shlvl);
	insert_env(grp, shlvl);
}
Beispiel #3
0
void		ft_setenv(t_env *list, char **tab, char *line)
{
	t_env	*tmp;

	if (ft_count_word(line, ' ') != 4)
	{
		ft_putstr("ft_minishell2: setenv usage : name value overwrite\n");
		return ;
	}
	tmp = list;
	while (tmp != NULL)
	{
		if (ft_strcmp(tmp->name, tab[1]) == 0)
		{
			if (ft_strcmp(tab[3], "1") == 0)
				tmp->value = tab[2];
			return ;
		}
		tmp = tmp->next;
	}
	tmp = insert_env(list, tab[1], tab[2]);
}
Beispiel #4
0
void	ft_setenv(t_group *grp)
{
	int		i;
	t_bool	error;

	i = 0;
	error = false;
	if (grp->cmd[1] == NULL)
	{
		ft_putendl("setenv: set argument(s) -> key=value or key=");
		return ;
	}
	while (grp->cmd[++i] != NULL)
	{
		if (insert_env(grp, grp->cmd[i]) < 0)
		{
			ft_putstr("setenv: bad synthax -> ");
			ft_putendl(grp->cmd[i]);
			error = true;
		}
	}
	error ? ft_putendl("setenv: synthax -> key=value or key=") : 0;
}
Beispiel #5
0
void	ft_setenv(t_group *grp)
{
	int		i;
	t_bool	error;

	i = 0;
	error = grp->cmd[1] != NULL ? false : true;
	while (grp->cmd[++i] != NULL)
	{
		if (!ft_strncmp(grp->cmd[i], "_", 1) ||
			!ft_strncmp(grp->cmd[i], "SHLVL", 5))
		{
			ft_putendl_fd("setenv: \"SHLVL\" and \"_\" can't be modify", 2);
			break ;
		}
		else if (insert_env(grp, grp->cmd[i]) < 0)
		{
			ft_putstr_fd("setenv: bad synthax -> ", 2);
			ft_putendl_fd(grp->cmd[i], 2);
			error = true;
		}
	}
	error ? ft_putendl_fd("setenv: synthax -> key=value or key=", 2) : 0;
}