diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-01 15:55:57 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-01 15:55:57 +0200 |
| commit | 2eb59ee61e49b60472f82c000dd4f3536bd1987c (patch) | |
| tree | 190ac7bc42051ee9fcc7c1d781be16afa4d43075 /include | |
| parent | 551e668e1b7a030fdff236067963100c7d8747a5 (diff) | |
| download | minishell-2eb59ee61e49b60472f82c000dd4f3536bd1987c.tar.gz minishell-2eb59ee61e49b60472f82c000dd4f3536bd1987c.tar.bz2 minishell-2eb59ee61e49b60472f82c000dd4f3536bd1987c.zip | |
Added builtin support in command eval, Refactoring eval/builtin function, Added doc
Diffstat (limited to 'include')
| -rw-r--r-- | include/ast.h | 19 | ||||
| -rw-r--r-- | include/eval.h | 26 | ||||
| -rw-r--r-- | include/minishell.h | 36 |
3 files changed, 61 insertions, 20 deletions
diff --git a/include/ast.h b/include/ast.h index 63dc12c..754956a 100644 --- a/include/ast.h +++ b/include/ast.h @@ -27,7 +27,8 @@ typedef enum SEP_OR, } t_sep; -typedef struct s_ast t_ast; +struct s_ast; + /** ** \brief Line struct ** \param left AST to the left of separator @@ -37,8 +38,8 @@ typedef struct s_ast t_ast; typedef struct { - t_ast *left; - t_ast *right; + struct s_ast *left; + struct s_ast *right; t_sep sep; } t_line; @@ -58,6 +59,12 @@ typedef struct bool is_append; } t_cmd; +/** +** \brief AST node tag (type) +** \param TAG_CMD Command AST node +** \param TAG_LINE Line AST node +*/ + typedef enum { TAG_CMD, @@ -66,13 +73,13 @@ typedef enum /** ** \brief AST node struct -** \param type Node type +** \param tag Node tag ** \param data Union containning possible node data ** \param data::cmd Command struct ** \param data::line Line struct */ -struct s_ast +typedef struct s_ast { t_ast_tag tag; union @@ -80,7 +87,7 @@ struct s_ast t_line line; t_cmd cmd; } data; -}; +} t_ast; t_ast *ast_new(t_ast_tag tag, void *data); void ast_destroy(t_ast *ast); diff --git a/include/eval.h b/include/eval.h index 0c3240a..55cd497 100644 --- a/include/eval.h +++ b/include/eval.h @@ -15,8 +15,8 @@ typedef struct { - int in_pipe[2]; // need stack pipe - int out_pipe[2]; + int pipe_in[2]; // need stack pipe + int pipe_out[2]; t_path path; t_env env; } t_eval_state; @@ -31,13 +31,25 @@ typedef struct int status; } t_eval_status; - -/** -** \brief Evaluate an AST -** \param state State of the evaluation -** \param ast Abstract syntax tree to evaluate +/* +** eval.c */ int eval(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); + +/* +** pipe.c +*/ + +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]); + #endif diff --git a/include/minishell.h b/include/minishell.h index 4f33951..a3970dd 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -52,6 +52,8 @@ # define PIPE_READ 0 +# define BUILTIN_NOT_FOUND -2 + typedef t_ftht* t_path; typedef t_ftht* t_env; @@ -72,13 +74,33 @@ char **env_to_array(t_env env); ** builtin*.c - directory with all builtin commands */ -int builtin_echo(char **argv); -int builtin_cd(t_env env, char **argv); -int builtin_pwd(void); -int builtin_export(t_env env, char **argv); -int builtin_unset(t_env env, char **argv); -int builtin_env(t_env env); -int builtin_exit(void); +/** +** \brief Type of a builtin main function +*/ + +typedef int (*t_builtin_func)(char **argv, t_env env); + +/** +** \brief Entry of builtin lookup array +** \param name Executable name of builtin +** \param func Associated function +*/ + +struct s_builtin_entry +{ + char *name; + t_builtin_func func; +}; + +int builtin_dispatch_run(char **argv, t_env env); +bool builtin_check_exec_name(char *exec_name); +int builtin_echo(char **argv, t_env env); +int builtin_cd(char **argv, t_env env); +int builtin_pwd(char **argv, t_env env); +int builtin_export(char **argv, t_env env); +int builtin_unset(char **argv, t_env env); +int builtin_env(char **argv, t_env env); +int builtin_exit(char **argv, t_env env); /* ** util.c - various utilitary functions |
