From e5393671a265e1c301c6c303f21f938c4cf9ca75 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 2 Apr 2020 15:50:13 +0200 Subject: Evaluation pipe frame (not tested) --- include/ast.h | 4 +++- include/eval.h | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/ast.h b/include/ast.h index 0d14779..6470a17 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/04/01 17:52:43 by charles ### ########.fr */ +/* Updated: 2020/04/02 13:27:59 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -76,12 +76,14 @@ typedef struct s_cmd ** \brief AST node tag (type) ** \param TAG_CMD Command AST node ** \param TAG_LINE Line AST node +** \param TAG_ROOT Root line AST node */ typedef enum e_ast_tag { TAG_CMD, TAG_LINE, + TAG_ROOT, } t_ast_tag; /* diff --git a/include/eval.h b/include/eval.h index 31f729b..31f79c2 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/04/01 17:53:26 by charles ### ########.fr */ +/* Updated: 2020/04/02 15:38:11 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,11 +43,17 @@ typedef struct s_eval_status int status; } t_eval_status; +typedef struct +{ + int pipe_in[2]; + int pipe_out[2]; +} t_io_frame; + /* ** eval.c */ -int eval(t_eval_state *state, t_ast *ast); +int eval(t_io_frame *frame, t_eval_state *state, t_ast *ast); /* ** exec.c @@ -63,5 +69,6 @@ char *exec_search_path(t_path path, char *path_var, char *exec_name); int pipe_setup_parent(t_cmd *cmd, int pipe_in[2], int pipe_out[2]); int pipe_setup_child(int pipe_in[2], int pipe_out[2]); +int io_frame_init(t_io_frame *frame); #endif -- cgit From c0e2ee28eedc1a9a886f9729a994d77738e2eb58 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 3 Apr 2020 15:13:08 +0200 Subject: Refactoring env, connecting pipes, preprocess draft --- include/minishell.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/minishell.h b/include/minishell.h index ac00875..bc404d4 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/04/01 22:13:47 by charles ### ########.fr */ +/* Updated: 2020/04/03 14:24:34 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,7 @@ # include "libft_lst.h" # include "libft_util.h" # include "libft_vec.h" +# include "libft_dstr.h" /* ** \brief Value of pipe entry if closed @@ -103,10 +104,20 @@ int builtin_unset(char **argv, t_env env); int builtin_env(char **argv, t_env env); int builtin_exit(char **argv, t_env env); +/* +** preprocess.c +*/ + +char *preprocess(char *input, t_env env); + /* ** util.c - various utilitary functions */ -void ht_del_str_entry(t_ftht_entry *entry); +int utils_directory_iter( + char *dirname, + void *param, + int (*f)(char*, struct dirent*, void*) + ); #endif -- cgit From db122618b7dd0e1c2b9432e3f470c880e0d4422e Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 4 Apr 2020 19:11:05 +0200 Subject: Glob logic mainly done --- include/minishell.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/minishell.h b/include/minishell.h index bc404d4..ed332c4 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/04/03 14:24:34 by charles ### ########.fr */ +/* Updated: 2020/04/04 14:50:21 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -108,6 +108,7 @@ int builtin_exit(char **argv, t_env env); ** preprocess.c */ +char *ms_glob(char *pattern); char *preprocess(char *input, t_env env); /* -- cgit From 4aeba6d2f03706fa21281709a138a7d3ea9797dc Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 5 Apr 2020 15:04:23 +0200 Subject: Preprocessing (glob and iterpolation) draft (not tested) --- include/minishell.h | 14 ++------------ include/ms_glob.h | 32 ++++++++++++++++++++++++++++++++ include/utils.h | 31 +++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 include/ms_glob.h create mode 100644 include/utils.h (limited to 'include') diff --git a/include/minishell.h b/include/minishell.h index ed332c4..9551c1f 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/04/04 14:50:21 by charles ### ########.fr */ +/* Updated: 2020/04/05 14:52:20 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,6 +71,7 @@ t_path path_update(t_path path, char *path_var); t_env env_from_array(char **envp); char *env_search(t_env env, char *key); +char *env_search_first_match(t_env env, const char *haystack); /* ** builtin*.c - directory with all builtin commands @@ -108,17 +109,6 @@ int builtin_exit(char **argv, t_env env); ** preprocess.c */ -char *ms_glob(char *pattern); char *preprocess(char *input, t_env env); -/* -** util.c - various utilitary functions -*/ - -int utils_directory_iter( - char *dirname, - void *param, - int (*f)(char*, struct dirent*, void*) - ); - #endif diff --git a/include/ms_glob.h b/include/ms_glob.h new file mode 100644 index 0000000..774d3be --- /dev/null +++ b/include/ms_glob.h @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ms_glob.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/05 11:45:11 by charles #+# #+# */ +/* Updated: 2020/04/05 13:05:10 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MS_GLOB_H +# define MS_GLOB_H + +# include +# include +# include +# include "libft_str.h" +# include "libft_vec.h" +# include "utils.h" + +struct s_glob_param +{ + char *pattern; + t_ftvec *matches; +}; + +t_ftvec *glob_matches(char *pattern); +char *ms_glob(char *pattern); + +#endif diff --git a/include/utils.h b/include/utils.h new file mode 100644 index 0000000..6f2fbc9 --- /dev/null +++ b/include/utils.h @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/05 12:05:49 by charles #+# #+# */ +/* Updated: 2020/04/05 14:51:38 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef UTILS_H +# define UTILS_H + +/* +** \file utils.h +** \brief Various utilitary functions +*/ + +typedef int (*t_directory_iter_func)(char*, struct dirent*, void*); + +int utils_directory_iter( + char *dirname, + void *param, + t_directory_iter_func f +); + +size_t utils_var_end(char *name); + +#endif -- cgit From 9fabc25a980550afc6337fd729632462f2680daa Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 12 Apr 2020 18:36:17 +0200 Subject: Removing data name in ast union, io_frame, root line ast tag --- include/ast.h | 19 ++++++++----------- include/eval.h | 23 +++++++++++++++-------- 2 files changed, 23 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/ast.h b/include/ast.h index 6470a17..b725c8b 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/04/02 13:27:59 by charles ### ########.fr */ +/* Updated: 2020/05/04 11:59:43 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,10 +25,10 @@ /* ** \brief Separator type -** \param SEP_END Regular command end `;` -** \param SEP_PIPE Pipe output of left to right `|` -** \param SEP_AND Execute right if left status == 0 `&&` -** \param SEP_OR Execute right if left status != 0 `||` +** \param SEP_END `;` Regular command end +** \param SEP_PIPE `|` Pipe output of left to right +** \param SEP_AND `&&` Execute right if left status == 0 +** \param SEP_OR `||` Execute right if left status != 0 */ typedef enum e_sep @@ -76,22 +76,19 @@ typedef struct s_cmd ** \brief AST node tag (type) ** \param TAG_CMD Command AST node ** \param TAG_LINE Line AST node -** \param TAG_ROOT Root line AST node */ typedef enum e_ast_tag { TAG_CMD, TAG_LINE, - TAG_ROOT, } t_ast_tag; /* ** \brief AST node struct ** \param tag Node tag -** \param data Union containning possible node data -** \param data::cmd Command struct -** \param data::line Line struct +** \param cmd Command struct +** \param line Line struct */ typedef struct s_ast @@ -101,7 +98,7 @@ typedef struct s_ast { t_line line; t_cmd cmd; - } data; + } ; } t_ast; t_ast *ast_new(t_ast_tag tag, void *data); diff --git a/include/eval.h b/include/eval.h index 31f79c2..fc149b2 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/04/02 15:38:11 by charles ### ########.fr */ +/* Updated: 2020/05/04 11:58:16 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,8 +27,7 @@ typedef struct { - int pipe_in[2]; - int pipe_out[2]; + int p[2]; t_path path; t_env env; } t_eval_state; @@ -45,15 +44,24 @@ typedef struct s_eval_status typedef struct { - int pipe_in[2]; - int pipe_out[2]; -} t_io_frame; + t_eval_state *state; + t_line *line; + int fd_in; + int fd_out; +} t_fork_param_line; + +typedef struct +{ + char *exec_path; + char **argv; + char **envp; +} t_fork_param_execve; /* ** eval.c */ -int eval(t_io_frame *frame, t_eval_state *state, t_ast *ast); +int eval(int fd_in, int fd_out, t_eval_state *state, t_ast *ast); /* ** exec.c @@ -69,6 +77,5 @@ char *exec_search_path(t_path path, char *path_var, char *exec_name); int pipe_setup_parent(t_cmd *cmd, int pipe_in[2], int pipe_out[2]); int pipe_setup_child(int pipe_in[2], int pipe_out[2]); -int io_frame_init(t_io_frame *frame); #endif -- cgit