v0.2
This commit is contained in:
parent
5f970ff3d8
commit
ce946aeed1
BIN
.pipex.h.swp
BIN
.pipex.h.swp
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Binary file not shown.
23
libft/ft_strslen.c
Normal file
23
libft/ft_strslen.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strslen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
BIN
libft/ft_strslen.o
Normal file
BIN
libft/ft_strslen.o
Normal file
Binary file not shown.
BIN
libft/libft.a
BIN
libft/libft.a
Binary file not shown.
|
@ -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
|
||||
|
|
101
pipex.c
101
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 <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
7
pipex.h
7
pipex.h
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <fcntl.h>
|
||||
# include <unistd.h>
|
||||
|
||||
typedef struct s_data
|
||||
{
|
||||
char *cmd1;
|
||||
char *flg1;
|
||||
char *cmd2;
|
||||
char *flg2;
|
||||
char *fl1;
|
||||
char *fl2;
|
||||
char *ct_fl1;
|
||||
} t_data;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue