diff --git a/42sh/Makefile b/42sh/Makefile index 5e78833d..4f3a2381 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -36,6 +36,7 @@ builtin/builtin_echo.c\ builtin/builtin_env.c\ builtin/builtin_exit.c\ builtin/builtin_export.c\ +builtin/builtin_func.c\ builtin/builtin_hash.c\ builtin/builtin_history.c\ builtin/builtin_math.c\ diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index 96fb1253..289c7b09 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:28:02 by ariard ### ########.fr */ +/* Updated: 2017/03/24 15:13:06 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,6 +49,7 @@ int builtin_bg(const char *path, char *const av[], char *const envp[]); int builtin_history(const char *path, char *const av[], char *const envp[]); int builtin_hash(const char *path, char *const av[], char *const envp[]); int builtin_math(const char *path, char *const av[], char *const envp[]); +int builtin_func(const char *path, char *const av[], char *const envp[]); int bt_env_geti(char ***av, t_env_data *data); int error_msg(char *msg); diff --git a/42sh/src/builtin/builtin_func.c b/42sh/src/builtin/builtin_func.c new file mode 100644 index 00000000..efbe3cc8 --- /dev/null +++ b/42sh/src/builtin/builtin_func.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtin_func.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/24 15:03:02 by wescande #+# #+# */ +/* Updated: 2017/03/24 15:30:13 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +#define FUNC_USAGE "func" + +int builtin_func(const char *path, + char *const argv[], char *const envp[]) +{ + t_list *list; + char **name; + t_btree **ast; + + (void)envp; + (void)path; + if (!argv || !argv[0] || argv[1]) + return (SH_ERR("usage: %s", FUNC_USAGE) ? 1 : 1); + list = data_singleton()->lst_func; + DG(); + int toto = 0; + while (list) + { + DG(">>>>>>>%d", toto++); + if (!(ast = list->content)) + return (SH_ERR("unexpected error")); + name = token_to_argv(((t_astnode *)(*ast)->item)->data.cmd.token, 1); + if (name && name[0]) + { + DG(); + ft_putendl(name[0]); + } + ft_tabdel(&name); + list = list->next; + } + return (0); +} diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 90a08144..dd931eba 100644 --- a/42sh/src/builtin/is_builtin.c +++ b/42sh/src/builtin/is_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ -/* Updated: 2017/03/21 16:24:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:12:42 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,7 @@ t_stof g_builtin[] = {"hash", &builtin_hash}, {"history", &builtin_history}, {"math", &builtin_math}, + {"func", &builtin_func}, {NULL, NULL}, }; diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index e0f79a5f..f305fbf1 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ -/* Updated: 2017/03/24 12:40:41 by wescande ### ########.fr */ +/* Updated: 2017/03/24 15:48:41 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,12 +17,14 @@ void data_exit(void) t_data *data; data = data_singleton(); + ft_strdel(&data->binary); ft_sstrfree(data->env); ft_sstrfree(data->local_var); ft_sstrfree(data->argv); lexer_destroy(&data->lexer); parser_destroy(&data->parser); ft_lstdel(&data->jobc.first_job, &job_free); + ft_lstdel(&data->lst_func, &tree_func_free); ft_save_termios(-1); ft_free_hash_table(); free_history_list(data_singleton()->line.list_beg);