From 98f247a378bbe077821b4cbcd8ab6241f28acad4 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Fri, 15 Oct 2021 18:17:26 +0200 Subject: [PATCH] tout debut implementation pipes --- Makefile | 3 ++- README.md | 14 +++++++++++++ headers/minishell_prototypes.h | 5 ++++- srcs/main.c | 13 +++--------- srcs/pipes_hugo.c | 36 ++++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 srcs/pipes_hugo.c diff --git a/Makefile b/Makefile index 3068941..9645868 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,8 @@ LIBFT_D = ./libft LIBFT = $(LIBFT_D)/libft.a SRCS = main.c init.c free.c generic.c \ - env.c exit.c + env.c exit.c \ + pipes_hugo.c DIR_OBJS = builds OBJS = $(SRCS:%.c=$(DIR_OBJS)/%.o) diff --git a/README.md b/README.md index 3612c40..07c0fcf 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,20 @@ _'___"___'___"_"___'___"___'_ ## 4. notes : --- +**idea about malloc protection :** + +have them(malloc and similar) done in a specific function that would check their return and accordingly exit the program or continue + +-> so that it can be done in one line + + void calloc_or_exit(int num, int size); + +and possibly give it a pointer to a function that will clean before exit + + void calloc_or_exit(int num, int size, void (*f)(void *ptr), void *ptr); + +--- + Ordre Interpreteur : 1) Couper les mots (comment faire ? je ne vois pas comment gerer ce genre de bordel ci dessous) ``` diff --git a/headers/minishell_prototypes.h b/headers/minishell_prototypes.h index 9ac275f..16739e6 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/10/10 23:55:14 by lperrey ### ########.fr */ +/* Updated: 2021/10/15 17:18:14 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,4 +28,7 @@ char *ft_strjoinfree(char *s1, char *s2); char *ft_strjoinfree_s1(char *s1, const char *s2); char *ft_strjoinfree_s2(const char *s1, char *s2); +// pipes hugo +void pipes_hugo(char *input); + #endif diff --git a/srcs/main.c b/srcs/main.c index 6495efc..3938a4c 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */ -/* Updated: 2021/10/10 15:13:26 by hulamy ### ########.fr */ +/* Updated: 2021/10/15 17:33:46 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,8 @@ void shell_loop(t_all *c) builtin_env(0, NULL, c); else if (!ft_strncmp(line_input, "exit", 5)) // temp placeholder builtin_exit(0, NULL, c); + else if (!ft_strncmp(line_input, "pipe ", 5)) // temp temp temp + pipes_hugo(line_input); else printf("echo: %s\n", line_input); } @@ -71,12 +73,3 @@ int main(int argc, char *argv[], char *envp[]) return (0); } - -/* -** idea about malloc protection : -** have them(mallocand similar) done in a specific function that would check their return and accordingly exit the program or continue -** -> so that it can be done in one line -** void calloc_or_exit(int num, int size); -** and possibly give it a pointer to a function that will clean before exit -** void calloc_or_exit(int num, int size, void (*f)(void *ptr), void *ptr); -*/ diff --git a/srcs/pipes_hugo.c b/srcs/pipes_hugo.c new file mode 100644 index 0000000..b663829 --- /dev/null +++ b/srcs/pipes_hugo.c @@ -0,0 +1,36 @@ +#include "minishell.h" + +int size_tab(char **split) +{ + int i; + + i = 0; + while (*split++) + i++; + return (i); +} + +void print_tab(char **array) +{ + int i; + + i = 0; + while (array[i]) + { + printf("%i: %s\n", i, array[i]); + i++; + } +} + +void pipes_hugo(char *input) +{ + char **split; + int nbr_pipes; + + split = ft_split(input, '|'); + split[0] += 5; // pour sauter la premiere entree qui est "pipe" + nbr_pipes = size_tab(split); +//printf("%i\n", nbr_pipes); +//print_tab(split); + +}