From 06f1987ae46e693f2ee65088d83ab565ea995c47 Mon Sep 17 00:00:00 2001 From: LuckyLaszlo Date: Thu, 16 Dec 2021 05:05:25 +0100 Subject: [PATCH] small adjust in files --- Makefile | 1 - headers/minishell_prototypes.h | 7 +++--- srcs/debug.c | 35 +++++++++++++++++++++++++++ srcs/generic/generic.c | 37 ----------------------------- srcs/misc/error_wrappers.c | 9 ++++++- srcs/parsing/parsing.c | 43 +++++++++++----------------------- 6 files changed, 60 insertions(+), 72 deletions(-) create mode 100644 srcs/debug.c delete mode 100644 srcs/generic/generic.c diff --git a/Makefile b/Makefile index 419d2e0..0a3a5b0 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,6 @@ SRCS = main.c \ exec_cmd_line.c pipeline.c \ find_access.c subshell_exec.c subshell_wait.c simple_cmd_builtin.c \ cd.c pwd.c export.c unset.c exit.c env.c echo.c \ - generic.c \ ft_split_quotes.c ft_strdup_quotes.c \ ft_strjoinfree.c ft_lst_func.c ft_isinset_str.c ft_is_posix_name.c \ ft_getenv.c ft_free_null.c ft_2d_arr_func.c \ diff --git a/headers/minishell_prototypes.h b/headers/minishell_prototypes.h index c6f57fa..8e5fb94 100644 --- a/headers/minishell_prototypes.h +++ b/headers/minishell_prototypes.h @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */ -/* Updated: 2021/12/11 20:59:40 by lperrey ### ########.fr */ +/* Updated: 2021/12/16 04:50:31 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,6 +72,7 @@ typedef void (*t_free_f)(void *); // generic // Error wrappers int shell_error(char *s1, char *s2, char *s3, int ret_val); int shell_perror(char *s1, char *s2, char *s3, int ret_val); +int ft_reti_perror_io(int ret, char *err_str, char *io_file); // Generic char *ft_strjoinfree(char *s1, char *s2); @@ -82,12 +83,10 @@ int ft_isinset_str(char *str, char *set); size_t ft_2d_arrlen(void *ptr); // Replace ft_arrlen() char **ft_dup_2d_char_arr(char **ptr); void *ft_resize_2d_arr(void *ptr, size_t add_nbr); -void print_matrix(char **matrix, char *sep); t_list *ft_lstbeforelast(t_list *lst); void *ft_lstnew_generic(size_t lst_size, size_t content_size); typedef void *(*t_dup_f)(void *); void *ft_dup_2d_arr(void *ptr, void *(*dup_func)(void *)); -int ft_reti_perror_io(int ret, char *err_str, char *io_file); void ft_free_null(void *ptr); char *ft_getenv(char *env_var); size_t ft_getenv_position(char *env_var); @@ -96,7 +95,7 @@ int ft_is_posix_name(char *str); char **ft_split_quotes(char const *s, char c); char *ft_strdup_quotes(const char *s); -// signals.c +// Signals handler void sigint_handler_interactive(int signum); void sigint_handler_heredoc(int signum); diff --git a/srcs/debug.c b/srcs/debug.c new file mode 100644 index 0000000..d3dd7e5 --- /dev/null +++ b/srcs/debug.c @@ -0,0 +1,35 @@ + +#include "minishell.h" + +// pour imprimer une char ** en precisant comment separer les char * +void print_matrix(char **matrix, char *sep) +{ + int i; + + i = 0; + while (matrix[i]) + { + printf("%s", matrix[i]); + if (matrix[i + 1]) + printf("%s", sep); + //fflush(stdout); + i++; + } + write(1, "\n", 1); +} + +void print_pipeline(t_cmd **pipeline) +{ + int i; + + i = 0; + while (pipeline[i]) + { + printf("CMD %i, fd_in=%i, fd_out=%i\n", i, pipeline[i]->fd_in, pipeline[i]->fd_out); + ft_putstr_fd(" |", 1); + print_matrix(pipeline[i]->argv, "|\n |"); + i++; + if (pipeline[i]) + ft_putstr_fd("----------------\n", 1); + } +} diff --git a/srcs/generic/generic.c b/srcs/generic/generic.c deleted file mode 100644 index 33024bc..0000000 --- a/srcs/generic/generic.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* generic.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: lperrey +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2021/10/08 09:25:35 by lperrey #+# #+# */ -/* Updated: 2021/12/16 03:50:35 by lperrey ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -// pour imprimer une char ** en precisant comment separer les char * -void print_matrix(char **matrix, char *sep) -{ - int i; - - i = 0; - while (matrix[i]) - { - printf("%s", matrix[i]); - if (matrix[i + 1]) - printf("%s", sep); - fflush(stdout); - i++; - } - write(1, "\n", 1); -} - -int ft_reti_perror_io(int ret, char *err_str, char *io_file) -{ - ft_putstr_fd(err_str, STDERR_FILENO); - perror(io_file); - return (ret); -} diff --git a/srcs/misc/error_wrappers.c b/srcs/misc/error_wrappers.c index aef5775..7871e30 100644 --- a/srcs/misc/error_wrappers.c +++ b/srcs/misc/error_wrappers.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/12/01 17:16:30 by lperrey #+# #+# */ -/* Updated: 2021/12/05 16:26:48 by lperrey ### ########.fr */ +/* Updated: 2021/12/16 04:38:05 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,3 +43,10 @@ int shell_perror(char *s1, char *s2, char *s3, int ret_val) perror(NULL); return (ret_val); } + +int ft_reti_perror_io(int ret, char *err_str, char *io_file) +{ + ft_putstr_fd(err_str, STDERR_FILENO); + perror(io_file); + return (ret); +} diff --git a/srcs/parsing/parsing.c b/srcs/parsing/parsing.c index 35ca10a..3a9755e 100644 --- a/srcs/parsing/parsing.c +++ b/srcs/parsing/parsing.c @@ -6,14 +6,13 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */ -/* Updated: 2021/12/12 21:18:52 by lperrey ### ########.fr */ +/* Updated: 2021/12/16 04:58:12 by lperrey ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" void save_redirections_words(t_token *t); -void print_pipeline(t_cmd **pipeline); t_cmd **parsing(t_token *token_list) { @@ -24,32 +23,19 @@ t_cmd **parsing(t_token *token_list) // 2.9.1 - 1) Save Words save_redirections_words(token_list); - // Struct CMD alloc pipeline = pipeline_alloc(1 + count_pipes(token_list)); if (!pipeline) return (NULL); - // 2.9.1 - 2) Expansion - // TEST TOKENS PRINT -/* ft_putstr_fd("TOKENS LIST :\n-----------\n", STDERR_FILENO); - ft_lstprint((t_list *)token_list, STDERR_FILENO); */ - // if (!expansions(token_list, pipeline)) return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline)); - // -/* ft_putstr_fd("TOKENS LIST EXPANDED :\n-----------\n", STDERR_FILENO); - ft_lstprint((t_list *)token_list, STDERR_FILENO); */ - // 2.9.1 - 3) Redirection if (!redirections(token_list, pipeline)) return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline)); - // Struct CMD fill if (!pipeline_fill_argv(token_list, pipeline)) return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline)); - //print_pipeline(pipeline); - return (pipeline); } @@ -67,21 +53,20 @@ void save_redirections_words(t_token *t) } } -void print_pipeline(t_cmd **pipeline) -{ - int i; +/* + 2.9.1 Simple Commands + 2.9.1 - 1) Save Words + 2.9.1 - 2) Expansion + 2.9.1 - 3) Redirection +https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html +#tag_18_09_01 +*/ - i = 0; - while (pipeline[i]) - { - printf("CMD %i, fd_in=%i, fd_out=%i\n", i, pipeline[i]->fd_in, pipeline[i]->fd_out); - ft_putstr_fd(" |", 1); - print_matrix(pipeline[i]->argv, "|\n |"); - i++; - if (pipeline[i]) - ft_putstr_fd("----------------\n", 1); - } -} +/* + 2.10 Shell Grammar +https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html +#tag_18_10 +*/ /* ------------------------------------------------------- The grammar symbols