From b15ab562d74b5111ac7c9bd6e0ec185435902472 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 31 Mar 2020 21:41:33 +0200 Subject: Removing ms_ prefix, Removing junk --- include/eval.h | 44 +++++++++++++++++++++++++ include/minishell.h | 25 +++++++------- include/ms_eval.h | 43 ------------------------ include/ms_parse.h | 92 ---------------------------------------------------- include/parse.h | 48 +++++++++++++++++++++++++++ src/builtin/cd.c | 2 +- src/builtin/echo.c | 2 +- src/builtin/env.c | 2 +- src/builtin/export.c | 2 +- src/builtin/pwd.c | 3 +- src/builtin/unset.c | 4 +-- src/env.c | 6 ++-- src/eval/eval.c | 12 +++---- src/main.c | 18 +++++----- src/parse/ast.c | 63 ----------------------------------- src/parse/lexer.c | 2 +- src/parse/parse.c | 6 ++-- src/path.c | 4 +-- src/utils.c | 2 +- 19 files changed, 136 insertions(+), 244 deletions(-) create mode 100644 include/eval.h delete mode 100644 include/ms_eval.h delete mode 100644 include/ms_parse.h create mode 100644 include/parse.h delete mode 100644 src/parse/ast.c diff --git a/include/eval.h b/include/eval.h new file mode 100644 index 0000000..ec04ff5 --- /dev/null +++ b/include/eval.h @@ -0,0 +1,44 @@ +#ifndef MS_EVAL_H +# define MS_EVAL_H + +/** +** \file eval.h +** \brief Evaluation module +*/ + +# include "minishell.h" +# include "ast.h" + +/** +** \brief Evaluation state struct +*/ + +typedef struct +{ + int status; + int in_pipe[2]; // need stack pipe + int out_pipe[2]; + t_path path; + t_env env; +} t_eval_state; + +/** +** \brief Evaluation status struct +*/ + +typedef struct +{ + char *err; + int status; +} t_eval_status; + + +/** +** \brief Evaluate an AST +** \param state State of the evaluation +** \param ast Abstract syntax tree to evaluate +*/ + +int eval(t_eval_state *state, t_ast *ast); + +#endif diff --git a/include/minishell.h b/include/minishell.h index 6a00ca8..4f33951 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -34,9 +34,6 @@ # include "libft_lst.h" # include "libft_util.h" -# include "ms_parse.h" -// # include "ms_eval.h" - /** ** \brief Value of pipe entry if closed */ @@ -62,31 +59,31 @@ typedef t_ftht* t_env; ** path.c */ -t_path ms_path_update(t_path path, char *path_var); +t_path path_update(t_path path, char *path_var); /* ** env.c */ -t_env ms_env_from_array(char **envp); -char **ms_env_to_array(t_env env); +t_env env_from_array(char **envp); +char **env_to_array(t_env env); /* ** builtin*.c - directory with all builtin commands */ -int ms_echo(char **argv); -int ms_cd(t_env env, char **argv); -int ms_pwd(void); -int ms_export(t_env env, char **argv); -int ms_unset(t_env env, char **argv); -int ms_env(t_env env); -int ms_exit(void); +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); /* ** util.c - various utilitary functions */ -void ms_ht_del_str_entry(t_ftht_entry *entry); +void ht_del_str_entry(t_ftht_entry *entry); #endif diff --git a/include/ms_eval.h b/include/ms_eval.h deleted file mode 100644 index b53b845..0000000 --- a/include/ms_eval.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef MS_EVAL_H -# define MS_EVAL_H - -/** -** \file ms_eval.h -** \brief Evaluation module -*/ - -# include "minishell.h" - -/** -** \brief Evaluation state struct -*/ - -typedef struct -{ - int status; - int in_pipe[2]; // need stack pipe - int out_pipe[2]; - t_path path; - t_env env; -} t_eval_state; - -/** -** \brief Evaluation status struct -*/ - -typedef struct -{ - char *err; - int status; -} t_eval_status; - - -/** -** \brief Evaluate an AST -** \param state State of the evaluation -** \param ast Abstract syntax tree to evaluate -*/ - -int ms_eval(t_eval_state *state, t_ast *ast); - -#endif diff --git a/include/ms_parse.h b/include/ms_parse.h deleted file mode 100644 index 0a33ccf..0000000 --- a/include/ms_parse.h +++ /dev/null @@ -1,92 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ms_parse.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */ -/* Updated: 2020/02/28 14:57:58 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MS_PARSE_H -# define MS_PARSE_H - -# include "minishell.h" -# include "ast.h" - -/** -** \file ms_parse.h -** \brief Input parsing and AST manipulation -** -** Context free grammar: -** ``` -** redir_in ::= '<' -** redir_out ::= '>' -** redir_append ::= '>>' -** string ::= '\'' .+ '\'' | '"' .+ '"' | [^ ]+ -** sep ::= '&&' | '||' | '|' | ';' -** expr ::= | | | -** cmd ::= + -** line ::= | -** ``` -*/ - -/** -** \brief AST node tag -** \param TAG_STRING string -** \param TAG_SEP `;` | `|` | `&&` | `||` -** \param TAG_REDIR_OUT `>` -** \param TAG_REDIR_IN `<` -** \param TAG_REDIR_APPEND `>>` -*/ - -// typedef enum -// { -// TAG_STRING, -// TAG_SEP, -// TAG_REDIR_OUT, -// TAG_REDIR_IN, -// TAG_REDIR_APPEND, -// TAG_CMD, -// TAG_LINE, -// } t_ast_tag; - -/** -** \brief AST (Abstract Syntax Tree) -** \param tag tag (type) of node -** \param content substring of the parsed string which corespond to tag -** \param children_num number of children -** \param children children nodes -*/ - -// typedef struct s_ast -// { -// t_tag tag; -// char* content; -// int children_num; -// struct s_ast** children; -// } t_ast; - -/* -** lexer.c -*/ - -char **ms_lexer(char *input); - -/* -** parse.c -*/ - -t_ast *ms_parse(char *input); - -/* -** ast.c -*/ - -// t_ast *ms_ast_new(t_tag tag); -// void ms_ast_destroy(t_ast *ast); -// void ms_ast_iter(t_ast *ast, void (*f)(void *f_arg, t_ast *children), void *arg); - -#endif diff --git a/include/parse.h b/include/parse.h new file mode 100644 index 0000000..c9710d7 --- /dev/null +++ b/include/parse.h @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */ +/* Updated: 2020/02/28 14:57:58 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MS_PARSE_H +# define MS_PARSE_H + +# include "minishell.h" +# include "ast.h" + +/** +** \file parse.h +** \brief Input parsing and AST manipulation +** +** Context free grammar: +** ``` +** redir_in ::= '<' +** redir_out ::= '>' +** redir_append ::= '>>' +** string ::= '\'' .+ '\'' | '"' .+ '"' | [^ ]+ +** sep ::= '&&' | '||' | '|' | ';' +** expr ::= | | | +** cmd ::= + +** line ::= | +** ``` +*/ + +/* +** lexer.c +*/ + +char **lexer(char *input); + +/* +** parse.c +*/ + +t_ast *parse(char *input); + +#endif diff --git a/src/builtin/cd.c b/src/builtin/cd.c index fe806ec..14c38d2 100644 --- a/src/builtin/cd.c +++ b/src/builtin/cd.c @@ -5,7 +5,7 @@ #include "minishell.h" -int ms_cd(t_env env, char **argv) +int builtin_cd(t_env env, char **argv) { char *path; diff --git a/src/builtin/echo.c b/src/builtin/echo.c index 817da28..b9f2e28 100644 --- a/src/builtin/echo.c +++ b/src/builtin/echo.c @@ -5,7 +5,7 @@ #include "minishell.h" -int ms_echo(char **argv) +int builtin_echo(char **argv) { bool newline; diff --git a/src/builtin/env.c b/src/builtin/env.c index 4855917..3869ead 100644 --- a/src/builtin/env.c +++ b/src/builtin/env.c @@ -13,7 +13,7 @@ void st_print_env_variable(t_ftht_entry *entry) ft_putchar('\n'); } -int ms_env(t_env env) +int builtin_env(t_env env) { ft_htiter(env, st_print_env_variable); return (0); diff --git a/src/builtin/export.c b/src/builtin/export.c index 77d46c1..c0839b9 100644 --- a/src/builtin/export.c +++ b/src/builtin/export.c @@ -5,7 +5,7 @@ #include "minishell.h" -/* int ms_export(t_env env, char **argv) */ +/* int export(t_env env, char **argv) */ /* { */ /* return (0); */ /* } */ diff --git a/src/builtin/pwd.c b/src/builtin/pwd.c index 326f834..813c4c6 100644 --- a/src/builtin/pwd.c +++ b/src/builtin/pwd.c @@ -2,9 +2,10 @@ ** \file pwd.c ** \brief `pwd` builtin */ + #include "minishell.h" -int ms_pwd(void) +int builtin_pwd(void) { char buf[PATH_MAX]; diff --git a/src/builtin/unset.c b/src/builtin/unset.c index 4d7c628..64f25f4 100644 --- a/src/builtin/unset.c +++ b/src/builtin/unset.c @@ -5,10 +5,10 @@ #include "minishell.h" -int ms_unset(t_env env, char **argv) +int builtin_unset(t_env env, char **argv) { if (argv[1] == NULL) return (1); - ft_htdelone(env, argv[1], ms_ht_del_str_entry); + ft_htdelone(env, argv[1], ht_del_str_entry); return (0); } diff --git a/src/env.c b/src/env.c index c019cb4..00fbaaf 100644 --- a/src/env.c +++ b/src/env.c @@ -29,7 +29,7 @@ ** \return Environment hash table or NULL on error */ -t_env ms_env_from_array(char **envp) +t_env env_from_array(char **envp) { t_env env; int i; @@ -50,7 +50,7 @@ t_env ms_env_from_array(char **envp) return (NULL); if ((value = ft_strdup(value + 1)) == NULL) return (NULL); - if (ft_htset(env, key, value, ms_ht_del_str_entry) == NULL) + if (ft_htset(env, key, value, ht_del_str_entry) == NULL) return (NULL); free(key); } @@ -63,7 +63,7 @@ t_env ms_env_from_array(char **envp) ** \return Array of string on NULL on error */ -char **ms_env_to_array(t_env env) +char **env_to_array(t_env env) { (void)env; // need ft_htlen diff --git a/src/eval/eval.c b/src/eval/eval.c index a5e2c71..d40c7f3 100644 --- a/src/eval/eval.c +++ b/src/eval/eval.c @@ -3,19 +3,19 @@ ** \brief Evaluation of an AST */ -#include "ms_eval.h" +#include "eval.h" static int eval_line(t_eval_state *state, t_line *line) { int status; if (line->right == NULL) - return (ms_eval(state, line->left)); - status = ms_eval(state, line->left); + return (eval(state, line->left)); + status = eval(state, line->left); if ((line->sep == SEP_AND && status != 0) || (line->sep == SEP_OR && status == 0)) return (status); - return (ms_eval(state, line->right)); + return (eval(state, line->right)); } static char *search_exec_path(t_path path, char *path_var, char *exec_name) @@ -25,7 +25,7 @@ static char *search_exec_path(t_path path, char *path_var, char *exec_name) // try current first if ((exec_path = ft_htget(path, exec_name)) == NULL) { - if (ms_path_update(path, path_var) == NULL) + if (path_update(path, path_var) == NULL) return (NULL); if ((exec_path = ft_htget(path, exec_name)) == NULL) return (NULL); @@ -67,7 +67,7 @@ static int eval_cmd(t_eval_state *state, t_cmd *cmd) return (WEXITSTATUS(child_pid)); } -int ms_eval(t_eval_state *state, t_ast *ast) +int eval(t_eval_state *state, t_ast *ast) { if (ast->tag == TAG_LINE) return eval_line(state, &ast->data.line); diff --git a/src/main.c b/src/main.c index b8a74f7..e1005d8 100644 --- a/src/main.c +++ b/src/main.c @@ -34,23 +34,23 @@ int main(int argc, char **argv, const char **envp) (void)argc; (void)argv; - env = ms_env_from_array((char**)envp); - path = ms_path_update(NULL, ft_htget(env, "PATH")); + env = env_from_array((char**)envp); + path = path_update(NULL, ft_htget(env, "PATH")); printf("%s\n", (char*)ft_htget(path, "nmap")); - /* ms_env(env); */ - /* ms_pwd(&state); */ - /* ms_cd(&state, NULL); */ - /* ms_pwd(&state); */ + /* env(env); */ + /* pwd(&state); */ + /* cd(&state, NULL); */ + /* pwd(&state); */ /* while ((ret = ft_next_line(STDIN_FILENO, &line)) == 1) */ /* { */ - /* if (ms_eval(ms_parse(line)) == -1) */ + /* if (eval(parse(line)) == -1) */ /* continue ; // and display error */ /* free(line); */ /* } */ /* free(line); */ - ft_htdestroy(path, ms_ht_del_str_entry); - ft_htdestroy(env, ms_ht_del_str_entry); + ft_htdestroy(path, ht_del_str_entry); + ft_htdestroy(env, ht_del_str_entry); return (0); } diff --git a/src/parse/ast.c b/src/parse/ast.c deleted file mode 100644 index 44a36cd..0000000 --- a/src/parse/ast.c +++ /dev/null @@ -1,63 +0,0 @@ -/** -** \file ast.c -** \brief AST manipulation -*/ - -#include "ms_parse.h" - -/** -** \brief Create a new AST node with default values -** \param tag Tag of the node -** \return The allocated node -*/ - -/* t_ast *ms_ast_new(t_ast_tag tag) */ -/* { */ -/* t_ast *ast; */ -/* */ -/* if ((ast = (t_ast*)malloc(sizeof(t_ast))) == NULL) */ -/* return (NULL); */ -/* ast->tag = tag; */ -/* ast->content = NULL; */ -/* ast->children_num = 0; */ -/* ast->children = NULL; */ -/* return (ast); */ -/* } */ - -/** -** \brief Destroy an allocated AST -** \warning Assumes that `content`, `children` and the node itself have been malloc'd -** \param ast AST to destroy -*/ - -/* void ms_ast_destroy(t_ast *ast) */ -/* { */ -/* int i; */ -/* */ -/* if (ast == NULL) */ -/* return ; */ -/* i = -1; */ -/* while (++i < ast->children_num) */ -/* ms_ast_destroy(ast->children[i]); */ -/* free(ast->children); */ -/* free(ast->content); */ -/* free(ast); */ -/* } */ - -/** -** \brief Iterate over an AST node's childs -** \param f Function applied to each child, take `arg` has his first argument. -** \param arg Pointer that will be passed to `f`, to keep information between iterations -*/ - -/* void ms_ast_iter( */ -/* t_ast *ast, */ -/* void (*f)(void *f_arg, t_ast *children), */ -/* void *arg) */ -/* { */ -/* int i; */ -/* */ -/* i = -1; */ -/* while (++i < ast->children_num) */ -/* f(arg, ast->children[i]); */ -/* } */ diff --git a/src/parse/lexer.c b/src/parse/lexer.c index d8f1254..57ecdf7 100644 --- a/src/parse/lexer.c +++ b/src/parse/lexer.c @@ -5,7 +5,7 @@ #include "minishell.h" -char **ms_lexer(char *input) +char **lexer(char *input) { char **out_lex; diff --git a/src/parse/parse.c b/src/parse/parse.c index 41b82c2..c99f0fe 100644 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -3,12 +3,12 @@ ** \brief Parser */ -#include "minishell.h" +#include "parse.h" -t_ast *ms_parse(char *input) +t_ast *parse(char *input) { /* char **out_lex; */ -/* if (!(out_lex = ms_lexer(input))) */ +/* if (!(out_lex = lexer(input))) */ /* return (NULL); */ (void)input; diff --git a/src/path.c b/src/path.c index c2b6582..db9d8bd 100644 --- a/src/path.c +++ b/src/path.c @@ -42,7 +42,7 @@ static t_path st_path_dir_update(t_path path, char *dirname) { if ((tmp = ft_strjoin3(dirname, "/", entry->d_name)) == NULL) return (NULL); - if (ft_htset(path, entry->d_name, tmp, ms_ht_del_str_entry) == NULL) + if (ft_htset(path, entry->d_name, tmp, ht_del_str_entry) == NULL) return (NULL); } if (closedir(dir) == -1) @@ -57,7 +57,7 @@ static t_path st_path_dir_update(t_path path, char *dirname) ** \return The updated/created path hash table or NULL on error */ -t_path ms_path_update(t_path path, char *path_var) +t_path path_update(t_path path, char *path_var) { int i; char **dirs; diff --git a/src/utils.c b/src/utils.c index 815e8e3..5989d71 100644 --- a/src/utils.c +++ b/src/utils.c @@ -23,7 +23,7 @@ ** */ -void ms_ht_del_str_entry(t_ftht_entry *entry) +void ht_del_str_entry(t_ftht_entry *entry) { if (entry == NULL) return ; -- cgit