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); }
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); }
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); } }
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); }
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); }
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); }
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); }
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); } }
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); } }