Esempio n. 1
0
int				cmd(char *s, int cs)
{
	pid_t	pid;
	int		status;
	char	**spt;

	if (!s || !*s)
		return (0);
	spt = ft_getarg(s);
	if (!ft_strcmp(spt[0], "get"))
	{
		ft_get(spt, cs);
		return (0);
	}
	if (!ft_strcmp(spt[0], "cd"))
	{
		ft_cd(spt[1], cs);
		return (0);
	}
	if (!(pid = fork()))
		ft_launch(s, cs);
	else if (pid > 0)
		wait4(pid, &status, 0, NULL);
	else if (pid == -1)
		ft_putendl_fd("fork", 2);
	return (1);
}
Esempio n. 2
0
void	ft_build_env(t_seq *seq)
{
	char	*tmp_args;
	char	**environ;
	char	**tab;
	t_seq	*tmp;
	int		index[2];

	tab = ft_strsplit(seq->args, ' ');
	index[0] = 0;
	while (ft_strstr(tab[index[0] + 1], "="))
		(index[0])++;
	if (index[0] > 0 && (index[1] = -1))
	{
		if ((environ = (char **)ft_malloc(sizeof(char *) * (index[0] + 1))))
		{
			while (++(index[1]) < index[0])
				environ[index[1]] = tab[index[1] + 1];
			environ[index[1]] = NULL;
		}
	}
	else
		environ = NULL;
	tmp_args = ft_strstr(seq->args, tab[index[0] + 1]);
	tmp = ft_lexer(tmp_args);
	ft_launch(1, tmp, environ);
	ft_lib_env(tab, tmp, environ);
}