diff --git a/bozo b/bozo new file mode 100644 index 0000000..e69de29 diff --git a/builtins/builtins.h b/builtins/builtins.h index 09ba4d9..faf28bc 100644 --- a/builtins/builtins.h +++ b/builtins/builtins.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtins.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet diff --git a/builtins/echo.c b/builtins/echo.c index a0caccd..f05d199 100644 --- a/builtins/echo.c +++ b/builtins/echo.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */ -/* Updated: 2023/03/13 16:50:40 by erey-bet ### ########.fr */ +/* Updated: 2023/03/28 15:53:52 by cchauvet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,7 +46,8 @@ int echo(int fd, char **strs) { while (is_space(*strs[i])) strs[i]++; - if (check_start_write == 1 || check_argument(strs[i], &check_backslash_n)) + if (check_start_write == 1 + || check_argument(strs[i], &check_backslash_n)) { check_start_write = 1; ft_putstr_fd(strs[i], fd); @@ -58,9 +59,3 @@ int echo(int fd, char **strs) write(fd, "\n", 1); return (0); } - -/*int main(int argc, char *argv[]) -{ - echo(1, argv + 1); - return (0); -}*/ diff --git a/cmd/cmd.h b/cmd/cmd.h index b04dbbb..346980d 100644 --- a/cmd/cmd.h +++ b/cmd/cmd.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cmd.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet diff --git a/cmd/cmd_private.h b/cmd/cmd_private.h index d27c80f..b507edd 100644 --- a/cmd/cmd_private.h +++ b/cmd/cmd_private.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cmd_private.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet diff --git a/data/data.c b/data/data.c index 261b5b1..f7075fe 100644 --- a/data/data.c +++ b/data/data.c @@ -1,7 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* data.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet diff --git a/env/env_private.h b/env/env_private.h index d431242..e735d71 100644 --- a/env/env_private.h +++ b/env/env_private.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* env_private.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet executable, "env") == 0) return_code = print_env(data->env, cmd->fd_out[0]); else if (ft_strcmp(cmd->executable, "export") == 0) - return_code = (ft_export(data->env,cmd->args + 1, cmd->fd_out[0])); + return_code = ft_export(data->env, cmd->args + 1, cmd->fd_out[0]); else if (ft_strcmp(cmd->executable, "cd") == 0) return_code = (move_folder(cmd->args + 1, cmd->fd_out[0])); else if (ft_strcmp(cmd->executable, "unset") == 0) @@ -110,7 +110,7 @@ int ft_cmds_executor(t_data *data) if (pipe(fds) == -1) return (1); ft_add_fd(content->fd_out, fds[1]); - ft_add_fd(((t_cmd *) (current->next->content))->fd_in, fds[0]); + ft_add_fd(((t_cmd *)(current->next->content))->fd_in, fds[0]); } if (ft_cmd_executor(data, content, fds[0])) return (1); diff --git a/execution/execution.h b/execution/execution.h index a322533..822c59b 100644 --- a/execution/execution.h +++ b/execution/execution.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* execution.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet #include -static char *ft_get_user_input() +static char *ft_get_user_input(void) { char *line; char *prompt; @@ -62,7 +62,7 @@ static void ft_cmds_waiter(t_data *data) { if (WTERMSIG(exit_status) == SIGKILL) data->exit_code = 131; - else //(WTERMSIG(exit_status) == SIGINT) + else data->exit_code = 130; } else diff --git a/parse/parse.c b/parse/parse.c index 9f4a6a9..5680bf7 100644 --- a/parse/parse.c +++ b/parse/parse.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet fd_in); ft_closer(cmd->fd_out); } - else if (ft_strcmp(cmd->args[0], "env") == 0) - own = 1; - else if (ft_strcmp(cmd->args[0], "export") == 0) - own = 1; - else if (ft_strcmp(cmd->args[0], "echo") == 0) - own = 1; - else if (ft_strcmp(cmd->args[0], "unset") == 0) - own = 1; - else if (ft_strcmp(cmd->args[0], "exit") == 0) - own = 1; - else if (ft_strcmp(cmd->args[0], "pwd") == 0) - own = 1; - else if (ft_strcmp(cmd->args[0], "cd") == 0) + else if (ft_strcmp(cmd->args[0], "env") == 0 || (ft_strcmp(cmd->args[0], + "export") == 0) || (ft_strcmp(cmd->args[0], "echo") == 0) + || (ft_strcmp(cmd->args[0], "unset") == 0) || (ft_strcmp(cmd->args[0], + "exit") == 0) || (ft_strcmp(cmd->args[0], "pwd") == 0) + || (ft_strcmp(cmd->args[0], "cd") == 0)) own = 1; else { @@ -55,10 +59,23 @@ static int ft_executable_parse(t_data *data, t_cmd *cmd) return (0); } +int ft_cmd_adder(t_data *data, t_cmd *cmd) +{ + t_list *element; + + element = ft_lstnew(cmd); + if (element == NULL) + { + ft_cmddel(cmd); + return (1); + } + ft_lstadd_back(data->cmds, element); + return (0); +} + int ft_cmd_parser(t_data *data, char *cmd_str) { t_cmd *cmd; - t_list *element; cmd = ft_calloc(sizeof(t_cmd), 1); if (cmd == NULL) @@ -81,37 +98,28 @@ int ft_cmd_parser(t_data *data, char *cmd_str) ft_cmddel(cmd); return (1); } - element = ft_lstnew(cmd); - if (element == NULL) - { - ft_cmddel(cmd); - return (1); - } - ft_lstadd_back(data->cmds, element); - return (0); + return (ft_cmd_adder(data, cmd)); } int ft_cmds_parser(t_data *data, const char *line) { char **tab; - size_t i; + ssize_t i; tab = ft_split_quoted(line, '|'); if (tab == NULL) { - ft_freer_tab_ultimate(1, tab); ft_eprintf("minishell: malloc failed\n"); return (1); } - i = 0; - while (tab[i] != NULL) + i = -1; + while (tab[++i] != NULL) { if (ft_cmd_parser(data, tab[i])) { ft_freer_tab_ultimate(1, tab); return (1); } - i++; } if (*data->cmds != NULL) { diff --git a/parse/parse.h b/parse/parse.h index 64d5e9b..cdaa9d3 100644 --- a/parse/parse.h +++ b/parse/parse.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet ") == 0) + else if (ft_strcmp(tab[i], ">") == 0) { if (ft_file_is_writable(data, tab[i + 1])) - cmd->fd_out[0] = open(tab[i + 1], O_WRONLY | O_TRUNC | O_CREAT, 0644); + cmd->fd_out[0] = open(tab[i + 1], + O_WRONLY | O_TRUNC | O_CREAT, 0644); else return (1); } - else if(ft_strcmp(tab[i], ">>") == 0) + else if (ft_strcmp(tab[i], ">>") == 0) { if (ft_file_is_appendable(data, tab[i + 1])) - cmd->fd_out[0] = open(tab[i + 1], O_WRONLY | O_APPEND | O_CREAT, 0644); + cmd->fd_out[0] = open(tab[i + 1], + O_WRONLY | O_APPEND | O_CREAT, 0644); else return (1); } diff --git a/redirection/redirection.h b/redirection/redirection.h index 66f32fa..c745c90 100644 --- a/redirection/redirection.h +++ b/redirection/redirection.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* redirection.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet # include # include diff --git a/syntax/syntax.h b/syntax/syntax.h index 9a87c39..5b064ac 100644 --- a/syntax/syntax.h +++ b/syntax/syntax.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* syntax.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet @@ -5,12 +17,10 @@ void ft_closer(int fds[2]) { if (fds[0] > 2) { - //dprintf(2, "close(%d)\n", fds[0]); close(fds[0]); } if (fds[1] > 2) { - //dprintf(2, "close(%d)\n", fds[1]); close(fds[1]); } } diff --git a/utils/ft_get_executable.c b/utils/ft_get_executable.c index e1b7979..f511e50 100644 --- a/utils/ft_get_executable.c +++ b/utils/ft_get_executable.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_get_executable.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet @@ -26,14 +38,11 @@ char *ft_get_executable_with_path(t_data *data, const char *name) return (path); } -char *ft_get_executable_without_path(t_data *data, const char *name) +static char **ft_get_paths(t_data *data, const char *name) { - char **tab; char *paths; - char *path; - size_t i; + char **tab; - path = NULL; paths = get_value_by_key("PATH", data->env); if (paths == NULL) { @@ -47,10 +56,23 @@ char *ft_get_executable_without_path(t_data *data, const char *name) ft_eprintf("minishell: malloc failed\n"); return (NULL); } + return (tab); +} + +static char *ft_get_executable_without_path(t_data *data, const char *name) +{ + char **paths; + char *path; + size_t i; + + paths = ft_get_paths(data, name); + if (paths == NULL) + return (NULL); + path = NULL; i = 0; - while (tab[i] != NULL) + while (paths[i] != NULL) { - path = ft_strmerger(3, tab[i], "/", name); + path = ft_strmerger(3, paths[i], "/", name); if (path == NULL) { ft_eprintf("minishell: malloc failed\n"); @@ -62,7 +84,7 @@ char *ft_get_executable_without_path(t_data *data, const char *name) path = NULL; i++; } - ft_freer_tab_ultimate(1, tab); + ft_freer_tab_ultimate(1, paths); if (path == NULL) { data->exit_code = 127; diff --git a/utils/ft_is_in_quote.c b/utils/ft_is_in_quote.c index c2d756e..3436b7f 100644 --- a/utils/ft_is_in_quote.c +++ b/utils/ft_is_in_quote.c @@ -6,40 +6,36 @@ /* By: cchauvet int ft_is_in_quote(const char *str, size_t n) { - size_t i; + ssize_t i; - i = 0; - while (str[i] != '\0' && i < n) + i = -1; + while (str[++i] != '\0' && i < (ssize_t) n) { if (str[i] == '\'') { i++; while (str[i] != '\'' && str[i] != '\0') { - if (i == n) + if (i == (ssize_t) n) return (1); i++; } } if (str[i] == '"') { - i++; - while (str[i] != '"' && str[i] != '\0') - { - if (i == n) + while (str[++i] != '"' && str[i] != '\0') + if (i == (ssize_t) n) return (2); - i++; - } } - i++; } return (0); }