ajout free des func + ajout builtin func

This commit is contained in:
wescande 2017-03-24 15:54:09 +01:00
parent af2fd99dd0
commit 26bddc8a58
5 changed files with 54 additions and 3 deletions

View file

@ -36,6 +36,7 @@ builtin/builtin_echo.c\
builtin/builtin_env.c\ builtin/builtin_env.c\
builtin/builtin_exit.c\ builtin/builtin_exit.c\
builtin/builtin_export.c\ builtin/builtin_export.c\
builtin/builtin_func.c\
builtin/builtin_hash.c\ builtin/builtin_hash.c\
builtin/builtin_history.c\ builtin/builtin_history.c\
builtin/builtin_math.c\ builtin/builtin_math.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 22:59:57 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_history(const char *path, char *const av[], char *const envp[]);
int builtin_hash(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_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 bt_env_geti(char ***av, t_env_data *data);
int error_msg(char *msg); int error_msg(char *msg);

View file

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin_func.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:09:57 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}, {"hash", &builtin_hash},
{"history", &builtin_history}, {"history", &builtin_history},
{"math", &builtin_math}, {"math", &builtin_math},
{"func", &builtin_func},
{NULL, NULL}, {NULL, NULL},
}; };

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/07 18:07:50 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; t_data *data;
data = data_singleton(); data = data_singleton();
ft_strdel(&data->binary);
ft_sstrfree(data->env); ft_sstrfree(data->env);
ft_sstrfree(data->local_var); ft_sstrfree(data->local_var);
ft_sstrfree(data->argv); ft_sstrfree(data->argv);
lexer_destroy(&data->lexer); lexer_destroy(&data->lexer);
parser_destroy(&data->parser); parser_destroy(&data->parser);
ft_lstdel(&data->jobc.first_job, &job_free); ft_lstdel(&data->jobc.first_job, &job_free);
ft_lstdel(&data->lst_func, &tree_func_free);
ft_save_termios(-1); ft_save_termios(-1);
ft_free_hash_table(); ft_free_hash_table();
free_history_list(data_singleton()->line.list_beg); free_history_list(data_singleton()->line.list_beg);