From 83c8441919c830c7e683de08330f4edd2fb54d10 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 17 Jun 2020 12:52:06 +0200 Subject: Added env_export and env_keycmp --- include/minishell.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/minishell.h b/include/minishell.h index 97b12e4..148766f 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 12:51:48 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,8 +70,10 @@ t_path path_update(t_path path, char *path_var); */ t_env env_from_array(char **envp); +int env_keycmp(char *var, char *key); char *env_search(t_env env, char *key); char *env_search_first_match(t_env env, const char *haystack); +char *env_export(t_env env, char *key, char *value); /* ** builtin*.c - directory with all builtin commands -- cgit 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 From 4d5e2f861331989f8de16e3b0458e45b34bd0b6f Mon Sep 17 00:00:00 2001 From: nass1pro Date: Thu, 18 Jun 2020 13:19:21 +0200 Subject: Change parse --- include/parser.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/parser.h b/include/parser.h index bc1e549..302c45f 100644 --- a/include/parser.h +++ b/include/parser.h @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */ -/* Updated: 2020/06/17 18:03:33 by nahaddac ### ########.fr */ +/* Updated: 2020/06/18 13:18:13 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,11 +37,20 @@ ** parse.c */ + t_ret *parse(t_ftlst *input); -t_ret *parse_c(t_ftlst *input); +t_ret *parse_op(t_ftlst *input); +t_ret *parse_expr(t_ftlst *input); +t_ret *parse_cmd(t_ftlst *input); + +// utils +t_ret *ret_wrap_ast(t_ast *ast, t_ftlst *rest); +t_ftlst *push_token(t_ftlst **tokens, t_token *pushed); + + + t_ast *push_cmd(t_ast *ast, t_ftlst *ret); t_ast *push_redir(t_ast *ast, t_ftlst *rest); - int parse_cmd_str_true_false(enum e_token_tag tag); int parse_redir_true_false(enum e_token_tag tag); -- cgit