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 100644 new mode 100755 index e69de29..b33c560 --- a/input +++ b/input @@ -0,0 +1 @@ +test test 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..d6931e4 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..6dd6e56 Binary files /dev/null and b/libft/libft.a differ diff --git a/output b/output old mode 100644 new mode 100755 index e69de29..0cfbf08 --- a/output +++ b/output @@ -0,0 +1 @@ +2 diff --git a/pipex b/pipex new file mode 100755 index 0000000..82701d7 Binary files /dev/null and b/pipex differ diff --git a/pipex.c b/pipex.c index 1ad16fc..356c0bb 100644 --- a/pipex.c +++ b/pipex.c @@ -29,19 +29,23 @@ int get_next(char *cmd, char c) return (i); } -char *get_flags(char *cmd) +char **get_flags(char *cmd) { - int i; - int y; - char *new_str; + size_t i; + int y; + char *new_str; + char **flags; - i = get_next(cmd, '-') + 1; + i = get_next(cmd, ' ') + 1; new_str = ft_calloc(ft_strlen(cmd) - i + 1, 1); y = 0; while (cmd[i]) new_str[y++] = cmd[i++]; new_str[y] = '\0'; - return (new_str); + flags = ft_split(new_str, ' '); + i = 0; + free(new_str); + return (flags); } char *get_command(char *cmd) @@ -57,6 +61,28 @@ char *get_command(char *cmd) return (new_str); } +char **add_cmd(char **flg, char *cmd) +{ + char *tmp; + int i; + int check; + + tmp = NULL; + i = 0; + check = 0; + while (check == 0) + { + if (flg[i] == NULL) + check = 1; + if (tmp != NULL) + flg[i] = tmp; + tmp = flg[i]; + i++; + } + flg[0] = cmd; + return (flg); +} + int parsing(char *argv[], t_data *data) { int fd1; @@ -65,7 +91,7 @@ int parsing(char *argv[], t_data *data) fd2 = open(argv[4], O_WRONLY | O_TRUNC | O_CREAT); if (fd2 < 0) return (-1); - fd1 = open(argv[1], O_RDONLY | O_TRUNC | O_CREAT); + fd1 = open(argv[1], O_RDONLY); if (fd1 < 0) { close(fd2); @@ -74,10 +100,12 @@ int parsing(char *argv[], t_data *data) data->cmd1 = get_command(argv[2]); data->cmd2 = get_command(argv[3]); data->flg1 = get_flags(argv[2]); + data->flg1 = add_cmd(data->flg1, data->cmd1); data->flg2 = get_flags(argv[3]); + data->flg2 = add_cmd(data->flg2, data->cmd2); data->fl1 = argv[1]; data->fl2 = argv[4]; - data->ct_fl1 = read_file(fd1); + //data->ct_fl1 = read_file(fd1); data->fd1 = fd1; data->fd2 = fd2; return (0); @@ -87,33 +115,35 @@ char *find_command(char **env, char *cmd) { char *path; char *s; - int fd; int i; int y; while (*env != NULL) { - if (ft_strnstr(*env, "PATH=/", ft_strlen(*env))) + if (ft_strnstr(*env, "PATH=/", ft_strlen(*env)) + && ft_strchr(*env, ':') > 0) break; env++; } - i = 4; - y = 4; - s = malloc(ft_strlen(*env) + 1); - while (*env[i]) + i = 5; + y = 0; + s = ft_calloc(ft_strlen(*env) + 1, 1); + while ((*env)[i]) { - if (*env[i] != ':') - s[y++] = *env[i]; + if ((*env)[i] != ':') + s[y++] = (*env)[i]; else { + s = ft_strjoin(s, "/"); path = ft_strjoin(s, cmd); - fd = open(path, O_RDONLY); - free(path); - if (fd != -1) + if (access(path, X_OK) == 0) { free(s); return (path); } + free(s); + free(path); + s = ft_calloc(ft_strlen(*env) + 1, 1); y = 0; } i++; @@ -127,7 +157,7 @@ void first_cmd(int fd[2], t_data data) dup2(fd[1], 1); close(fd[0]); close(fd[1]); - execve(data.cmd1, &data.flg1, NULL); + execve(data.cmd1, data.flg1, data.env); } void second_cmd(int fd[2], t_data data) @@ -136,7 +166,7 @@ void second_cmd(int fd[2], t_data data) dup2(data.fd2, 1); close(fd[0]); close(fd[1]); - execve(data.cmd2, &data.flg2, NULL); + execve(data.cmd2, data.flg2, data.env); } int pipex(t_data data) @@ -160,14 +190,14 @@ int pipex(t_data data) return (0); } -#include - int main(int argc, char *argv[], char **env) { t_data data; //(void)argc; //(void)argv; + //char **test = ft_split(argv[2], ' '); + //execve(find_command(env, argv[1]), test, env); if (argc < 5) return (1); if (parsing(argv, &data)) @@ -178,9 +208,9 @@ int main(int argc, char *argv[], char **env) data.cmd2 = find_command(env, data.cmd2); if (data.cmd2 == NULL) return (4); + data.env = env; if (pipex(data)) return (5); - free(data.fl1); close(data.fd1); close(data.fd2); return (0); diff --git a/pipex.h b/pipex.h index e57f4db..94442e0 100644 --- a/pipex.h +++ b/pipex.h @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/01/11 15:33:34 by erey-bet #+# #+# */ -/* Updated: 2023/01/12 17:34:59 by erey-bet ### ########.fr */ +/* Updated: 2023/01/16 18:52:06 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,14 +23,15 @@ typedef struct s_data { char *cmd1; - char *flg1; + char **flg1; char *cmd2; - char *flg2; + char **flg2; char *fl1; char *fl2; char *ct_fl1; int fd1; int fd2; + char **env; } t_data; #endif diff --git a/pipex.o b/pipex.o new file mode 100644 index 0000000..2252866 Binary files /dev/null and b/pipex.o differ