Skip to content

Commit

Permalink
lol again
Browse files Browse the repository at this point in the history
  • Loading branch information
Qarl Cesar committed Nov 13, 2021
1 parent 9ca935f commit 02ab27b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NAME = minishell

CC = gcc
FLAGS = -Wall -Wextra -L/Users/heveline/.brew/opt/readline/lib -I/Users/heveline/.brew/opt/readline/include
FLAGS = -Wall -Wextra -L/Users/$(USER)/.brew/opt/readline/lib -I/Users/$(USER)/.brew/opt/readline/include

LIBFT = $(LIBFT_DIRECTORY)libft.a
LIBFT_DIRECTORY = ./libft/
Expand Down
5 changes: 3 additions & 2 deletions envp.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ void binary_command(t_ast *ast, char **cmd_array, t_env **env_list, t_ctrl *con
ast_data_free(val);
env = env_array(env_list);
path = path_handler(cmd_array[0], env);
ft_putendl_fd("are you in the exec?", 2);
// printf("%s\n", path);
if (execve(path, cmd_array, env) == -1)
ft_err("Error: command not executable");
}
else
waitpid(pid, &i, 0);
waitpid(pid, &i, 0);
ft_putendl_fd("in binary before set exit", 2);
set_exit(i/256);
}
4 changes: 3 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void tree(char **array, t_ctrl *control, char **envp)

ast = NULL;
ast = tree_create(ast, array);
//tree_print_rec(ast, 0);
tree_print_rec(ast, 0);
tree_handle(ast, control, envp);
tree_free(&ast);
}
Expand Down Expand Up @@ -75,6 +75,8 @@ int main(int ac, char **av, char **env)
}
add_history(line);
array = parsing(line, env);
if (!array || !array[0])
continue;
tree(array, control, env);
}
clear_history();
Expand Down
1 change: 1 addition & 0 deletions minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void right_redir(t_ast *ast, t_ctrl *control, t_ast_data *val,char **envp);
void left_redir(t_ast *ast, t_ctrl *control, t_ast_data *val, char **envp);
void pipe_func(t_ast *ast, t_ctrl *control, t_ast_data *val,char **envp);
void ctrl_free(t_ctrl *control);
void ast_data_default(t_ast_data *val);
//----set_exit.c-----//
static int new_exit(const int *id);
int get_exit(void);
Expand Down
50 changes: 37 additions & 13 deletions redirects.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ void right_redir(t_ast *ast, t_ctrl *control, t_ast_data *val,char **envp)
go_through_nodes(ast->left, control, val, envp);
}
}

/*
void pipe_child(t_ast *ast, t_ctrl *control, t_ast_data *val,char **envp)
{
int fork_pid;
int pipe_des[2];
if (pipe(pipe_des) < 0)
ft_err("pipe problem");
fork_pid = fork();
//check for -1
Expand All @@ -80,23 +77,50 @@ void pipe_child(t_ast *ast, t_ctrl *control, t_ast_data *val,char **envp)
}
exit(1);
}
}*/

void pipe_func(t_ast *ast, t_ctrl *control, t_ast_data *val,char **envp)
{
int fork_pid;
int fork_pid[2];
int pipe_des[2];
int status;

fork_pid = fork();
//check condition here
if (pipe(pipe_des) < 0)
ft_err("pipe problem");

if (fork_pid == 0)

//check condition here
val->out = pipe_des[1];
fork_pid[0] = fork();
if (fork_pid[0] == 0)
{
control->pid = 0;
pipe_child(ast, control, val, envp);
go_through_nodes(ast->left, control, val, envp);
}
else
ast_data_default(val);
val->in = pipe_des[0];

ft_putendl_fd("hey1", 2);
fork_pid[1] = fork();
if (fork_pid[1] == 0)
{
waitpid(fork_pid, NULL, 0);
// control->exit_status = WIFEXITED(status) ? WEXITSTATUS(status) : g_sig;
ft_putendl_fd("hey2", 2);
ft_putnbr_fd(getpid(), 2);
ft_putendl_fd("", 2);
control->pid = 0;
go_through_nodes(ast->right, control, val, envp);
ft_putendl_fd("hey4", 2);
}
close(pipe_des[0]);
close(pipe_des[1]);
ft_putendl_fd("hey3", 2);
ft_putnbr_fd(getpid(), 2);
ft_putendl_fd("", 2);
waitpid(fork_pid[0], 0, 0);
waitpid(fork_pid[1], &status, 0);
set_exit(status/256);
if (control->pid == 0)
exit(get_exit());
// control->exit_status = WIFEXITED(status) ? WEXITSTATUS(status) : g_sig;

}
7 changes: 5 additions & 2 deletions tree_handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ void cmd_commands(t_ast *ast, t_ctrl *control, t_ast_data *val, char **envp)
{
char **cmd_array;


cmd_array = split_values(ast->value, envp);
ft_putendl_fd("in cmd", 2);
if (cmd_array[0] == NULL)
{
empty_cmd(ast, control, val, cmd_array);
Expand Down Expand Up @@ -240,15 +242,15 @@ void ctrl_free(t_ctrl *control)
void ast_data_default(t_ast_data *val)
{
int i;

/*
if (val->pipe)
{
i = 0;
while (val->pipe[i] != -1)
close(val->pipe[i++]);
free(val->pipe);
val->pipe = NULL;
}
}*/
if (val->file)
{
i = 0;
Expand All @@ -271,6 +273,7 @@ void go_through_nodes(t_ast *ast, t_ctrl *control, t_ast_data *val, char **en
{
if (!ast)
{
ft_putendl_fd("hey1111", 2);
if (control->pid == 0)
{
ctrl_free(control);
Expand Down

0 comments on commit 02ab27b

Please sign in to comment.