From 1ad56ece41e7f16974c83fde9df8a817d8a677c4 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Fri, 17 Mar 2017 00:22:47 +0100 Subject: [PATCH] master steady, merged end --- 42sh/Makefile | 1 - 42sh/includes/minishell.h | 30 +++--- 42sh/src/builtin/builtin_math.c | 158 +++++++++++++++---------------- 42sh/src/main/instruction_free.c | 26 ----- 4 files changed, 95 insertions(+), 120 deletions(-) delete mode 100644 42sh/src/main/instruction_free.c diff --git a/42sh/Makefile b/42sh/Makefile index 6a620772..8ac4b6c4 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -267,7 +267,6 @@ main/data_init.c\ main/data_singleton.c\ main/error_msg.c\ main/ft_putast.c\ -main/instruction_free.c\ main/main.c\ main/shell_init.c\ parser/add_bang.c\ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index a144b2e4..eaeb4c37 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/16 23:01:59 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 00:20:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,17 +40,21 @@ struct s_data { - t_flag opts; - char **env; - int argc; - char **argv; - t_line line; - t_comp *comp; - t_exec exec; - t_jobc jobc; - t_list *heredoc_queue; - char **local_var; - t_list *lst_func; + t_flag opts; + char **env; + int argc; + char **argv; + t_line line; + t_list *token; + t_btree *ast; + t_lexer lexer; + t_parser parser; + t_comp *comp; + t_exec exec; + t_jobc jobc; + t_list *heredoc_queue; + char **local_var; + t_list *lst_func; }; int shell_init(int ac, char **av); @@ -58,8 +62,6 @@ void shell_exit(void); int data_init(int ac, char **av); void data_exit(void); -int instruction_free(t_list **token, t_parser *parser, - t_btree **ast); void content_free(void *data, size_t content_size); char *ft_putast(void *node); diff --git a/42sh/src/builtin/builtin_math.c b/42sh/src/builtin/builtin_math.c index 5f9804a9..f8eeda67 100644 --- a/42sh/src/builtin/builtin_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -6,92 +6,92 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 10:58:49 by ariard #+# #+# */ -/* Updated: 2017/03/17 00:02:12 by ariard ### ########.fr */ +/* Updated: 2017/03/16 16:40:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "minishell.h" +/* #include "minishell.h" */ -static int init_math(char **var, char **value, char **operator, char **operand) -{ - *var = NULL; - *value = NULL; - *operator = NULL; - *operand = NULL; - return (0); -} +/* static int init_math(char **var, char **value, char **operator, char **operand) */ +/* { */ +/* *var = NULL; */ +/* *value = NULL; */ +/* *operator = NULL; */ +/* *operand = NULL; */ +/* return (0); */ +/* } */ -static int get_value(char **var, char **value) -{ - char *temp; +/* static int get_value(char **var, char **value) */ +/* { */ +/* char *temp; */ - if (!word_is_assignment(var)) - return (error_msg(MATHERR_1)); - temp = ft_sstrstr(data_singleton()->local_var, *var); - if (temp) - { - temp += ft_strlenchr(temp, '=') + 1; - *value = ft_strdup(temp); - if (!(ft_stris(*value, &ft_isdigit))) - { - ft_strdel(value); - *value = ft_itoa(0); - } - } - else - *value = ft_itoa(0); - return (0); -} +/* if (!word_is_assignment(var)) */ +/* return (error_msg(MATHERR_1)); */ +/* temp = ft_sstrstr(data_singleton()->local_var, *var); */ +/* if (temp) */ +/* { */ +/* temp += ft_strlenchr(temp, '=') + 1; */ +/* *value = ft_strdup(temp); */ +/* if (!(ft_stris(*value, &ft_isdigit))) */ +/* { */ +/* ft_strdel(value); */ +/* *value = ft_itoa(0); */ +/* } */ +/* } */ +/* else */ +/* *value = ft_itoa(0); */ +/* return (0); */ +/* } */ -static int do_math(char **value, char *operator, char *operand) -{ - long ope1; - long ope2; +/* static int do_math(char **value, char *operator, char *operand) */ +/* { */ +/* long ope1; */ +/* long ope2; */ - ope1 = ft_atoi(*value); - if (operand) - ope2 = ft_atoi(operand); - else - ope2 = 0; - if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) - return (error_msg(MATHERR_4)); - else - { - ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; - ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1; - ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1; - ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1; - ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1; - } - ft_strdel(value); - *value = ft_itoa(ope1); - return (0); -} +/* ope1 = ft_atoi(*value); */ +/* if (operand) */ +/* ope2 = ft_atoi(operand); */ +/* else */ +/* ope2 = 0; */ +/* if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) */ +/* return (error_msg(MATHERR_4)); */ +/* else */ +/* { */ +/* ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; */ +/* ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1; */ +/* ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1; */ +/* ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1; */ +/* ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1; */ +/* } */ +/* ft_strdel(value); */ +/* *value = ft_itoa(ope1); */ +/* return (0); */ +/* } */ -int builtin_math(const char *path, char *const av[], char *const envp[]) -{ - char *var; - char *value; - char *operator; - char *operand; +/* int builtin_math(const char *path, char *const av[], char *const envp[]) */ +/* { */ +/* char *var; */ +/* char *value; */ +/* char *operator; */ +/* char *operand; */ - (void)path; - (void)envp; - if (!av || !av[1] || !av[2] || !av[3] || av[4]) - return (error_msg(MATHERR_0)); - init_math(&var, &value, &operator, &operand); - var = av[1]; - if (get_value(&var, &value) == -1) - return (-1); - operator = av[2]; - if (!(ft_strlen(operator) == 1 && (operator[0] == '+' || operator[0] == '-' - || operator[0] == '/' || operator[0] == '*' || operator[0] == '%'))) - return (error_msg(MATHERR_2)); - operand = av[3]; - if (!ft_stris(operand, &ft_isdigit)) - return (error_msg(MATHERR_3)); - if (do_math(&value, operator, operand) == -1) - return (-1); - builtin_setenv("setenv", (char *[]){"local", var, value, 0}, data_singleton()->local_var); - return (0); -} +/* (void)path; */ +/* (void)envp; */ +/* if (!av || !av[1] || !av[2] || !av[3] || av[4]) */ +/* return (error_msg(MATHERR_0)); */ +/* init_math(&var, &value, &operator, &operand); */ +/* var = av[1]; */ +/* if (get_value(&var, &value) == -1) */ +/* return (-1); */ +/* operator = av[2]; */ +/* if (!(ft_strlen(operator) == 1 && (operator[0] == '+' || operator[0] == '-' */ +/* || operator[0] == '/' || operator[0] == '*' || operator[0] == '%'))) */ +/* return (error_msg(MATHERR_2)); */ +/* operand = av[3]; */ +/* if (!ft_stris(operand, &ft_isdigit)) */ +/* return (error_msg(MATHERR_3)); */ +/* if (do_math(&value, operator, operand) == -1) */ +/* return (-1); */ +/* builtin_setenv("setenv", (char *[]){"local", var, value, 0}, data_singleton()->local_var); */ +/* return (0); */ +/* } */ diff --git a/42sh/src/main/instruction_free.c b/42sh/src/main/instruction_free.c deleted file mode 100644 index 4b644120..00000000 --- a/42sh/src/main/instruction_free.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* instruction_free.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/15 15:54:59 by gwojda #+# #+# */ -/* Updated: 2017/03/16 18:27:57 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int instruction_free(t_list **token, t_btree **ast, t_lexer *lexer, t_parser *parser) -{ - ft_lstdel(token, &token_free); - token = NULL; - ft_lstdel(&parser->stack, &ft_lst_cfree); - btree_del(ast, &ft_lst_cfree); - ft_lstdel(&data_singleton()->parser.heredoc_queue, &redir_free); - ft_lstdel(&data_singleton()->exec.op_stack, &ft_lst_cfree); - ft_strdel(&lexer->str); - free(parser->new_sym); - return (0); -}