Beispiel #1
0
Datei: red.c Projekt: jalcim/42sh
int			double_rightbis(char *line, t_sh *t, char *l_p, int i)
{
	int		d;
	int		wak;

	d = dup(1);
	dup2(t->fd1, 1);
	while (read(t->fd1, &wak, 1) > 0)
		;
	close(t->fd1);
	exec_cmd(t);
	dup2(d, 1);
	close(d);
	if (line[i] && (OPE2(line, i) || PIPOR(line, i)))
	{
		t->pv2 = i;
		if (OPE2(line, i) && have_pipe(line, i, t) == t->pv2)
			return (ft_red(line, t));
		i = t->pv2;
		pre_parse(l_p, line, i, t);
		if (line[t->pv2] && line[t->pv2] == '>')
			return (ft_red(line, t));
		return (t->pv2);
	}
	return (t->pv2 = i);
}
Beispiel #2
0
int		exec_fath(char *line, t_sh *t)
{
	if (t->save_c)
		wait(0);
	t->pv = ++t->pv2;
	while (line[t->pv2]
		&& !search_ope(&line[t->pv2], t->ope, 1))
		t->pv2++;
	close(t->pipe_fd[1]);
	dup2(t->pipe_fd[0], 0);
	close(t->pipe_fd[1]);
	t->args = ft_strsplitsh(ft_strsub(line, t->pv, t->pv2 - t->pv));
	if (line[t->pv2] == '|' || line[t->pv2] == '>')
	{
		if (line[t->pv2] != '|')
			return (ft_red(line, t));
		else if (line[t->pv2 + 1] && !search_ope(&line[t->pv2 + 1], t->ope, 1))
			return (exec_pipes(line, t));
		else if (line[t->pv2 + 1] && line[t->pv2 + 1] != '|')
			return (parse_error(line, t, t->pv2 + 1));
		t->flag = line[t->pv2];
	}
	exec_cmd(t);
	return (t->pv2);
}
Beispiel #3
0
Datei: ft_cd.c Projekt: kedric/42
static t_gen	*ft_docd(char *path, t_gen *env, int ih, int ip)
{
	char		*s;
	char		*tmp;

	tmp = ft_dellast(env->env[ih] + 5);
	if (path[0] == '~' && path[1] == '/')
		s = ft_red(path + 2, env->env[ih] + 5);
	else if (path[0] == '~')
		s = ft_red(path + 1, tmp);
	else if (path[0] == '/')
		s = ft_red(path + 1, NULL);
	else if (ft_strcmp(path, "-") == 0)
		s = ft_strdup(&(env->env[ft_found("OLDPWD", env)][7]));
	else
		s = ft_red(path, env->env[ip] + 5);
	ft_checkaccess(s, env, ip);
	free(s);
	free(tmp);
	return (env);
}
Beispiel #4
0
Datei: red.c Projekt: jalcim/42sh
int			left_red_next(int i, t_sh *t, char **line)
{
	char	*l_p;

	l_p = NULL;
	t->pv2 = i;
	if (OPE2(*line, i) && have_pipe(*line, i, t) == t->pv2)
	{
		ft_red(*line, t);
		dup2(t->dupl, 0);
		close(t->dupl);
		t->fd1 = 0;
		return (t->pv2);
	}
	i = t->pv2;
	pre_parse(l_p, *line, i, t);
	dup2(t->dupl, 0);
	close(t->dupl);
	t->fd1 = 0;
	if ((*line)[t->pv2] && OPE2(*line, i))
		return (ft_red(*line, t));
	return (t->pv2);
}