tout debut implementation pipes

This commit is contained in:
hugogogo
2021-10-15 18:17:26 +02:00
parent 97ab70c475
commit 98f247a378
5 changed files with 59 additions and 12 deletions

View File

@@ -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)

View File

@@ -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)
```

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
*/

36
srcs/pipes_hugo.c Normal file
View File

@@ -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);
}