From b16d4b834d95d5cc0757d09e74fe6042e55f5440 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 10 Sep 2020 15:08:28 +0200 Subject: Added better error handling in eval --- include/error.h | 24 +++++++++++++++--------- include/eval.h | 10 +++++----- include/minishell.h | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) (limited to 'include') diff --git a/include/error.h b/include/error.h index 941f1b2..2326d1a 100644 --- a/include/error.h +++ b/include/error.h @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/08/27 20:34:25 by charles #+# #+# */ -/* Updated: 2020/08/27 20:38:52 by charles ### ########.fr */ +/* Updated: 2020/09/10 14:48:42 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,17 +20,23 @@ ** error.c */ -typedef enum +enum { - ERR_FATAL = -1, - ERR_NONE = 0, - ERR_AMBIGUOUS_REDIR = 1, - ERR_OPEN = 1, - ERR_CMD_NOT_FOUND = 127, - ERR_SYNTAX = 2, -} t_err; + ERR_NONE = 1024, + ERR_FATAL, + ERR_SYNTAX, + ERR_OPEN, + ERR_AMBIGUOUS_REDIR, + ERR_CMD_NOT_FOUND, + ERR_IS_DIRECTORY, + ERR_ERRNO, +}; + +typedef int t_err; void errorf(const char *format, ...); void verrorf(const char *format, va_list ap); +void error_set_status(int status); +int error_get_status(int status); #endif diff --git a/include/eval.h b/include/eval.h index a23b249..7139f34 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/09/09 17:27:21 by charles ### ########.fr */ +/* Updated: 2020/09/10 14:14:56 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,9 +39,9 @@ typedef struct t_builtin_entry *builtin; } t_fork_param_cmd; -# define MS_NO_FD -2 -# define FDS_WRITE 1 -# define FDS_READ 0 +# define FD_NONE -2 +# define FD_WRITE 1 +# define FD_READ 0 extern pid_t g_child_pid; @@ -64,7 +64,7 @@ t_ftlst *split_token(t_ftlst **lst, enum e_tok); ** redir.c */ -bool redir_extract(t_tok_lst **redirs, t_env env, int fds[2]); +int redir_extract(t_tok_lst **redirs, t_env env, int fds[2]); /* ** exec.c diff --git a/include/minishell.h b/include/minishell.h index 085f082..7e755a3 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -51,7 +51,7 @@ typedef t_ftht* t_path; typedef t_ftvec* t_env; -extern int g_last_status_code; +extern int g_last_status; extern char *g_basename; /* -- cgit From 98990d5195e93154abbfd16eaa9d1fcc3572bc5c Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 10 Sep 2020 19:46:07 +0200 Subject: Added errorf_ret helper, Removing error to status (just status code and fatal error) --- include/error.h | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/error.h b/include/error.h index 2326d1a..3933fe9 100644 --- a/include/error.h +++ b/include/error.h @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/08/27 20:34:25 by charles #+# #+# */ -/* Updated: 2020/09/10 14:48:42 by charles ### ########.fr */ +/* Updated: 2020/09/10 20:29:17 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,23 +20,10 @@ ** error.c */ -enum -{ - ERR_NONE = 1024, - ERR_FATAL, - ERR_SYNTAX, - ERR_OPEN, - ERR_AMBIGUOUS_REDIR, - ERR_CMD_NOT_FOUND, - ERR_IS_DIRECTORY, - ERR_ERRNO, -}; - -typedef int t_err; +# define EVAL_FATAL 1024 void errorf(const char *format, ...); void verrorf(const char *format, va_list ap); -void error_set_status(int status); -int error_get_status(int status); +int errorf_ret(int err, const char *format, ...); #endif -- cgit From 9446bb78646bef4e3449a59a9e01118b025402bf Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Fri, 11 Sep 2020 19:18:17 +0200 Subject: Removing command local variable --- include/eval.h | 9 +-------- include/lexer.h | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/eval.h b/include/eval.h index 7139f34..b799c26 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/09/10 14:14:56 by charles ### ########.fr */ +/* Updated: 2020/09/11 19:10:30 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,6 @@ typedef struct char *exec_path; char **argv; t_env env; - t_env env_local; t_builtin_entry *builtin; } t_fork_param_cmd; @@ -74,10 +73,4 @@ 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); -/* -** variable.c -*/ - -bool variable_extract(t_tok_lst **argv, t_env env, t_env env_local); - #endif diff --git a/include/lexer.h b/include/lexer.h index fd8972e..7e1bf06 100644 --- a/include/lexer.h +++ b/include/lexer.h @@ -6,7 +6,7 @@ /* By: nahaddac +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/19 10:51:26 by nahaddac #+# #+# */ -/* Updated: 2020/09/10 06:17:43 by nahaddac ### ########.fr */ +/* Updated: 2020/09/11 19:17:06 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,26 @@ # include # include "libft_lst.h" # include "libft_str.h" -// # include "minishell.h" + +/* +** \brief token tags (type of token) +** \param TAG_AND && +** \param TAG_END ; +** \param TAG_OR || +** \param TAG_PIPE | +** \param TAG_REDIR_IN < +** \param TAG_REDIR_OUT > +** \param TAG_REDIR_APPEND >> +** \param TAG_PARENT_OPEN ( +** \param TAG_PARENT_CLOSE ) +** \param TAG_STR unquoted string +** \param TAG_STR_DOUBLE string quoted with " +** \param TAG_STR_SINGLE string quoted with ' +** \param TAG_STICK token is sticked to the next one +** \param TAG_IS_STR all of string tags +** \param TAG_IS_REDIR all of redirection tags +** \param TAG_IS_SEP all of separator tags +*/ enum e_tok { @@ -44,7 +63,13 @@ enum e_tok */ /* -** \warning DO NOT change the order of the fields +** \brief Token list struct +** \param content token string content +** \param next next token in the list (NULL if end) +** \param tag token tag +** \warning DO NOT change the order of the fields +** (they are in the same order as t_ftlst so +** that t_ftlst functions can be used on this struct aswell) */ typedef struct s_tok_lst @@ -61,7 +86,6 @@ t_tok_lst *tok_lst_push_front(t_tok_lst **tokens, t_tok_lst *pushed); void *tok_lst_destroy(t_tok_lst **tokens, void (*del)(void*)); t_tok_lst *tok_lst_last(t_tok_lst *tokens); t_tok_lst *tok_lst_uncons(t_tok_lst **tokens); -t_tok_lst *tok_lst_take_sticked(t_tok_lst **tokens); /* ** lexer.c -- cgit From 65006d0c14d3efa647b3c866ab54bdb1749fa31d Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sat, 12 Sep 2020 17:12:41 +0200 Subject: Added concurrent pipeline (not working with minishell_test for some obscure reason) --- include/eval.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/eval.h b/include/eval.h index b799c26..89f05ef 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/09/11 19:10:30 by charles ### ########.fr */ +/* Updated: 2020/09/12 12:28:36 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,11 +24,11 @@ typedef struct { - t_path path; - t_env env; - t_ast *ast; - int fds[2]; -} t_fork_param_parent; + t_path path; + t_env env; + t_ast *ast; + int fds[2]; +} t_fork_param_args; typedef struct { @@ -42,35 +42,36 @@ typedef struct # define FD_WRITE 1 # define FD_READ 0 -extern pid_t g_child_pid; +extern pid_t g_child_pid; /* ** op.c */ -int eval_op(int fds[2], t_env env, t_path path, t_ast *ast); -int eval(int fds[2], t_env env, t_path path, t_ast *ast); +int eval_op(int fds[2], t_env env, t_path path, t_ast *ast); +int eval(int fds[2], t_env env, t_path path, t_ast *ast); +int eval_forked(int fds[2], t_env env, t_path path, t_ast *ast, pid_t *child_pid); /* ** cmd.c */ -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); -t_ftlst *split_token(t_ftlst **lst, enum e_tok); +int fork_wrap(int fds[2], void *passed, int (*wrapped)(void *param), pid_t *child_pid); +int fork_wrap_wait(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 */ -int redir_extract(t_tok_lst **redirs, t_env env, int fds[2]); +int redir_extract(t_tok_lst **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); +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 -- cgit