faut afire les hairdoc

This commit is contained in:
Etienne Rey-bethbeder 2023-01-31 16:06:15 +01:00
parent dac4fe9717
commit f30c4843ee
54 changed files with 31 additions and 51 deletions

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/18 18:04:58 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; i = -1;
while (++i < data->argc - 3) while (++i < data->argc - 3)
free(data->cmds[i]); free(data->cmds[i]);
free(data->cmds);
return (1); 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(fl1, 0);
dup2(fl2, 1); dup2(fl2, 1);
close(fd[0][0]); close(data.fd[0][0]);
close(fd[0][1]); close(data.fd[0][1]);
close(fd[1][0]); close(data.fd[1][0]);
close(fd[1][1]); close(data.fd[1][1]);
execve(data.cmds[0], data.flgs[0], data.env); 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) if (t == 0)
make_cmd(fd, data, data.fd1, 0); make_cmd(data, 0, data.fd1, data.fd[0][1]);
else if (t == 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) 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); free_all(&data);
exit(1); exit(1);
} }
int pipex(int argc, t_data data) int pipex(int argc, t_data data)
{ {
int fd[2][2];
int *fk; int *fk;
int i; int i;
if (pipe(fd[0]) < -1) if (pipe(data.fd[0]) < -1)
return (1); return (1);
if (pipe(fd[1]) < -1) if (pipe(data.fd[1]) < -1)
return (1); return (1);
fk = ft_calloc(argc - 3, sizeof(int)); fk = ft_calloc(argc - 3, sizeof(int));
i = -1; i = -1;
while (++i < argc - 3) while (++i < argc - 3)
{ {
fk[i] = fork(); fk[i] = fork();
if (fk < 0) if (fk[i] < 0)
return (1); return (1);
if (fk == 0) if (fk[i] == 0)
{ {
if (i == 0 && data.fd1 > 0 && data.cmds[0]) if (i == 0 && data.fd1 > 0 && data.cmds[0])
cmd(fd, data, i, 0); cmd(data, i, 0);
else if (i == argc - 3) else if (i + 1 < argc - 3)
cmd(fd, data, i, 1); cmd(data, i, 1);
else else
cmd(fd, data, i, 2); cmd(data, i, 2);
} }
} }
close(fd[0][0]); close(data.fd[0][0]);
close(fd[0][1]); close(data.fd[0][1]);
close(fd[1][0]); close(data.fd[1][0]);
close(fd[1][1]); close(data.fd[1][1]);
if (data.fd1 > 0 && data.cmds[0]) if (data.fd1 > 0 && data.cmds[0])
waitpid(fk[0], NULL, 0); waitpid(fk[0], NULL, 0);
i = -1; i = -1;
while (++i < argc - 3) while (++i < argc - 3)
waitpid(fk[i], NULL, 0); waitpid(fk[i], NULL, 0);
free(fk);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/11 15:33:34 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; char *fl2;
int fd1; int fd1;
int fd2; int fd2;
int fd[2][2];
char **env; char **env;
int argc; int argc;
} t_data; } t_data;

BIN
bonus/pipex.o Normal file

Binary file not shown.

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/19 17:03:01 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; 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) if (data->fd2 < 0)
return (1); return (1);
data->fd1 = open(argv[1], O_RDONLY); 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->cmds = ft_calloc(argc - 2, sizeof(char *));
data->flgs = ft_calloc(argc - 2, sizeof(char *)); data->flgs = ft_calloc(argc - 2, sizeof(char *));
i = -1; i = -1;
while (++i < argc - 4) while (++i < argc - 3)
{ {
data->cmds[i] = get_command(argv[2 + i]); data->cmds[i] = get_command(argv[2 + i]);
data->flgs[i] = ft_split(argv[2 + i], ' '); data->flgs[i] = ft_split(argv[2 + i], ' ');
} }
data->fl1 = argv[1]; data->fl1 = argv[1];
data->fl2 = argv[4]; data->fl2 = argv[argc - 1];
return (0); return (0);
} }

BIN
bonus/pipex_parsing.o Normal file

Binary file not shown.

BIN
bonus/pipex_utils.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

22
input Executable file → Normal file
View file

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

BIN
libft/ft_atoi.o Normal file

Binary file not shown.

BIN
libft/ft_atoi_check.o Normal file

Binary file not shown.

BIN
libft/ft_bzero.o Normal file

Binary file not shown.

BIN
libft/ft_calloc.o Normal file

Binary file not shown.

BIN
libft/ft_get_size.o Normal file

Binary file not shown.

BIN
libft/ft_isalnum.o Normal file

Binary file not shown.

BIN
libft/ft_isalpha.o Normal file

Binary file not shown.

BIN
libft/ft_isascii.o Normal file

Binary file not shown.

BIN
libft/ft_isdigit.o Normal file

Binary file not shown.

BIN
libft/ft_isprint.o Normal file

Binary file not shown.

BIN
libft/ft_itoa.o Normal file

Binary file not shown.

BIN
libft/ft_memchr.o Normal file

Binary file not shown.

BIN
libft/ft_memcmp.o Normal file

Binary file not shown.

BIN
libft/ft_memcpy.o Normal file

Binary file not shown.

BIN
libft/ft_memmove.o Normal file

Binary file not shown.

BIN
libft/ft_memset.o Normal file

Binary file not shown.

BIN
libft/ft_power.o Normal file

Binary file not shown.

BIN
libft/ft_putchar_fd.o Normal file

Binary file not shown.

BIN
libft/ft_putendl_fd.o Normal file

Binary file not shown.

BIN
libft/ft_putnbr_fd.o Normal file

Binary file not shown.

BIN
libft/ft_putstr_fd.o Normal file

Binary file not shown.

BIN
libft/ft_split.o Normal file

Binary file not shown.

BIN
libft/ft_strchr.o Normal file

Binary file not shown.

BIN
libft/ft_strdup.o Normal file

Binary file not shown.

BIN
libft/ft_strdup_free.o Normal file

Binary file not shown.

BIN
libft/ft_strdups.o Normal file

Binary file not shown.

BIN
libft/ft_striteri.o Normal file

Binary file not shown.

BIN
libft/ft_strjoin.o Normal file

Binary file not shown.

BIN
libft/ft_strjoin_free.o Normal file

Binary file not shown.

BIN
libft/ft_strlcat.o Normal file

Binary file not shown.

BIN
libft/ft_strlcpy.o Normal file

Binary file not shown.

BIN
libft/ft_strlen.o Normal file

Binary file not shown.

BIN
libft/ft_strlen_double.o Normal file

Binary file not shown.

BIN
libft/ft_strmapi.o Normal file

Binary file not shown.

BIN
libft/ft_strncmp.o Normal file

Binary file not shown.

BIN
libft/ft_strnstr.o Normal file

Binary file not shown.

BIN
libft/ft_strrchr.o Normal file

Binary file not shown.

BIN
libft/ft_strslen.o Normal file

Binary file not shown.

BIN
libft/ft_strtrim.o Normal file

Binary file not shown.

BIN
libft/ft_substr.o Normal file

Binary file not shown.

BIN
libft/ft_tolower.o Normal file

Binary file not shown.

BIN
libft/ft_toupper.o Normal file

Binary file not shown.

BIN
libft/libft.a Normal file

Binary file not shown.

0
output
View file

BIN
pipex Executable file

Binary file not shown.