示例#1
0
文件: ft_sh2.c 项目: Erwanito/42sh
void	ft_sh2(t_line *tree, char ***newenv)
{
	int		fd[2];

	if (tree->type == 1)
		ft_execcmd(tree->cmd, newenv);
	if (tree->type == 2)
	{
		pipe(fd);
		ft_pipe(tree, newenv, fd);
	}
	if (tree->type == 3)
		ft_right(tree, newenv, 1);
	if (tree->type == 4)
		ft_left(tree, newenv);
	if (tree->type == 5)
		ft_right(tree, newenv, 2);
	if (tree->type == 7 || tree->type == 8)
		ft_logic_opp(tree, newenv);
}
示例#2
0
static void	ft_checkcmd(char *cmdline, t_conf *config)
{
	char		**cmdline_split;
	static void	(*tabf[5])(t_conf *, char **) = {&ft_cd, &ft_exit,
		&ft_unsetenv, &ft_env, &ft_setenv};
	int			builtin;
	t_bin		*cmd;

	cmd = NULL;
	if (!cmdline || !*cmdline || !(cmdline_split = ft_strsplit(cmdline, ' ')))
		return ;
	if ((builtin = ft_findbuiltin(*cmdline_split)) != -1)
		(tabf[builtin])(config, cmdline_split);
	else if (*cmdline_split[0] == '/' ||
			*cmdline_split[0] == '.' ||
			(cmd = ft_findcmd(*cmdline_split, ft_hashsearch(config,
															*cmdline_split))))
		ft_execcmd(cmd, cmdline_split, config);
	else
		ft_error(*cmdline_split, CMD_NOTFOUND, KEEP);
	ft_free_split(cmdline_split);
	free(cmdline_split);
}