From 9aab4ace12a04d0c5477909e54bb43fefcd19f9c Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 17 Jun 2020 17:10:46 +0200 Subject: Added (basic) operator evaluation --- include/ast.h | 22 +++++++++++----------- include/eval.h | 37 +++++++++++++++++++++---------------- include/minishell.h | 14 +------------- 3 files changed, 33 insertions(+), 40 deletions(-) (limited to 'include') diff --git a/include/ast.h b/include/ast.h index bcb5e11..cbbe061 100644 --- a/include/ast.h +++ b/include/ast.h @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:05:38 by charles #+# #+# */ -/* Updated: 2020/06/14 17:47:10 by charles ### ########.fr */ +/* Updated: 2020/06/17 16:34:45 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,36 +26,36 @@ struct s_ast; /* -** \brief Line struct +** \brief Operation struct ** \param left AST to the left of separator ** \param right AST to the right of separator ** \param sep Type of separator */ -typedef struct s_line +typedef struct s_op { struct s_ast *left; struct s_ast *right; enum e_token_tag sep; -} t_line; +} t_op; /* ** \brief AST node tag (type) ** \param TAG_CMD Command AST node -** \param TAG_LINE Line AST node +** \param TAG_OP Operation AST node */ enum e_ast_tag { AST_CMD, - AST_LINE, + AST_OP, }; /* ** \brief AST node struct ** \param tag Node tag -** \param line Line struct +** \param op Operation struct ** \param cmd_argv Array of string tokens ** \param in STDIN redirection string tokens ** \param out STDOUT redirection string tokens @@ -65,11 +65,11 @@ enum e_ast_tag typedef struct s_ast { enum e_ast_tag tag; - union - { - t_line line; + // union + // { + t_op op; t_ftlst *cmd_argv; - }; + // }; t_ftlst *redirs; } t_ast; diff --git a/include/eval.h b/include/eval.h index f834d45..79ebfeb 100644 --- a/include/eval.h +++ b/include/eval.h @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:05:30 by charles #+# #+# */ -/* Updated: 2020/06/15 11:09:49 by charles ### ########.fr */ +/* Updated: 2020/06/17 16:41:58 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ */ # include "minishell.h" +# include "lexer.h" # include "ast.h" /* @@ -44,10 +45,10 @@ typedef struct s_eval_status typedef struct { t_eval_state *state; - t_line *line; + t_op *op; int fd_in; int fd_out; -} t_fork_param_line; +} t_fork_param_op; typedef struct { @@ -57,21 +58,16 @@ typedef struct t_builtin_func builtin; } t_fork_param_cmd; -#define MS_NO_FD -2 +# define MS_NO_FD -2 +# define FDS_WRITE 1 +# define FDS_READ 0 /* -** eval.c +** op.c */ -int eval(int fd_in, int fd_out, t_eval_state *state, t_ast *ast); - -/* -** exec.c -*/ - -bool exec_is_path(char *path_str); -bool exec_is_valid(char *exec_path); -char *exec_search_path(t_path path, char *path_var, char *exec_name); +int eval_op(int fds[2], t_env env, t_path path, t_op *op); +int eval(int fds[2], t_env env, t_path path, t_ast *ast); enum e_error { @@ -99,12 +95,21 @@ void error_eval_put(enum e_error id, char *unexpected); ** cmd.c */ -int eval_cmd(t_env env, t_path path, t_ast *ast); +int fork_wrap(int fds[2], void *passed, int (*wrapped)(void *param)); +int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast); /* ** redir.c */ -bool redir_extract(t_ftlst *redirs, t_env env, int *fd_in, int *fd_out); +bool redir_extract(t_ftlst *redirs, t_env env, int fds[2]); + +/* +** exec.c +*/ + +bool exec_is_path(char *exec_name); +bool exec_is_valid(char *exec_path); +char *exec_search_path(t_path path, char *path_var, char *exec_name); #endif diff --git a/include/minishell.h b/include/minishell.h index 97b12e4..1c5bd56 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/26 15:33:51 by cacharle #+# #+# */ -/* Updated: 2020/06/15 09:47:20 by charles ### ########.fr */ +/* Updated: 2020/06/17 16:10:31 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,18 +42,6 @@ # define PIPE_CLOSED -1 -/* -** \brief Pipe write index -*/ - -# define PIPE_WRITE 1 - -/* -** \brief Pipe read index -*/ - -# define PIPE_READ 0 - # define BUILTIN_NOT_FOUND -2 typedef t_ftht* t_path; -- cgit