diff --git a/.pipex.h.swp b/.pipex.h.swp index 2e251c5..cd117f4 100644 Binary files a/.pipex.h.swp and b/.pipex.h.swp differ diff --git a/libft/Makefile b/libft/Makefile index 27c4c00..b12262c 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -17,7 +17,7 @@ ft_memchr.c ft_memcmp.c ft_strnstr.c ft_atoi.c ft_calloc.c ft_strdup.c \ ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c \ ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \ ft_get_size.c ft_power.c ft_atoi_check.c ft_strlen_double.c ft_strjoin_free.c \ -ft_strdup_free.c ft_strdups.c +ft_strdup_free.c ft_strdups.c ft_strslen.c OBJS = ${SRCS:.c=.o} BONUS_SRCS = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c \ ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c diff --git a/libft/ft_strdups.c b/libft/ft_strdups.c index 56d22ed..d9e0c2c 100644 --- a/libft/ft_strdups.c +++ b/libft/ft_strdups.c @@ -12,16 +12,6 @@ #include "libft.h" -static int ft_strslen(char **src) -{ - int i; - - i = 0; - while (src[i]) - i++; - return (i); -} - char **ft_strdups(char **src) { char **src_copy; diff --git a/libft/ft_strdups.o b/libft/ft_strdups.o index 64e6319..b438dae 100644 Binary files a/libft/ft_strdups.o and b/libft/ft_strdups.o differ diff --git a/libft/ft_strslen.c b/libft/ft_strslen.c new file mode 100644 index 0000000..c91921d --- /dev/null +++ b/libft/ft_strslen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strslen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/26 14:25:30 by erey-bet #+# #+# */ +/* Updated: 2023/01/12 16:51:53 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strslen(char **src) +{ + int i; + + i = 0; + while (src[i]) + i++; + return (i); +} 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/libft.a b/libft/libft.a index 37239c4..6dd6e56 100644 Binary files a/libft/libft.a and b/libft/libft.a differ diff --git a/libft/libft.h b/libft/libft.h index 651b5a2..c552ecc 100644 --- a/libft/libft.h +++ b/libft/libft.h @@ -71,4 +71,6 @@ void ft_lstiter(t_list *lst, void (*f)(void *)); t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); int ft_atoi_check(const char *nptr); int ft_strlen_double(char **strs); +int ft_strslen(char **src); + #endif diff --git a/pipex b/pipex index b56f28b..25d0828 100755 Binary files a/pipex and b/pipex differ diff --git a/pipex.c b/pipex.c index 57c630b..36c82bd 100644 --- a/pipex.c +++ b/pipex.c @@ -19,10 +19,49 @@ char *read_file(int fd) return (str); } +int get_next(char *cmd, char c) +{ + int i; + + i = 0; + while (cmd[i] != c) + i++; + return (i); +} + +char *get_flags(char *cmd) +{ + int i; + int y; + char *new_str; + + i = get_next(cmd, ' '); + new_str = ft_calloc(ft_strlen(cmd) - i + 1); + y = i; + while (cmd[i]) + new_str[y++] = cmd[i++]; + new_str[y] = '\0'; + return (new_str); +} + +char *get_command(char *cmd) +{ + int i; + char *new_str; + + new_str = ft_calloc(get_next(cmd, ' ') + 1); + i = -1; + while (cmd[++i] != ' ') + new_str[i] = cmd[i]; + new_str[i] = '\0'; + return (new_str); +} + int parsing(char *argv[], t_data *data) { int fd1; int fd2; + fd2 = open(argv[4], O_WRONLY | O_TRUNC | O_CREAT); if (fd2 < 0) return (-1); @@ -32,30 +71,70 @@ int parsing(char *argv[], t_data *data) close(fd2); return (-1); } - data->cmd1 = argv[2]; - data->cmd2 = argv[3]; - data->fl1 = read_file(fd1); + data->cmd1 = get_command(argv[2]); + data->cmd2 = get_command(argv[3]); + data->flg1 = get_flags(argv[2]); + data->flg2 = get_flags(argv[3]); + data->fl1 = argv[1]; + data->fl2 = argv[4]; + data->ct_fl1 = read_file(fd1); close(fd1); return (0); } -void pipex(t_data data) +int find_command(char **env) +{ + char *s; + + while (*env != NULL) + { + if (ft_strnstr(*env, "PATH=/", ft_strlen(*env))) + s = *env; + env++; + } +} + +int first_cmd(int fd[2], t_data data) +{ + close(fd[0]); + execve(data->cmd1) +} + +int second_cmd(int fd[2], t_data data) { - int fd[2] } -int main(int argc, char *argv[]) +int pipex(t_data data) { - t_data data; + int fd[2] + int id; - if (argc < 5) + if (pipe(fd) < -1) + return (1); + id = fork(); + if (id == 0) + 1_cmd(fd, data); + else + 2_cmd(fd, data); +} + +#include + +int main(int argc, char *argv[], char **env) +{ + //t_data data; + + (void)argc; + (void)argv; + /*if (argc < 5) return (1); if (parsing(argv, &data)) return (2); - - pipex(data); - free(data.fl1); + find_command(env); + if (pipex(data)) + return (3); + free(data.fl1);*/ return (0); } diff --git a/pipex.h b/pipex.h index 2a05078..69c4ff0 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/11 16:51:43 by erey-bet ### ########.fr */ +/* Updated: 2023/01/12 17:34:59 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,17 @@ # include "libft/libft.h" # include "get_next_line/get_next_line.h" # include +# include typedef struct s_data { char *cmd1; + char *flg1; char *cmd2; + char *flg2; char *fl1; + char *fl2; + char *ct_fl1; } t_data; #endif diff --git a/pipex.o b/pipex.o new file mode 100644 index 0000000..7e82803 Binary files /dev/null and b/pipex.o differ