Skip to content

Commit

Permalink
suite pipex
Browse files Browse the repository at this point in the history
  • Loading branch information
Chloe AUBRY committed Oct 7, 2022
1 parent 2657cb4 commit 9d43543
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ #
# By: caubry <caubry@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/05/04 14:03:48 by jroux-fo #+# #+# #
# Updated: 2022/10/06 13:33:10 by ychibani ### ########.fr #
# Updated: 2022/10/07 16:27:34 by caubry ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -45,6 +45,7 @@ SRCS_FILES = srcs/minishell/minishell.c \
srcs/executor/builtin/export/export_utils.c \
srcs/executor/builtin/unset/unset.c \
srcs/executor/builtin/exit/exit.c \
srcs/executor/pipex/pipex.c


NAME = minishell
Expand Down
14 changes: 11 additions & 3 deletions includes/minishell_fonctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* minishell_fonctions.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ */
/* By: caubry <caubry@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/02 20:42:53 by ychibani #+# #+# */
/* Updated: 2022/10/06 13:32:01 by ychibani ### ########.fr */
/* Updated: 2022/10/07 17:14:13 by caubry ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -110,14 +110,22 @@ void ft_concat_var(t_env *env, char *var_to_split);
** pwd
*/

void ft_pwd(void);
char *ft_getpwd(t_user_input *ui);
void ft_pwd(t_user_input *ui);

/*
** unset
*/

void ft_unset(t_user_input *ui);

/*
** pipex
*/

int ft_pipex(t_user_input *ui);


/*
** exec
*/
Expand Down
40 changes: 30 additions & 10 deletions includes/minishell_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
/* By: caubry <caubry@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/10 16:28:32 by ychibani #+# #+# */
/* Updated: 2022/10/07 15:32:05 by caubry ### ########.fr */
/* Updated: 2022/10/07 18:25:32 by caubry ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef MINISHELL_STRUCTS_H
# define MINISHELL_STRUCTS_H

typedef int t_bool;

typedef struct s_token
{
char *content;
Expand All @@ -37,25 +39,43 @@ typedef struct s_lexer
struct s_lexer *next;
} t_lexer;

// typedef struct s_cmd
// {
// int redirection[2];
// int index;
// char **arg;
// struct s_msh *msh;
// struct s_cmd *next;

// } t_cmd;

typedef struct s_cmd
{
int redirection[2];
int index;
char **arg;
struct s_msh *msh;
struct s_cmd *next;

t_bool mode;
int outfile;
char *cmd;
char *infile_name;
char *outfile_name;
} t_cmd;

typedef struct s_pipe
{
int *pid;
int pipe[2];
int prev_read;
t_cmd *head;
t_cmd *elem;
size_t ninst;
size_t index;
} t_pipe;

typedef struct s_user_input
{
t_list *token;
t_lexer *lexer;
t_lexer *error_delim;
t_env **test_env;
t_cmd *cmd;
int prev_read;
int outfile;
t_pipe *pipe;
char **env;
char *to_tokenize;
int ret_token;
Expand Down
Binary file removed libft/libft.a
Binary file not shown.
Binary file removed minishell
Binary file not shown.
105 changes: 104 additions & 1 deletion srcs/executor/pipex/pipex.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,107 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: caubry <caubry@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/07 16:30:41 by caubry #+# #+# */
/* Updated: 2022/10/07 19:03:23 by caubry ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

t_cmd *ft_cmd_new(t_lexer *lexer, t_cmd *new)
{
while (lexer && lexer->type != PIPE)
{
if (lexer->type == REDIRECTION || lexer->type == HERE_DOC)
lexer = ft_
}
}

t_cmd *init_new_cmd(t_cmd *new)
{
new->mode = 0;
new->outfile = 0;
new->cmd = NULL;
new->infile_name = NULL;
new->outfile_name = NULL;
}

t_lexer *ft_split_cmd(t_lexer *lexer, t_cmd *head)
{
t_cmd *new;
t_cmd *tmp;

new = malloc(sizeof(t_cmd));
if (!(new))
return (NULL);
new = init_new_cmd(new);
new = ft_cmd_new(lexer, new);
if (!head)
head = new;
else
{
tmp = head;
while (tmp->next)
tmp = tmp->next;
tmp->next = new;
}
return (lexer);
}

t_cmd init_cmd_list(t_user_input *ui)
{
t_cmd *head;
t_lexer *split_cmd;

split_cmd = ui->lexer;
head = NULL;
while (split_cmd)
{
split_cmd = ft_split_cmd(split_cmd, head);
}
return (head);
}

void init_pipe(t_user_input *ui, t_pipe *data)
{
data->elem = init_cmd_list(ui);
data->head = data->elem;
data->ninst = ft_lstsize(data->elem);
data->index = 0;
data->pid = (int *)malloc(sizeof(int) * (data->ninst));
if (!data->pid)
_error_prompt("error :");
}

void init(t_pipe *data)
{
data->prev_read = 0;
data->head = NULL;
data->elem = NULL;
data->ninst = 0;
data->index = 0;
data = NULL;
}

t_pipe *ft_init_pipex(t_user_input *ui, t_pipe *pipe)
{
init(pipe);
init_pipe(ui, pipe);
return (pipe);
}

int ft_pipex(t_user_input *ui)
{

ui->pipe = malloc(sizeof(t_pipe));
if (!ui->pipe)
return (perror("error"), STDERR_FILENO);
if (!ft_is_pipe(ui->lexer))
return (ft_cmd(ui));
if (!ft_init_pipex(ui, ui->pipe))
return (STDERR_FILENO);
return (ft_cmd(ui));
}
2 changes: 1 addition & 1 deletion srcs/parser/parsing.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: caubry <caubry@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/12 19:43:21 by ychibani #+# #+# */
/* Updated: 2022/10/07 15:21:53 by caubry ### ########.fr */
/* Updated: 2022/10/07 16:32:29 by caubry ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down

0 comments on commit 9d43543

Please sign in to comment.