diff --git a/srcs/exec.c b/srcs/exec.c index d41cd89..92dbcc4 100755 --- a/srcs/exec.c +++ b/srcs/exec.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */ -/* Updated: 2024/02/28 18:53:41 by marde-vr ### ########.fr */ +/* Updated: 2024/03/02 16:48:46 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -155,6 +155,7 @@ void redirect_input(t_msh *msh, int i) } else if (i > 0) { + ft_printf_fd(2, "input_fd: %d\n", msh->fds[i - 1][0]); if (dup2(msh->fds[i - 1][0], 0) < 0) ft_exit(msh, 1); } @@ -178,12 +179,12 @@ void pipe_child(t_msh *msh, char **cmd_args, int i) { if (msh->in_type != ARG) { - //ft_printf_fd(2, "redirecting input of %s of type %d\n", msh->cmds->token, msh->in_type); + ft_printf_fd(2, "redirecting input of %s of type %d with fd %d\n", msh->cmds->token, msh->in_type, msh->in_fd); redirect_input(msh, i); } if (msh->out_type != ARG) { - //ft_printf_fd(2, "redirecting output of %s of type %d\n", msh->cmds->token, msh->out_type); + ft_printf_fd(2, "redirecting output of %s of type %d with fd %d\n", msh->cmds->token, msh->out_type, msh->out_fd); redirect_output(msh, i); } if (i != 0) @@ -358,8 +359,8 @@ void get_in_type(t_msh *msh) handle_here_doc(msh, cur_cmd->token); if (msh->in_type == RED_I) { - //ft_printf_fd(2, "opening %s\n", cur_cmd->token); msh->in_fd = open(cur_cmd->token, O_RDONLY); + ft_printf_fd(2, "opened %s: %d\n", cur_cmd->token, msh->in_fd); if (msh->in_fd == -1) { ft_printf_fd(2, "minishell: %s: ", cur_cmd->token); @@ -367,8 +368,8 @@ void get_in_type(t_msh *msh) // todo: cancel execution of all commands } } - cur_cmd = cur_cmd->next; - msh->cmds = cur_cmd; + //cur_cmd = cur_cmd->next; + //msh->cmds = cur_cmd; //ft_printf_fd(2, "cmd: %s\n", msh->cmds->token); } } @@ -380,6 +381,7 @@ void get_out_type(t_msh *msh) t_cmd *cur_cmd; msh->out_type = ARG; + msh->out_fd = 0; cur_cmd = msh->cmds; while (cur_cmd && cur_cmd->next && cur_cmd->type == ARG) cur_cmd = cur_cmd->next; @@ -394,6 +396,8 @@ void get_out_type(t_msh *msh) if (msh->out_type == RED_O_APP) msh->out_fd = open(cur_cmd->next->token, O_CREAT | O_RDWR | O_APPEND, 0644); + if (msh->out_fd) // debug + ft_printf_fd(2, "opened %s: %d\n", cur_cmd->next->token, msh->out_fd); if (msh->out_fd == -1) { perror("open"); @@ -424,6 +428,7 @@ void exec_command(t_msh *msh) ft_exit(msh, 1); get_in_type(msh); get_out_type(msh); + ft_printf_fd(2, "%d\n", msh->out_fd); //ft_printf_fd(2, "cmd: %s\n", msh->cmds->token); if (!cmd_is_builtin(msh, msh->cmds->token)) get_cmd_path(msh); diff --git a/srcs/main.c b/srcs/main.c index ac93de0..bdae764 100755 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ -/* Updated: 2024/02/26 15:28:23 by marde-vr ### ########.fr */ +/* Updated: 2024/03/02 16:13:58 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -88,7 +88,7 @@ int main(int argc, char **argv, char **envp) command = (char *)1; init_minishell(&msh, argc, argv, envp); - //handle_minishellrc(msh); + handle_minishellrc(msh); while (msh->env && command) { prompt = get_prompt(msh->env); @@ -99,9 +99,8 @@ int main(int argc, char **argv, char **envp) add_history(command); msh->cmds = parse_command(command, msh->env); free(command); - //print_parsed_cmd(parsed_cmd);//debug msh->cmds = handle_alias(msh); - //print_parsed_cmd(parsed_cmd);//debug + //print_parsed_cmd(msh->cmds); exec_command(msh); free_cmd(msh->cmds); } diff --git a/srcs/minishellrc.c b/srcs/minishellrc.c index 8e585ce..6a39cf0 100644 --- a/srcs/minishellrc.c +++ b/srcs/minishellrc.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/16 17:40:16 by marde-vr #+# #+# */ -/* Updated: 2024/02/26 15:24:28 by marde-vr ### ########.fr */ +/* Updated: 2024/02/29 13:13:15 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ void exec_rc_file(t_msh *msh, int fd) msh->cmds = parse_command(line, msh->env); exec_command(msh); free_cmd(msh->cmds); - free(line); + //free(line); } free(line); line = get_next_line(fd);