コード例 #1
0
ファイル: main_test.c プロジェクト: Mouradif/Hexter
int		main(int ac, char **av)
{
	int	i;
	int	fd;

	if (ac > 1)
	{
		i = 1;
		while (i < ac)
		{
			fd = open(av[i], O_RDONLY);
			if (fd == -1)
				ft_errno(8);
			if (!g_errno)
				ft_execute(fd);
			else
			{
				ft_putnbr(g_errno);
				ft_putstr("Map error\n");
			}
			i++;
		}
	}
	else
		ft_execute(STDIN_FILENO);
	return (0);
}
コード例 #2
0
ファイル: loop.c プロジェクト: Oex999/Minishell
void	ft_loop(t_env *env)
{
	char	*line;
	char	**cmds;
	char	**args;
	int		status;

	status = 1;
	ft_getenv("USER", &env->username, &env);
	ft_printf("\033c");
	while (status)
	{
		ft_printf("[%s]$>", env->username);
		get_next_line(0, &line);
		cmds = ft_splitcommands(line);
		while (*cmds)
		{
			args = ft_split(*cmds);
			status = ft_execute(args, &env);
			if (status == 0)
				break ;
			cmds++;
		}
	}
	free(env->username);
}
コード例 #3
0
ファイル: ft_pipe.c プロジェクト: vikingeff/pipex
void	ft_begin(t_cmd *arg)
{
	int		childpid;
	int		fd;
	int		fd2;

	pipe(arg->fd);
	if ((childpid = fork()) == -1)
		ft_fork_error();
	if (childpid == 0)
	{
		fd = ft_check_file(arg->av[1], R_OK);
		dup2(fd, 0);
		dup2(arg->fd[1], 1);
		close(arg->fd[0]);
		ft_execute(arg);
	}
	if (childpid > 0)
	{
		fd2 = ft_check_file_exist(arg);
		dup2(fd2, 1);
		dup2(arg->fd[0], 0);
		close(arg->fd[1]);
		ft_execute_2(arg);
	}
}
コード例 #4
0
ファイル: pipex.c プロジェクト: fnormand/PipeX
void		parent(int *fds, int fd, t_args *ptr, char **envp)
{
	close(fds[1]);
	dup2(fds[0], 0);
	close(fds[0]);
	dup2(fd, 1);
	ft_execute(ptr->path, ptr->cmd2, envp);
}
コード例 #5
0
ファイル: pipex.c プロジェクト: fnormand/PipeX
void		child(int *fds, int fd, t_args *ptr, char **envp)
{
	if (fd == -1)
		error();
	close(fds[0]);
	dup2(fds[1], 1);
	dup2(fd, 0);
	close(fds[1]);
	ft_execute(ptr->path, ptr->cmd1, envp);
}
コード例 #6
0
void	ft_ex_command(t_ex *ex_info)
{
	pid_t	pid;
	int		ret;

	pid = fork();
	if (pid == 0)
	{
		ft_execute(ex_info);
		ft_error(ex_info);
		exit(0);
	}
	if (pid > 0)
		wait(&ret);
}
コード例 #7
0
int			command_execute_simple(t_list *arg,
                                   t_cmd *cmd, t_env *env, t_dir *dir)
{
    int *fd;
    int save[2];
    int	ret;

    save[0] = dup(0);
    save[1] = dup(1);
    fd = ft_init_fd(arg);
    if (fd == NULL)
        return (1);
    ret = ft_execute(arg, cmd, env, dir);
    ft_close(fd);
    ft_reverse_fd(save);
    free(fd);
    return (ret);
}
コード例 #8
0
ファイル: operation_on_command.c プロジェクト: Succubae/42
void	ft_not_builtins_fd_right(char **p, char **arg, char ***env, t_ast *ast)
{
	int		status;
	int		i;
	int		fildes;
	char	**cmd;

	if ((i = fork()) > 0)
		waitpid(-1, &status, WNOHANG & WUNTRACED);
	else if (i == 0)
	{
		cmd = ft_strsplit(ast->right, ' ');
		if ((fildes = create_file(cmd[0])) == -1)
			return ;
		dup2(fildes, 1);
		ft_execute(p, arg, env);
	}
}
コード例 #9
0
ファイル: operation_on_command.c プロジェクト: Succubae/42
void	ft_not_builtins_fd_left(char **p, char **arg, char ***env, t_ast *ast)
{
	int		status;
	int		i;
	int		fildes;
	char	**cmd;

	if ((i = fork()) > 0)
		waitpid(-1, &status, WNOHANG & WUNTRACED);
	else if (i == 0)
	{
		cmd = ft_strsplit(ast->right, ' ');
		if ((fildes = open_file(cmd[0])) == -1)
			ft_error_exit("{f_n_b_f_l} An error occurred while opening file");
		dup2(fildes, 0);
		close(fildes);
		ft_execute(p, arg, env);
	}
}