diff --git a/include/execution.h b/include/execution.h index 7139994..80a65f6 100644 --- a/include/execution.h +++ b/include/execution.h @@ -6,7 +6,7 @@ /* By: mmoussou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */ -/* Updated: 2024/07/07 14:37:59 by adjoly ### ########.fr */ +/* Updated: 2024/07/09 23:52:39 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,8 +33,8 @@ typedef enum s_quote DOUBLE = 34 } t_quote; -t_cmd *get_redir_fd(void *content, t_env *env); -t_list *get_cmd_list(t_list *list, t_env *env); +t_cmd *get_redir_fd(void *content); +t_list *get_cmd_list(t_list *list); void open_redir(t_redirection *redir, t_cmd *cmd, t_redir_sign sign[2]); /** @@ -135,5 +135,6 @@ void print_quote_type(t_quote type); void print_redir_sign(t_redir_sign redir_sign); void print_token(t_token *token); void print_redir(t_redirection *redir); +void print_cmd(t_cmd *cmd); #endif diff --git a/src/exec/exec_split_cmd.c b/src/exec/exec_split_cmd.c index 8456fb1..f6ed7d8 100644 --- a/src/exec/exec_split_cmd.c +++ b/src/exec/exec_split_cmd.c @@ -6,29 +6,14 @@ /* By: mmoussou 4) - exit(0); } else execve(cmd, argv, env); } -char *get_cmd_local_path(char *cmd, t_env *env) +void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec) { - char *path; - - path = env_get_value("PWD", env); - if (!path) - return (NULL); - path = ft_strjoin_free_s1(path, "/"); - if (!path) - return (NULL); - path = ft_strjoin_free_s1(path, cmd); - return (path); -} - -int switch_cmd_path(t_cmd *cmd, t_env *env) -{ - if (is_in_builtins(cmd->cmd)) - return (0); - if (cmd->cmd[0] == '.' && cmd->cmd[1] == '/') - cmd->cmd = get_cmd_local_path(cmd->cmd, env); - else if (cmd->cmd[0] != '/') - cmd->cmd = get_path(env_get_value("PATH", env), cmd->cmd); - if (!(cmd->cmd)) - return (-1); - return (0); + exec.status = dup2(cmd->infile, STDIN_FILENO); + if (cmd->infile != STDIN_FILENO) + close(cmd->infile); + if (exec.status == -1) + exit(-1); + exec.status = dup2(cmd->outfile, STDOUT_FILENO); + if (cmd->outfile != STDOUT_FILENO) + close(cmd->outfile); + if (exec.pipe_fd[0] != -1) + close(exec.pipe_fd[0]); + if (exec.pipe_fd[0] != -1) + close(exec.pipe_fd[1]); + if (exec.status != -1) + exec_cmd(cmd->cmd, cmd->argv, env, env_t); + exit(-1); } int exec_single_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2]) { + t_exec exec; int fork_pid; - int status; char *input; input = ft_strdup(cmd->cmd); - status = switch_cmd_path(cmd, env_t); - if (status == -1 || !input || (access(cmd->cmd, X_OK) && !is_in_builtins(cmd->cmd))) + exec.pipe_fd[0] = pipe_fd[0]; + exec.pipe_fd[1] = pipe_fd[1]; + exec.status = switch_cmd_path(cmd, env_t); + if (exec.status == -1 || !input || (access(cmd->cmd, X_OK) \ + && !is_in_builtins(cmd->cmd))) { printf("minishell : command not found: %s\n", input); + free(input); return (-1); } - if (is_in_builtins(cmd->cmd) && is_in_builtins(cmd->cmd) < 5) + free(input); + if (is_in_builtins(cmd->cmd) > 0) { exec_cmd(cmd->cmd, cmd->argv, env, env_t); return (0); } fork_pid = fork(); if (!fork_pid) - { - status = dup2(cmd->infile, STDIN_FILENO); - if (cmd->infile != STDIN_FILENO) - close(cmd->infile); - if (status == -1) - exit(-1); - status = dup2(cmd->outfile, STDOUT_FILENO); - if (cmd->outfile != STDOUT_FILENO) - close(cmd->outfile); - if (pipe_fd[0] != -1) - close(pipe_fd[0]); - if (pipe_fd[0] != -1) - close(pipe_fd[1]); - if (status != -1) - exec_cmd(cmd->cmd, cmd->argv, env, env_t); - exit(-1); - } + __fork_single_cmd(cmd, env, env_t, exec); return (fork_pid); } -void print_return_value(int return_code) +t_exec exec_pipe(t_exec exec, t_list *list_cmd, t_env *env) { - int code; - static const char *sigmsg[] = {0, "Hangup", 0, "Quit", "Illegal \ - instruction", "Trace/breakpoint trap", "Aborted", "Bus error", - "Floating point exception", "Killed", "User defined signal 1", - "Segmentation fault", "User defined signal 2", 0, - "Alarm clock", "Terminated", "Stack fault", 0, 0, "Stopped", "Stopped", - "Stopped", "Stopped", 0, "CPU time limit exceeded", - "File size limit exceeded", "Virtual time expired", - "Profiling timer expired", "I/O possible", "Power failure", - "Bad system call"}; - - if (!WIFEXITED(return_code)) - { - if (WIFSIGNALED(return_code)) - { - code = WTERMSIG(return_code); - if (!sigmsg[code]) - return ; - if (WCOREDUMP(return_code)) - printf("minishell : %s %s\n", sigmsg[code], ERROR_COREDUMP); - else - printf("minishell : %s\n", sigmsg[code]); - } - } -} - -int exec_split_cmd(t_list *list_cmd, t_env *env) -{ - char **env_array; - int status; - int return_code; - int i; - int pipe_fd[2]; - - env_array = env_get(env); - pipe_fd[0] = -1; - pipe_fd[1] = -1; - if (!env_array) - return (-1); - i = 1; while (list_cmd->next) { - status = pipe(pipe_fd); - if (status) - return (-1); + exec.status = pipe(exec.pipe_fd); + if (exec.status) + return ((t_exec){exec.env_array, -1, exec.i, \ + {exec.pipe_fd[0], exec.pipe_fd[1]}}); if (((t_cmd *)(list_cmd->content))->outfile == STDOUT_FILENO) - ((t_cmd *)(list_cmd->content))->outfile = pipe_fd[1]; + ((t_cmd *)(list_cmd->content))->outfile = exec.pipe_fd[1]; if (((t_cmd *)(list_cmd->next->content))->infile == STDIN_FILENO) - ((t_cmd *)(list_cmd->next->content))->infile = pipe_fd[0]; - status = exec_single_cmd(list_cmd->content, env_array, env, pipe_fd); - if (((t_cmd *)(list_cmd->content))->outfile != STDOUT_FILENO) - close(((t_cmd *)(list_cmd->content))->outfile); - if (((t_cmd *)(list_cmd->content))->infile != STDIN_FILENO) - close(((t_cmd *)(list_cmd->content))->infile); - if (status != -1) - i++; + ((t_cmd *)(list_cmd->next->content))->infile = exec.pipe_fd[0]; + exec.status = exec_single_cmd(list_cmd->content, exec.env_array, \ + env, exec.pipe_fd); + __close(list_cmd->content); + if (exec.status != -1) + exec.i++; list_cmd = list_cmd->next; } - status = exec_single_cmd(list_cmd->content, env_array, env, pipe_fd); + exec.status = exec_single_cmd(list_cmd->content, exec.env_array, \ + env, exec.pipe_fd); if (((t_cmd *)(list_cmd->content))->outfile != STDOUT_FILENO) close(((t_cmd *)(list_cmd->content))->outfile); if (((t_cmd *)(list_cmd->content))->infile != STDIN_FILENO) close(((t_cmd *)(list_cmd->content))->infile); - ft_free("a", &env_array); - if (status == -1) - i--; - if (i < 1) + return (exec); +} + +int exec_split_cmd(t_list *list_cmd, t_env *env) +{ + t_exec exec; + int return_code; + + exec.env_array = env_get(env); + if (!exec.env_array) + return (-1); + return_code = 0; + exec.pipe_fd[0] = -1; + exec.pipe_fd[1] = -1; + exec.i = 1; + exec = exec_pipe(exec, list_cmd, env); + if (exec.env_array) + ft_free("a", &exec.env_array); + if (exec.status == -1) + exec.i--; + if (exec.i < 1) return (0); - if (status != 0) - waitpid(status, &return_code, 0); - while (i - 1) - { - waitpid(-1, NULL, 0); - i--; - } + if (exec.status != 0) + waitpid(exec.status, &return_code, 0); + if (!return_code) + return_code = 0; + __wait(exec.i); print_return_value(return_code); return (0); } diff --git a/src/exec/format_quotes.c b/src/exec/format_quotes.c index f2c0e86..7eb9c0d 100644 --- a/src/exec/format_quotes.c +++ b/src/exec/format_quotes.c @@ -6,7 +6,7 @@ /* By: mmoussou argv[i]) { - format_quotes_string(cmd->argv[i]); + cmd->argv[i] = format_quotes_string(cmd->argv[i]); + cmd->argv[i] = env_var_replace(cmd->argv[i], env); i++; } return (0); } -int format_quotes(t_list *list_cmd) +int format_quotes(t_list *list_cmd, t_env *env) { if (!list_cmd) return (0); while (list_cmd) { - format_quotes_cmd(list_cmd->content); + format_quotes_cmd(list_cmd->content, env); list_cmd = list_cmd->next; } return (0); diff --git a/src/exec/heredoc.c b/src/exec/heredoc.c index 68738a7..8949488 100644 --- a/src/exec/heredoc.c +++ b/src/exec/heredoc.c @@ -6,7 +6,7 @@ /* By: mmoussou 0) - return (open(path, O_RDONLY)); - else - return (open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644)); + return (__open_fd_here(path, mode)); } static int get_input(char *delimiter, int fd) @@ -52,16 +49,16 @@ static int get_input(char *delimiter, int fd) int status; line = readline("heredoc> "); - while (ft_strcmp(line, delimiter)) + while (line && ft_strcmp(line, delimiter)) { status = write(fd, line, ft_strlen(line)); if (status == -1) - fd_manager(fd); + close(fd_manager(fd)); if (status == -1) break ; status = write(fd, "\n", 1); if (status == -1) - fd_manager(fd); + close(fd_manager(fd)); if (status == -1) break ; free(line); @@ -70,11 +67,21 @@ static int get_input(char *delimiter, int fd) free(line); status = write(fd, "\0", 1); if (status == -1) - fd_manager(fd); + close(fd_manager(fd)); return (-(status == -1)); } -int __heredoc(char *delimiter) +void __forked(char *delimiter, int fd, t_cmd *cmd) +{ + get_input(delimiter, fd); + free(cmd); + ft_envclear(get_env(NULL), free); + ft_lstclear_till_nxt(get_list2(NULL), &free_cmd); + ft_lstclear(get_list(NULL), &free_token); + close(fd); +} + +int __heredoc(char *delimiter, t_cmd *cmd) { int fork_pid; int fd; @@ -82,33 +89,31 @@ int __heredoc(char *delimiter) fd = fd_manager(0); if (fd == -1) { - fd_manager(-1); + close(fd_manager(-1)); return (-1); } fork_pid = fork(); if (fork_pid == -1) { - fd_manager(-1); + close(fd_manager(-1)); close(fd); return (-1); } if (!fork_pid) { - get_input(delimiter, fd); - ft_envclear(get_env(NULL), free); - ft_lstclear(get_list(NULL), &free_token); + __forked(delimiter, fd, cmd); exit(0); } else waitpid(fork_pid, NULL, 0); + close(fd); return (fd_manager(1)); } -int ft_heredoc(char *delimiter) +int ft_heredoc(char *delimiter, t_cmd *cmd) { int fd; - fd = __heredoc(delimiter); - + fd = __heredoc(delimiter, cmd); return (fd); } diff --git a/src/exec/heredoc_utils.c b/src/exec/heredoc_utils.c new file mode 100644 index 0000000..2822e30 --- /dev/null +++ b/src/exec/heredoc_utils.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* heredoc_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/10 01:14:10 by adjoly #+# #+# */ +/* Updated: 2024/07/10 01:16:48 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include +#include + +int __open_fd_here(char *path, int mode) +{ + int fd; + + if (mode > 0) + fd = open(path, O_RDONLY); + else + fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644); + free(path); + return (fd); +} + +void ft_lstclear_till_nxt(t_list **lst, void (*del)(void *)) +{ + t_list *tmp; + + if (!(*lst)->next) + { + free(*lst); + return ; + } + if (!lst || !del) + return ; + while (lst && *lst && (*lst)->next && del) + { + tmp = (*lst)->next; + if ((*lst)->content) + ft_lstdelone(*lst, del); + *lst = tmp; + } + free(*lst); +} diff --git a/src/exec/utils_exec.c b/src/exec/utils_exec.c new file mode 100644 index 0000000..45aa5bd --- /dev/null +++ b/src/exec/utils_exec.c @@ -0,0 +1,91 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils_exec.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/09 19:25:18 by adjoly #+# #+# */ +/* Updated: 2024/07/10 01:17:11 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "minishell.h" + +int is_in_builtins(char *cmd) +{ + int i; + static const char *builtins[] = {"exit", "cd", "unset", "export", "echo", + "pwd", "env", NULL}; + + i = 0; + while (builtins[i]) + { + if (!ft_strcmp(cmd, builtins[i])) + return (i + 1); + i++; + } + return (0); +} + +void print_return_value(int return_code) +{ + int code; + static const char *sigmsg[] = {0, "Hangup", 0, "Quit", "Illegal \ + instruction", "Trace/breakpoint trap", "Aborted", "Bus error", + "Floating point exception", "Killed", "User defined signal 1", + "Segmentation fault", "User defined signal 2", 0, + "Alarm clock", "Terminated", "Stack fault", 0, 0, "Stopped", "Stopped", + "Stopped", "Stopped", 0, "CPU time limit exceeded", + "File size limit exceeded", "Virtual time expired", + "Profiling timer expired", "I/O possible", "Power failure", + "Bad system call"}; + + if (!WIFEXITED(return_code)) + { + if (WIFSIGNALED(return_code)) + { + code = WTERMSIG(return_code); + if (!sigmsg[code]) + return ; + if (WCOREDUMP(return_code)) + printf("minishell : %s %s\n", sigmsg[code], ERROR_COREDUMP); + else + printf("minishell : %s\n", sigmsg[code]); + } + } +} + +char *get_cmd_local_path(char *cmd, t_env *env) +{ + char *path; + + path = env_get_value("PWD", env); + if (!path) + return (NULL); + path = ft_strjoin_free_s1(path, "/"); + if (!path) + return (NULL); + path = ft_strjoin_free_s1(path, cmd); + return (path); +} + +int switch_cmd_path(t_cmd *cmd, t_env *env) +{ + char *path; + + if (is_in_builtins(cmd->cmd)) + return (0); + if (cmd->cmd[0] == '.' && cmd->cmd[1] == '/') + cmd->cmd = get_cmd_local_path(cmd->cmd, env); + else if (cmd->cmd[0] != '/') + { + path = env_get_value("PATH", env); + cmd->cmd = get_path(path, cmd->cmd); + free(path); + } + if (!(cmd->cmd)) + return (-1); + return (0); +} diff --git a/src/exec/utils_exec_2.c b/src/exec/utils_exec_2.c new file mode 100644 index 0000000..4cbfb1a --- /dev/null +++ b/src/exec/utils_exec_2.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils_exec_2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/09 22:53:01 by adjoly #+# #+# */ +/* Updated: 2024/07/09 22:57:38 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "minishell.h" + +void __wait(int i) +{ + while (i - 1) + { + waitpid(-1, NULL, 0); + i--; + } +} + +void __close(void *content) +{ + if (((t_cmd *)(content))->outfile != STDOUT_FILENO) + close(((t_cmd *)(content))->outfile); + if (((t_cmd *)(content))->infile != STDIN_FILENO) + close(((t_cmd *)(content))->infile); +} + +int send_error_exec(char *input) +{ + printf("minishell : command not found: %s\n", input); + free(input); + return (-1); +} diff --git a/src/free_list.c b/src/free_list.c index 940dde9..af22b7b 100644 --- a/src/free_list.c +++ b/src/free_list.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/04 20:10:35 by adjoly #+# #+# */ -/* Updated: 2024/07/04 20:12:06 by adjoly ### ########.fr */ +/* Updated: 2024/07/10 01:19:32 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ void free_redir(void *redir_v) redir = redir_v; free(redir->file_name); + free(redir); } void free_token(void *token_v) @@ -36,7 +37,14 @@ void free_cmd(void *content) t_cmd *cmd; cmd = (t_cmd *)content; - free(cmd->cmd); - ft_free("a", &(cmd->argv)); - free(cmd); + if (cmd->cmd) + free(cmd->cmd); + if (cmd->infile != STDIN_FILENO && cmd->infile != -1) + close(cmd->infile); + if (cmd->outfile != STDOUT_FILENO && cmd->outfile != -1) + close(cmd->outfile); + if (cmd->argv) + ft_free("a", &(cmd->argv)); + if (cmd) + free(cmd); } diff --git a/src/get_to_free.c b/src/get_to_free.c index 6a3b32f..312af4f 100644 --- a/src/get_to_free.c +++ b/src/get_to_free.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/09 17:24:15 by adjoly #+# #+# */ -/* Updated: 2024/07/09 18:05:07 by adjoly ### ########.fr */ +/* Updated: 2024/07/10 00:46:24 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,16 @@ t_env **get_env(t_env **env) t_list **get_list(t_list **list) { static t_list **ret; - + + if (list) + ret = list; + return (ret); +} + +t_list **get_list2(t_list **list) +{ + static t_list **ret; + if (list) ret = list; return (ret); diff --git a/src/main.c b/src/main.c index 4d0b65a..71595cb 100644 --- a/src/main.c +++ b/src/main.c @@ -6,11 +6,12 @@ /* By: mmoussou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/09 16:32:21 by adjoly #+# #+# */ -/* Updated: 2024/07/09 16:39:44 by adjoly ### ########.fr */ +/* Updated: 2024/07/09 23:09:41 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "parsing.h" #include "error_msg.h" +#include "minishell.h" bool check_redir(t_list *list) { diff --git a/src/parsing/env_var/env_var_replace.c b/src/parsing/env_var/env_var_replace.c index df1c779..0612d51 100644 --- a/src/parsing/env_var/env_var_replace.c +++ b/src/parsing/env_var/env_var_replace.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/05 21:14:04 by adjoly #+# #+# */ -/* Updated: 2024/07/09 16:12:34 by adjoly ### ########.fr */ +/* Updated: 2024/07/09 20:23:16 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,5 +64,6 @@ char *env_var_replace(char *readline, t_env *env) tmp++; } } + free(readline); return (rl_dollared); } diff --git a/src/parsing/get_cmd_list.c b/src/parsing/get_cmd_list.c index fd6cb6a..60c42ad 100644 --- a/src/parsing/get_cmd_list.c +++ b/src/parsing/get_cmd_list.c @@ -6,23 +6,28 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/31 12:47:13 by adjoly #+# #+# */ -/* Updated: 2024/07/06 18:05:27 by adjoly ### ########.fr */ +/* Updated: 2024/07/10 01:12:52 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include "parsing.h" +#include "minishell.h" -t_list *get_cmd_list(t_list *list, t_env *env) +t_list *get_cmd_list(t_list *list) { t_list *tmp; t_list *cmd_list; tmp = list; - cmd_list = NULL; + cmd_list = malloc(sizeof(t_list)); + get_list2(&cmd_list); + cmd_list->next = NULL; + cmd_list->content = get_redir_fd(tmp->content); + tmp = tmp->next; while (tmp) { - ft_lstadd_back(&cmd_list, ft_lstnew(get_redir_fd(tmp->content, env))); + ft_lstadd_back(&cmd_list, ft_lstnew(get_redir_fd(tmp->content))); tmp = tmp->next; } return (cmd_list); diff --git a/src/parsing/get_redir_fd.c b/src/parsing/get_redir_fd.c index 7e6b8d7..ca0aca0 100644 --- a/src/parsing/get_redir_fd.c +++ b/src/parsing/get_redir_fd.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/30 10:48:41 by adjoly #+# #+# */ -/* Updated: 2024/07/09 16:16:27 by adjoly ### ########.fr */ +/* Updated: 2024/07/10 01:07:50 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,12 +18,11 @@ #include #include "libft.h" -t_cmd *get_redir_fd(void *content, t_env *env) +t_cmd *get_redir_fd(void *content) { t_list *tmp; t_redir_sign sign[2]; t_cmd *cmd; - char *env_varred; tmp = ((t_token *)content)->redirection; cmd = NULL; @@ -39,8 +38,6 @@ t_cmd *get_redir_fd(void *content, t_env *env) cmd->outfile = STDOUT_FILENO; if (sign[1] == OUTFILE) cmd->infile = STDIN_FILENO; - env_varred = env_var_replace(((t_token *)content)->argv, env); - cmd = split_cmd(env_varred, cmd); - free(env_varred); + cmd = split_cmd(((t_token *)content)->argv, cmd); return (cmd); } diff --git a/src/parsing/open_redir.c b/src/parsing/open_redir.c index 1ce1b76..0c68a77 100644 --- a/src/parsing/open_redir.c +++ b/src/parsing/open_redir.c @@ -6,14 +6,15 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/30 15:56:53 by adjoly #+# #+# */ -/* Updated: 2024/06/30 18:03:14 by adjoly ### ########.fr */ +/* Updated: 2024/07/10 01:07:09 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "tokenizer.h" #include -#include "execution.h" #include "parsing.h" +#include "execution.h" +#include t_redir_sign __close_unused_fd(t_cmd *cmd, t_redir_sign sign) { @@ -31,7 +32,7 @@ void open_redir(t_redirection *redir, t_cmd *cmd, t_redir_sign sign[2]) if (redir->sign == INFILE || redir->sign == HEREDOC) sign[1] = __close_unused_fd(cmd, redir->sign); if (redir->sign == HEREDOC) - cmd->infile = ft_heredoc(redir->file_name); + cmd->infile = ft_heredoc(redir->file_name, cmd); else if (redir->sign == INFILE) cmd->infile = open(redir->file_name, O_RDONLY); else if (redir->sign == OUTFILE) diff --git a/src/parsing/tokenizer/__to_redir.c b/src/parsing/tokenizer/__to_redir.c index c376101..16bd87e 100644 --- a/src/parsing/tokenizer/__to_redir.c +++ b/src/parsing/tokenizer/__to_redir.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/25 15:06:15 by adjoly #+# #+# */ -/* Updated: 2024/05/30 15:47:19 by adjoly ### ########.fr */ +/* Updated: 2024/07/10 00:21:08 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/parsing/tokenizer/__to_token.c b/src/parsing/tokenizer/__to_token.c index 51be671..d3bd268 100644 --- a/src/parsing/tokenizer/__to_token.c +++ b/src/parsing/tokenizer/__to_token.c @@ -6,13 +6,14 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/20 21:05:04 by adjoly #+# #+# */ -/* Updated: 2024/06/26 12:56:14 by adjoly ### ########.fr */ +/* Updated: 2024/07/09 23:43:39 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "tokenizer.h" #include "libft.h" #include "parsing.h" +#include size_t __get_sizeof_redir(char *redir_s, t_redirection *redir) {