From 29e1af2b65d097e533189db4e7d5e20534c17b35 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 14 Jul 2020 10:04:44 +0200 Subject: Refactoring error handling during parsing --- include/ast.h | 4 ++-- include/eval.h | 34 ++++++---------------------------- include/minishell.h | 27 ++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 31 deletions(-) (limited to 'include') diff --git a/include/ast.h b/include/ast.h index 597c444..a767444 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/19 13:29:27 by charles ### ########.fr */ +/* Updated: 2020/07/14 09:57:43 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,7 +77,7 @@ typedef struct s_ast typedef struct s_ret { - t_token *unexpected; + bool syntax_error; t_ast *ast; t_ftlst *rest; } t_ret; diff --git a/include/eval.h b/include/eval.h index 38671aa..261e1a2 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/07/13 09:54:40 by charles ### ########.fr */ +/* Updated: 2020/07/14 09:35:17 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,30 +48,8 @@ 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); - -enum e_error -{ - ERROR_AMBIGUOUS_REDIR, - ERROR_OPEN, - ERROR_CMD_NOT_FOUND, - ERROR_SYNTAX, -}; - -typedef struct -{ - enum e_error id; - int status; - char *msg; // if NULL call strerror - // char *basename; -} t_error; - -/* -** error.c -*/ - -void error_eval_put(enum e_error id, char *unexpected); +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); /* ** cmd.c @@ -90,8 +68,8 @@ 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); +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 f2b237f..9405109 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/23 08:32:46 by charles ### ########.fr */ +/* Updated: 2020/07/14 09:35:14 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,6 +47,8 @@ typedef t_ftht* t_path; typedef t_ftvec* t_env; +extern int g_last_status_code; + /* ** path.c */ @@ -103,4 +105,27 @@ int builtin_exit(char **argv, t_env env); char **preprocess(t_ftlst **tokens, t_env env); char *preprocess_filename(t_ftlst **tokens, t_env env); +/* +** error.c +*/ + +enum e_error +{ + ERROR_AMBIGUOUS_REDIR, + ERROR_OPEN, + ERROR_CMD_NOT_FOUND, + ERROR_SYNTAX, + ERROR_CMD_FOUND_ERROR, +}; + +typedef struct +{ + enum e_error id; + int status; + char *msg; // if NULL call strerror + // char basename; +} t_error; + +void error_eval_put(enum e_error id, char *unexpected); + #endif -- cgit