diff --git a/bonus/pipex.c b/bonus/pipex.c index db4b4b5..e40f40e 100644 --- a/bonus/pipex.c +++ b/bonus/pipex.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/01/18 18:04:58 by erey-bet #+# #+# */ -/* Updated: 2023/01/20 17:58:22 by erey-bet ### ########.fr */ +/* Updated: 2023/01/30 14:24:01 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,68 +32,69 @@ int free_all(t_data *data) i = -1; while (++i < data->argc - 3) free(data->cmds[i]); + free(data->cmds); return (1); } -void make_cmd(int fd[2][2], t_data data, int fl1, int fl2) +void make_cmd(t_data data, int i, int fl1, int fl2) { dup2(fl1, 0); dup2(fl2, 1); - close(fd[0][0]); - close(fd[0][1]); - close(fd[1][0]); - close(fd[1][1]); - execve(data.cmds[0], data.flgs[0], data.env); + close(data.fd[0][0]); + close(data.fd[0][1]); + close(data.fd[1][0]); + close(data.fd[1][1]); + execve(data.cmds[i], data.flgs[i], data.env); } -void cmd(int fd[2][2], t_data data, int i, int t) +void cmd(t_data data, int i, int t) { if (t == 0) - make_cmd(fd, data, data.fd1, 0); + make_cmd(data, 0, data.fd1, data.fd[0][1]); else if (t == 1) - make_cmd(fd, data, (i + 1) % 2, i % 2); + make_cmd(data, i, data.fd[(i + 1) % 2][0], data.fd[i % 2][1]); else if (t == 2) - make_cmd(fd, data, (i + 1) % 2, data.fd2); + make_cmd(data, i, data.fd[(i + 1) % 2][0], data.fd2); free_all(&data); exit(1); } int pipex(int argc, t_data data) { - int fd[2][2]; int *fk; int i; - if (pipe(fd[0]) < -1) + if (pipe(data.fd[0]) < -1) return (1); - if (pipe(fd[1]) < -1) + if (pipe(data.fd[1]) < -1) return (1); fk = ft_calloc(argc - 3, sizeof(int)); i = -1; while (++i < argc - 3) { fk[i] = fork(); - if (fk < 0) + if (fk[i] < 0) return (1); - if (fk == 0) + if (fk[i] == 0) { if (i == 0 && data.fd1 > 0 && data.cmds[0]) - cmd(fd, data, i, 0); - else if (i == argc - 3) - cmd(fd, data, i, 1); + cmd(data, i, 0); + else if (i + 1 < argc - 3) + cmd(data, i, 1); else - cmd(fd, data, i, 2); + cmd(data, i, 2); } } - close(fd[0][0]); - close(fd[0][1]); - close(fd[1][0]); - close(fd[1][1]); + close(data.fd[0][0]); + close(data.fd[0][1]); + close(data.fd[1][0]); + close(data.fd[1][1]); if (data.fd1 > 0 && data.cmds[0]) waitpid(fk[0], NULL, 0); i = -1; while (++i < argc - 3) waitpid(fk[i], NULL, 0); + free(fk); return (0); } diff --git a/bonus/pipex.h b/bonus/pipex.h index 57b68b3..02a6783 100644 --- a/bonus/pipex.h +++ b/bonus/pipex.h @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/01/11 15:33:34 by erey-bet #+# #+# */ -/* Updated: 2023/01/20 17:48:08 by erey-bet ### ########.fr */ +/* Updated: 2023/01/30 14:03:26 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,7 @@ typedef struct s_data char *fl2; int fd1; int fd2; + int fd[2][2]; char **env; int argc; } t_data; diff --git a/bonus/pipex.o b/bonus/pipex.o new file mode 100644 index 0000000..1975607 Binary files /dev/null and b/bonus/pipex.o differ diff --git a/bonus/pipex_parsing.c b/bonus/pipex_parsing.c index ea66801..a84d4d3 100644 --- a/bonus/pipex_parsing.c +++ b/bonus/pipex_parsing.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/01/19 17:03:01 by erey-bet #+# #+# */ -/* Updated: 2023/01/20 17:49:08 by erey-bet ### ########.fr */ +/* Updated: 2023/01/30 14:19:02 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ int parsing(int argc, char *argv[], t_data *data) { int i; - data->fd2 = open(argv[4], O_WRONLY | O_TRUNC | O_CREAT); + data->fd2 = open(argv[argc - 1], O_WRONLY | O_TRUNC | O_CREAT); if (data->fd2 < 0) return (1); data->fd1 = open(argv[1], O_RDONLY); @@ -25,13 +25,13 @@ int parsing(int argc, char *argv[], t_data *data) data->cmds = ft_calloc(argc - 2, sizeof(char *)); data->flgs = ft_calloc(argc - 2, sizeof(char *)); i = -1; - while (++i < argc - 4) + while (++i < argc - 3) { data->cmds[i] = get_command(argv[2 + i]); data->flgs[i] = ft_split(argv[2 + i], ' '); } data->fl1 = argv[1]; - data->fl2 = argv[4]; + data->fl2 = argv[argc - 1]; return (0); } diff --git a/bonus/pipex_parsing.o b/bonus/pipex_parsing.o new file mode 100644 index 0000000..a95d685 Binary files /dev/null and b/bonus/pipex_parsing.o differ diff --git a/bonus/pipex_utils.o b/bonus/pipex_utils.o new file mode 100644 index 0000000..c37e193 Binary files /dev/null and b/bonus/pipex_utils.o differ diff --git a/get_next_line/get_next_line.o b/get_next_line/get_next_line.o new file mode 100644 index 0000000..3f937bc Binary files /dev/null and b/get_next_line/get_next_line.o differ diff --git a/get_next_line/get_next_line_utils.o b/get_next_line/get_next_line_utils.o new file mode 100644 index 0000000..f0ec4a7 Binary files /dev/null and b/get_next_line/get_next_line_utils.o differ diff --git a/input b/input old mode 100755 new mode 100644 index 9dcb0ca..e69de29 --- a/input +++ b/input @@ -1,22 +0,0 @@ -hello that's why we are here s, your name -im not kidding -what's your name -please can we talk -commandes are not wrking, if you want send me in private -how can i reach you dud, s -pelase give me a wrod that end with a -oh do you mean likw palama -what !!! -palama -sorry id don't know what this mean -me too i don't know, -so way you say it -not your bussnis -hahahahahah -why you ?? -i wnat it to end with s -okay -what bout lives -emmm thats nice -and eyes -emmm thats batter diff --git a/libft/ft_atoi.o b/libft/ft_atoi.o new file mode 100644 index 0000000..17303a8 Binary files /dev/null and b/libft/ft_atoi.o differ diff --git a/libft/ft_atoi_check.o b/libft/ft_atoi_check.o new file mode 100644 index 0000000..843ec1e Binary files /dev/null and b/libft/ft_atoi_check.o differ diff --git a/libft/ft_bzero.o b/libft/ft_bzero.o new file mode 100644 index 0000000..8f185a2 Binary files /dev/null and b/libft/ft_bzero.o differ diff --git a/libft/ft_calloc.o b/libft/ft_calloc.o new file mode 100644 index 0000000..13201ce Binary files /dev/null and b/libft/ft_calloc.o differ diff --git a/libft/ft_get_size.o b/libft/ft_get_size.o new file mode 100644 index 0000000..9d09ecc Binary files /dev/null and b/libft/ft_get_size.o differ diff --git a/libft/ft_isalnum.o b/libft/ft_isalnum.o new file mode 100644 index 0000000..c08b5fa Binary files /dev/null and b/libft/ft_isalnum.o differ diff --git a/libft/ft_isalpha.o b/libft/ft_isalpha.o new file mode 100644 index 0000000..b703773 Binary files /dev/null and b/libft/ft_isalpha.o differ diff --git a/libft/ft_isascii.o b/libft/ft_isascii.o new file mode 100644 index 0000000..926ca43 Binary files /dev/null and b/libft/ft_isascii.o differ diff --git a/libft/ft_isdigit.o b/libft/ft_isdigit.o new file mode 100644 index 0000000..4a1c779 Binary files /dev/null and b/libft/ft_isdigit.o differ diff --git a/libft/ft_isprint.o b/libft/ft_isprint.o new file mode 100644 index 0000000..3a498c8 Binary files /dev/null and b/libft/ft_isprint.o differ diff --git a/libft/ft_itoa.o b/libft/ft_itoa.o new file mode 100644 index 0000000..1decb7c Binary files /dev/null and b/libft/ft_itoa.o differ diff --git a/libft/ft_memchr.o b/libft/ft_memchr.o new file mode 100644 index 0000000..c515b83 Binary files /dev/null and b/libft/ft_memchr.o differ diff --git a/libft/ft_memcmp.o b/libft/ft_memcmp.o new file mode 100644 index 0000000..e45e49d Binary files /dev/null and b/libft/ft_memcmp.o differ diff --git a/libft/ft_memcpy.o b/libft/ft_memcpy.o new file mode 100644 index 0000000..ba83c2a Binary files /dev/null and b/libft/ft_memcpy.o differ diff --git a/libft/ft_memmove.o b/libft/ft_memmove.o new file mode 100644 index 0000000..2974700 Binary files /dev/null and b/libft/ft_memmove.o differ diff --git a/libft/ft_memset.o b/libft/ft_memset.o new file mode 100644 index 0000000..8b36b44 Binary files /dev/null and b/libft/ft_memset.o differ diff --git a/libft/ft_power.o b/libft/ft_power.o new file mode 100644 index 0000000..9e4459c Binary files /dev/null and b/libft/ft_power.o differ diff --git a/libft/ft_putchar_fd.o b/libft/ft_putchar_fd.o new file mode 100644 index 0000000..bd2f6b6 Binary files /dev/null and b/libft/ft_putchar_fd.o differ diff --git a/libft/ft_putendl_fd.o b/libft/ft_putendl_fd.o new file mode 100644 index 0000000..364faed Binary files /dev/null and b/libft/ft_putendl_fd.o differ diff --git a/libft/ft_putnbr_fd.o b/libft/ft_putnbr_fd.o new file mode 100644 index 0000000..3bcbc7e Binary files /dev/null and b/libft/ft_putnbr_fd.o differ diff --git a/libft/ft_putstr_fd.o b/libft/ft_putstr_fd.o new file mode 100644 index 0000000..accddc2 Binary files /dev/null and b/libft/ft_putstr_fd.o differ diff --git a/libft/ft_split.o b/libft/ft_split.o new file mode 100644 index 0000000..aa5138d Binary files /dev/null and b/libft/ft_split.o differ diff --git a/libft/ft_strchr.o b/libft/ft_strchr.o new file mode 100644 index 0000000..7afcea5 Binary files /dev/null and b/libft/ft_strchr.o differ diff --git a/libft/ft_strdup.o b/libft/ft_strdup.o new file mode 100644 index 0000000..9e2087b Binary files /dev/null and b/libft/ft_strdup.o differ diff --git a/libft/ft_strdup_free.o b/libft/ft_strdup_free.o new file mode 100644 index 0000000..085b5f2 Binary files /dev/null and b/libft/ft_strdup_free.o differ diff --git a/libft/ft_strdups.o b/libft/ft_strdups.o new file mode 100644 index 0000000..b438dae Binary files /dev/null and b/libft/ft_strdups.o differ diff --git a/libft/ft_striteri.o b/libft/ft_striteri.o new file mode 100644 index 0000000..9c22927 Binary files /dev/null and b/libft/ft_striteri.o differ diff --git a/libft/ft_strjoin.o b/libft/ft_strjoin.o new file mode 100644 index 0000000..6c66b4a Binary files /dev/null and b/libft/ft_strjoin.o differ diff --git a/libft/ft_strjoin_free.o b/libft/ft_strjoin_free.o new file mode 100644 index 0000000..4614d90 Binary files /dev/null and b/libft/ft_strjoin_free.o differ diff --git a/libft/ft_strlcat.o b/libft/ft_strlcat.o new file mode 100644 index 0000000..b9b8ba3 Binary files /dev/null and b/libft/ft_strlcat.o differ diff --git a/libft/ft_strlcpy.o b/libft/ft_strlcpy.o new file mode 100644 index 0000000..36935b9 Binary files /dev/null and b/libft/ft_strlcpy.o differ diff --git a/libft/ft_strlen.o b/libft/ft_strlen.o new file mode 100644 index 0000000..44a92ad Binary files /dev/null and b/libft/ft_strlen.o differ diff --git a/libft/ft_strlen_double.o b/libft/ft_strlen_double.o new file mode 100644 index 0000000..0c68076 Binary files /dev/null and b/libft/ft_strlen_double.o differ diff --git a/libft/ft_strmapi.o b/libft/ft_strmapi.o new file mode 100644 index 0000000..a6ed151 Binary files /dev/null and b/libft/ft_strmapi.o differ diff --git a/libft/ft_strncmp.o b/libft/ft_strncmp.o new file mode 100644 index 0000000..6a8cdb1 Binary files /dev/null and b/libft/ft_strncmp.o differ diff --git a/libft/ft_strnstr.o b/libft/ft_strnstr.o new file mode 100644 index 0000000..6892ee6 Binary files /dev/null and b/libft/ft_strnstr.o differ diff --git a/libft/ft_strrchr.o b/libft/ft_strrchr.o new file mode 100644 index 0000000..cd68480 Binary files /dev/null and b/libft/ft_strrchr.o differ diff --git a/libft/ft_strslen.o b/libft/ft_strslen.o new file mode 100644 index 0000000..45ef044 Binary files /dev/null and b/libft/ft_strslen.o differ diff --git a/libft/ft_strtrim.o b/libft/ft_strtrim.o new file mode 100644 index 0000000..7df8f10 Binary files /dev/null and b/libft/ft_strtrim.o differ diff --git a/libft/ft_substr.o b/libft/ft_substr.o new file mode 100644 index 0000000..153f309 Binary files /dev/null and b/libft/ft_substr.o differ diff --git a/libft/ft_tolower.o b/libft/ft_tolower.o new file mode 100644 index 0000000..e83e769 Binary files /dev/null and b/libft/ft_tolower.o differ diff --git a/libft/ft_toupper.o b/libft/ft_toupper.o new file mode 100644 index 0000000..ff59a8b Binary files /dev/null and b/libft/ft_toupper.o differ diff --git a/libft/libft.a b/libft/libft.a new file mode 100644 index 0000000..a092af0 Binary files /dev/null and b/libft/libft.a differ diff --git a/output b/output deleted file mode 100755 index e69de29..0000000 diff --git a/pipex b/pipex new file mode 100755 index 0000000..1117b84 Binary files /dev/null and b/pipex differ