diff --git a/42sh/Makefile b/42sh/Makefile index 5961a2e6..2a885d45 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/14 12:34:49 by gwojda ### ########.fr # +# Updated: 2017/03/14 21:59:22 by ariard ### ########.fr # # # # **************************************************************************** # @@ -39,6 +39,7 @@ builtin/builtin_exit.c\ builtin/builtin_export.c\ builtin/builtin_hash.c\ builtin/builtin_history.c\ +builtin/builtin_math.c\ builtin/builtin_read.c\ builtin/builtin_setenv.c\ builtin/builtin_unset.c\ @@ -72,7 +73,6 @@ exec/exec_case_branch.c\ exec/exec_elif.c\ exec/exec_else.c\ exec/exec_leaf.c\ -exec/exec_math.c\ exec/exec_or_if.c\ exec/exec_pipe.c\ exec/exec_reset.c\ @@ -277,7 +277,6 @@ parser/add_cmd.c\ parser/add_condition.c\ parser/add_func.c\ parser/add_loop.c\ -parser/add_math.c\ parser/add_number.c\ parser/add_redir.c\ parser/add_sep.c\ diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index 69999869..faa35a15 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -3,9 +3,10 @@ /* ::: :::::::: */ /* builtin.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */ +/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */ +/* Updated: 2017/03/15 00:48:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,5 +33,6 @@ int builtin_fg(const char *path, char *const av[], char *const envp[]); 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[]); #endif diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 576a1c3f..d9f8261e 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/14 21:17:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:07:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,7 +62,7 @@ struct s_data_cond struct s_data_list { - t_ld *list_word; + t_ld *token; t_btree *content; }; diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 3e766562..2f07a512 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -104,7 +104,6 @@ int add_cmd(t_btree **ast, t_list **lst); int add_file(t_btree **ast, t_list **lst); int add_loop_cmd(t_btree **ast, t_list **lst); int add_loop_sep(t_btree **ast, t_list **lst); -int add_loop_condition(t_btree **ast, t_list **lst); int add_condition_cmd(t_btree **ast, t_list **lst); int add_condition_sep(t_btree **ast, t_list **lst); int add_branch(t_btree **ast, t_list **lst); @@ -127,7 +126,6 @@ int add_bang_sep(t_btree **ast, t_list **lst); int add_if(t_btree **ast, t_list **lst); int isloop(t_btree **ast, t_list **lst); -int isloop_condition(t_btree **ast, t_list **lst); int iscase(t_btree **ast, t_list **lst); int iscase_pattern(t_btree **ast, t_list **lst); int iscase_branch(t_btree **ast, t_list **lst); @@ -142,8 +140,6 @@ int isdir_sep(t_btree **ast, t_list **list); int isdir_word(t_btree **ast, t_list **list); int isnull(t_btree **ast, t_list **list); int isionumber(t_btree **ast, t_list **lst); -int ismath(t_btree **ast, t_list **lst); -int ismath_expr(t_btree **ast, t_list **lst); int isbang(t_btree **ast, t_list **lst); int isbang_sep(t_btree **ast, t_list **lst); @@ -171,7 +167,6 @@ struct s_cmd { t_list *redir; t_ld *token; - t_ld *wordlist; }; union u_astdata diff --git a/42sh/includes/types.h b/42sh/includes/types.h index e35c78d9..9098de75 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,8 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/14 20:25:53 by jhalford ### ########.fr */ -/* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 22:53:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -198,9 +197,6 @@ enum e_sym OPEN_FUNC, CLOSE_FUNC, CLOSE_LIST, - MATH, - MATH_PLUS, - MATH_SUP, REDIR, CMD, HEREDOCDATA, diff --git a/42sh/src/exec/exec_math.c b/42sh/src/builtin/builtin_math.c similarity index 70% rename from 42sh/src/exec/exec_math.c rename to 42sh/src/builtin/builtin_math.c index fab21747..3bcbd1ea 100644 --- a/42sh/src/exec/exec_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -6,17 +6,25 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 10:58:49 by ariard #+# #+# */ -/* Updated: 2017/03/14 00:55:04 by ariard ### ########.fr */ +/* Updated: 2017/03/14 22:45:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int get_math(char *stream, char **var, char **value, char **operator) +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; - *var = ft_strduptr(stream, &ft_isalpha); temp = ft_sstrstr(data_singleton()->local_var, *var); if (temp) { @@ -30,21 +38,21 @@ static int get_math(char *stream, char **var, char **value, char **operator) } else *value = ft_itoa(0); - stream += ft_strlen(*var); - *operator = ft_strdup(stream); return (0); } -static int do_math(char **value, char *operator) +static int do_math(char **value, char *operator, char *operand) { long ope1; long ope2; ope1 = ft_atoi(*value); - if (operator[2]) - ope2 = ft_atoi(&operator[2]); + if (operand) + ope2 = ft_atoi(operand); else ope2 = 0; + if (ft_strlen(operator) > 1) + return (0); if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) ope1 = 0; else @@ -60,22 +68,22 @@ static int do_math(char **value, char *operator) return (0); } -int exec_math(t_btree **ast) +int builtin_math(const char *path, char *const av[], char *const envp[]) { - t_astnode *node; - char **av; char *var; char *value; char *operator; + char *operand; - node = (*ast)->item; - av = token_to_argv(node->data.cmd.wordlist, 1); - DG("before get math : %s", av[0]); - get_math(av[0], &var, &value, &operator); - DG("before do math var %s value %s operator %s", var, value, operator); - do_math(&value, operator); - DG("before setenv %s", value); + (void)path; + (void)envp; + init_math(&var, &value, &operator, &operand); + var = av[1]; + get_value(&var, &value); + operator = av[2]; + operand = av[3]; +// DG("math %s %s %s", var, operator, operand); + do_math(&value, operator, operand); builtin_setenv("setenv", (char *[]){"local", var, value, 0}, data_singleton()->local_var); - DG("after setenv"); return (0); } diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index eb2024e1..a1cc7dc9 100644 --- a/42sh/src/builtin/builtin_setenv.c +++ b/42sh/src/builtin/builtin_setenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/03/14 21:40:07 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 02:12:56 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,7 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[]) } else { - str = ft_str3join(av[0], "=", av[1]); + str = ft_str3join(av[0], "=", av[2]); while ((*env) && (*env)[i]) { if (ft_strcmp((*env)[i], av[0]) == '=') diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 9cdb3d4b..4bc3a2c3 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/13 22:52:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 22:32:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,7 @@ t_stof g_builtin[] = {"read", &builtin_read}, {"hash", &builtin_hash}, {"history", &builtin_history}, + {"math", &builtin_math}, {NULL, NULL}, }; diff --git a/42sh/src/exec/exec_case_branch.c b/42sh/src/exec/exec_case_branch.c index 76596970..9335cdaa 100644 --- a/42sh/src/exec/exec_case_branch.c +++ b/42sh/src/exec/exec_case_branch.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:33:45 by wescande #+# #+# */ -/* Updated: 2017/03/07 20:34:48 by wescande ### ########.fr */ +/* Updated: 2017/03/15 01:21:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,23 +17,20 @@ int exec_case_branch(t_btree **ast) t_astnode *node; char **av; t_exec *exec; - int i; + DG("exec branch case"); exec = &data_singleton()->exec; if (EXEC_IS_CASE_BRANCH(exec->attrs)) return (0); node = (*ast)->item; - av = token_to_argv(node->data.cmd.wordlist, 1); - i = 0; - while (av[i]) - { - if (ft_strcmp(av[i], ((char **)exec->case_pattern)[0]) == 0) - { - exec->attrs |= EXEC_CASE_BRANCH; - ft_exec(&(*ast)->right); - break ; - } - i++; + av = token_to_argv(node->data.cmd.token, 1); + DG("compare pattern %s ", av[0]); + DG("and case %s", ((char **)exec->case_pattern)[0]); + DG(); + if (ft_strcmp(av[0], ((char **)exec->case_pattern)[0]) == 0) + { + exec->attrs |= EXEC_CASE_BRANCH; + ft_exec(&(*ast)->right); } return (0); } diff --git a/42sh/src/exec/exec_elif.c b/42sh/src/exec/exec_elif.c index c4a5fa4a..f3742225 100644 --- a/42sh/src/exec/exec_elif.c +++ b/42sh/src/exec/exec_elif.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:08:53 by ariard #+# #+# */ -/* Updated: 2017/03/04 17:45:29 by ariard ### ########.fr */ +/* Updated: 2017/03/15 02:04:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 1404e6a9..e26f54d4 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -1,4 +1,4 @@ -/* ************************************************************************** */ +/*ss ************************************************************************** */ /* */ /* ::: :::::::: */ /* exec_leaf.c :+: :+: :+: */ @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/14 20:26:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 02:04:30 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_var.c b/42sh/src/exec/exec_var.c index 194309ae..9b1136c2 100644 --- a/42sh/src/exec/exec_var.c +++ b/42sh/src/exec/exec_var.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ -/* Updated: 2017/03/14 21:09:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 23:55:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,8 @@ int exec_var(t_btree **ast) node = (*ast)->item; av = token_to_argv(node->data.cmd.token, 1); set_var(av[0], &var, &value); + if (ft_getenv(data_singleton()->env, var)) + return (0); builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL); return (0); } diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 26b73112..1f4a97ae 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/03/14 00:49:02 by ariard ### ########.fr */ +/* Updated: 2017/03/15 02:04:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,6 @@ t_itof g_execmap[] = {TK_CASE, &exec_leaf}, {TK_PAREN_OPEN, &exec_case_branch}, {TK_ASSIGNMENT_WORD, &exec_var}, - {MATH, &exec_math}, {SUBSHELL, &exec_leaf}, {TK_LBRACE, &exec_leaf}, {TK_BANG, &exec_bang}, diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c index b31cf2f2..d79e1e2a 100644 --- a/42sh/src/exec/node_copy.c +++ b/42sh/src/exec/node_copy.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ -/* Updated: 2017/03/14 00:49:02 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:24:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,6 @@ void *node_copy(void *data) new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); } if (old->type == TK_FOR || old->type == TK_PAREN_OPEN || old->type == TK_CASE) - new->data.cmd.wordlist = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); + new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); return (new); } diff --git a/42sh/src/exec/pfree_cond.c b/42sh/src/exec/pfree_cond.c index 57168280..2dae0996 100644 --- a/42sh/src/exec/pfree_cond.c +++ b/42sh/src/exec/pfree_cond.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:26:31 by wescande #+# #+# */ -/* Updated: 2017/03/13 22:31:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 02:04:14 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ int pfree_cond(t_process *p) { - btree_del(&p->data.d_while.condition, &ast_free); btree_del(&p->data.d_while.content, &ast_free); return (0); } diff --git a/42sh/src/exec/pfree_list.c b/42sh/src/exec/pfree_list.c index 55236f61..ac896c97 100644 --- a/42sh/src/exec/pfree_list.c +++ b/42sh/src/exec/pfree_list.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:37:04 by wescande #+# #+# */ -/* Updated: 2017/03/13 22:31:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:05:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ int pfree_list(t_process *p) { - ft_ld_del(&p->data.d_for.list_word, &ft_tabdel); + ft_ld_del(&p->data.d_for.token, &ft_tabdel); btree_del(&p->data.d_for.content, &ast_free); return (0); } diff --git a/42sh/src/exec/plaunch_builtin.c b/42sh/src/exec/plaunch_builtin.c index 88c60800..4a937d65 100644 --- a/42sh/src/exec/plaunch_builtin.c +++ b/42sh/src/exec/plaunch_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/13 23:35:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 22:34:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_case.c b/42sh/src/exec/plaunch_case.c index 1a9bccab..8c7e49b1 100644 --- a/42sh/src/exec/plaunch_case.c +++ b/42sh/src/exec/plaunch_case.c @@ -6,43 +6,21 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:02:23 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:10:32 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -/* -int exec_case(t_btree **ast) -{ - t_astnode *node; - char **av; - t_exec *exec; - - (void)ast; - exec = &data_singleton()->exec; - exec->attrs &= ~EXEC_CASE_BRANCH; - - node = (*ast)->item; - av = token_to_argv(node->data.cmd.wordlist, 1); - exec->case_pattern = av; - return (0); -} -*/ static int do_case(t_process *p) { t_exec *exec; + DG("exec case"); exec = &data_singleton()->exec; exec->attrs &= ~EXEC_CASE_BRANCH; - exec->case_pattern = token_to_argv(p->data.d_case.list_word, 1); -/* ft_exec(&p->data.d_if.condition); - if (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))) - { - exec->attrs |= EXEC_IF_BRANCH; - ft_exec(&p->data.d_if.content); - } - return (ft_atoi(ft_getenv(data_singleton()->env, "?")));*/ + exec->case_pattern = token_to_argv(p->data.d_case.token, 1); + ft_exec(&p->data.d_if.content); return (0); } diff --git a/42sh/src/exec/plaunch_file.c b/42sh/src/exec/plaunch_file.c index 4b466d72..211cfc75 100644 --- a/42sh/src/exec/plaunch_file.c +++ b/42sh/src/exec/plaunch_file.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/14 21:48:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 23:30:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_for.c b/42sh/src/exec/plaunch_for.c index 38e3104f..32cbc285 100644 --- a/42sh/src/exec/plaunch_for.c +++ b/42sh/src/exec/plaunch_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/15 00:49:20 by wescande #+# #+# */ -/* Updated: 2017/03/15 01:46:48 by wescande ### ########.fr */ +/* Updated: 2017/03/15 03:51:52 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,10 +19,11 @@ static int do_for(t_process *p) char **av; char *var; - temp = p->data.d_for.list_word; + temp = p->data.d_for.token; var = ((char **)temp->content)[0]; if (!word_is_assignment(temp->content)) return (error_badidentifier(var)); + DG(); temp = temp->next; while (temp) { @@ -30,8 +31,8 @@ static int do_for(t_process *p) av = token_to_argv(temp, 1); while (av[++i]) { - builtin_setenv("setenv", (char*[]){var, av[i], 0}, - data_singleton()->local_var); + builtin_setenv("setenv", (char*[]){"local" ,var, av[i], 0}, + NULL); ft_exec(&p->data.d_for.content); } temp = temp->next; @@ -64,33 +65,3 @@ int plaunch_for(t_process *p) do_for(p); return (0); } -/* - int exec_for(t_btree **ast) - { - t_astnode *node; - t_ld *temp; - char **av; - char *var; - int i; - - node = (*ast)->item; - temp = node->data.cmd.wordlist; - var = ((char **)(temp->content))[0]; - if (ft_isdigit(var[0])) - return (error_badidentifier(var)); - temp = temp->next; - while (temp) - { - i = 0; - av = token_to_argv(temp, 1); - while (av[i]) - { - builtin_setenv("setenv", (char*[]){var, av[i], 0}, - data_singleton()->local_var); - ft_exec(&(*ast)->right); - i++; - } - temp = temp->next; - } - return (0); - }*/ diff --git a/42sh/src/exec/plaunch_if.c b/42sh/src/exec/plaunch_if.c index a6208223..3efe9b9e 100644 --- a/42sh/src/exec/plaunch_if.c +++ b/42sh/src/exec/plaunch_if.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 02:04:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,12 +18,7 @@ static int do_if(t_process *p) exec = &data_singleton()->exec; exec->attrs &= ~EXEC_IF_BRANCH; - ft_exec(&p->data.d_if.condition); - if (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))) - { - exec->attrs |= EXEC_IF_BRANCH; - ft_exec(&p->data.d_if.content); - } + ft_exec(&p->data.d_if.content); return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index d1e4a65f..2920c659 100644 --- a/42sh/src/exec/plaunch_while.c +++ b/42sh/src/exec/plaunch_while.c @@ -6,29 +6,12 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:28:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 00:55:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -/* -int exec_while(t_btree **ast) -{ - int ret; - DG("exec while condition"); - ft_exec(&(*ast)->left); - DG("ret :[%s]", ft_getenv(data_singleton()->env, "?")); - while (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))) - { - DG("in the while"); - ft_exec(&(*ast)->right); - ret = ft_atoi(ft_getenv(data_singleton()->env, "?")); - ft_exec(&(*ast)->left); - } - exit(ret); - return (0); -} -*/ + static int do_while(t_process *p) { int ret; diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 1b30ca03..2e140bdf 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/13 23:10:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:52:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index f648a7d6..c57402e4 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/13 22:40:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 00:57:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_case.c b/42sh/src/exec/pset_case.c index e6aa9cde..bbc0ddb6 100644 --- a/42sh/src/exec/pset_case.c +++ b/42sh/src/exec/pset_case.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:46:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,8 @@ int pset_case(t_process *p, t_btree *ast) { - p->data.d_case.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy); + DG("set case"); + p->data.d_case.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, tab_esc_copy); p->data.d_case.content = btree_map(ast->right, &node_copy); p->type = PROCESS_CASE; return (0); diff --git a/42sh/src/exec/pset_cmd.c b/42sh/src/exec/pset_cmd.c index 3aafb8b1..408faeff 100644 --- a/42sh/src/exec/pset_cmd.c +++ b/42sh/src/exec/pset_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/13 22:52:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 21:25:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_for.c b/42sh/src/exec/pset_for.c index a5b4a4f6..3049e566 100644 --- a/42sh/src/exec/pset_for.c +++ b/42sh/src/exec/pset_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:05 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:57:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ int pset_for(t_process *p, t_btree *ast) { - p->data.d_for.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy); + p->data.d_for.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, tab_esc_copy); p->data.d_for.content = btree_map(ast->right, &node_copy); p->type = PROCESS_FOR; return (0); diff --git a/42sh/src/exec/pset_if.c b/42sh/src/exec/pset_if.c index 31440d0d..5d29ef80 100644 --- a/42sh/src/exec/pset_if.c +++ b/42sh/src/exec/pset_if.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:19:50 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 02:03:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ int pset_if(t_process *p, t_btree *ast) { - p->data.d_if.condition = btree_map(ast->left, &node_copy); p->data.d_if.content = btree_map(ast->right, &node_copy); p->type = PROCESS_IF; return (0); diff --git a/42sh/src/exec/token_to_argv.c b/42sh/src/exec/token_to_argv.c index 53c2a959..0e1ea38b 100644 --- a/42sh/src/exec/token_to_argv.c +++ b/42sh/src/exec/token_to_argv.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:55:53 by wescande #+# #+# */ -/* Updated: 2017/03/13 17:23:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 22:39:25 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_update_status.c b/42sh/src/job-control/job_update_status.c index c70d1f75..6432d8bc 100644 --- a/42sh/src/job-control/job_update_status.c +++ b/42sh/src/job-control/job_update_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ -/* Updated: 2017/03/13 14:53:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 23:43:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index acefe6f1..3033978a 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/13 17:36:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 23:43:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,8 @@ int job_wait(int id) DG("job wait id=[%i], pgid=[%i]", id, j->pgid); do { - if ((pid = waitpid(-j->pgid, &status, WUNTRACED)) == -1) + if ((pid = waitpid(-j->pgid, &status, WUNTRACED)) == -1 + && errno != ECHILD) ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", SHELL_NAME, errno); DG("waitpid->[%d]", pid); } diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index c2fabd19..9f9137e6 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/14 22:41:51 by wescande ### ########.fr */ +/* Updated: 2017/03/15 03:52:15 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 8be7b566..0d830c1c 100644 --- a/42sh/src/main/ft_putast.c +++ b/42sh/src/main/ft_putast.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ -/* Updated: 2017/03/14 00:50:34 by ariard ### ########.fr */ +/* Updated: 2017/03/14 22:11:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,10 +19,6 @@ char *ft_putast(void *nodein) if (node->type == TK_BANG) return ("TK_BANG"); - if (node->type == MATH) - return ("MATH"); - if (node->type == MATH_PLUS) - return ("MATH_PLUS"); if (node->type == TK_DSEMI) return ("TK_DSEMI"); if (node->type == WORDLIST) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index a41485ca..ffe4a3c3 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/14 23:08:20 by wescande ### ########.fr */ +/* Updated: 2017/03/15 03:52:32 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,7 +72,7 @@ int handle_instruction(int fd) } btree_print(STDBUG, ast, &ft_putast); if (ft_exec(&ast)) - return (1); + return (2); instruction_free(&token, &parser, &ast); if (SH_IS_INTERACTIVE(data_singleton()->opts) && *lexer.str) ft_add_str_in_history(lexer.str); @@ -97,7 +97,6 @@ int get_input_fd(char **av) pipe(fds); dup2_close(fds[PIPE_READ], 10); fd = 10; - //fd = fds[PIPE_READ]; file = *cliopts_getdata(av); write(fds[PIPE_WRITE], file, ft_strlen(file)); close(fds[PIPE_WRITE]); diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 828efaf6..ca14c64e 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/14 21:50:11 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 23:25:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static t_cliopts shell_opts[] = +static t_cliopts g_opts[] = { {'c', NULL, SH_OPTS_LC, SH_OPTS_JOBC | SH_INTERACTIVE, NULL}, {-1, "no-jobcontrol", 0, SH_OPTS_JOBC, NULL}, @@ -40,7 +40,7 @@ static int interactive_settings(void) if (setpgid(*shell_pgid, *shell_pgid)) { ft_dprintf(2, "Couldnt put the shell in it's own process group"); - exit (1); + exit(1); } tcsetpgrp(STDIN, *shell_pgid); tcgetattr(STDIN, &data->jobc.shell_tmodes); @@ -61,7 +61,7 @@ int shell_init(int ac, char **av) } else DG("non interactive"); - if (cliopts_get(av, shell_opts, data)) + if (cliopts_get(av, g_opts, data)) return (ft_perror()); if (SH_IS_INTERACTIVE(data->opts)) interactive_settings(); diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index 13f54c5f..1ea216dc 100644 --- a/42sh/src/parser/add_case.c +++ b/42sh/src/parser/add_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 20:42:13 by ariard #+# #+# */ -/* Updated: 2017/03/13 22:38:44 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:09:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,24 +25,8 @@ int iscase(t_btree **ast, t_list **lst) || node->type == TK_AMP || node->type == TK_PIPE) && iscase(&(*ast)->right, lst) == 1) return (1); - if (node->type == TK_CASE) - return (1); - } - return (0); -} - -int iscase_pattern(t_btree **ast, t_list **lst) -{ - t_astnode *node; - t_token *token; - - node = NULL; - token = (*lst)->content; - if (*ast) - { - node = (*ast)->item; if ((node->type == TK_CASE || node->type == TK_PAREN_OPEN) - && token->type == TK_WORD && node->pattern == 0) + && node->pattern == 1 && node->full == 0) return (1); } return (0); @@ -58,7 +42,7 @@ int iscase_branch(t_btree **ast, t_list **lst) if (*ast) { node = (*ast)->item; - if ((node->type == TK_PAREN_OPEN || node->type == TK_CASE) + if ((node->type == TK_PAREN_OPEN) && node->nest == 0 && token->type == TK_PAREN_OPEN) return (1); } @@ -81,22 +65,10 @@ int add_case_cmd(t_btree **ast, t_list **lst) else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN && node->nest == 0) return ((node->full = 1)); - else if ((token->type == TK_ESAC || token->type == TK_PAREN_CLOSE) + else if ((token->type == TK_ESAC) && node->nest == 0) + return ((node->full = 1)); + else if (token->type == TK_PAREN_CLOSE) return (0); return (add_cmd(&(*ast)->right, lst)); } - -int add_pattern(t_btree **ast, t_list **lst) -{ - t_astnode *node; - t_token *token; - - token = (*lst)->content; - node = (*ast)->item; - DG("node type is %s", read_state(node->type)); - ft_ld_pushback(&node->data.cmd.wordlist, - gen_tab(token->data, token->esc, token->esc2, 1)); - node->pattern = 1; - return (0); -} diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 436f0fd5..300a4c99 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/03/14 00:50:34 by ariard ### ########.fr */ +/* Updated: 2017/03/15 02:12:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,22 +15,18 @@ t_distrostree g_distrostree[] = { {&superflous_token, &add_null}, - {&isdir_sep, &add_redir_type}, - {&isdir_word, &add_redir_word}, - {&isloop_condition, &add_loop_condition}, {&isloop, &add_loop_cmd}, {&iscondition_branch, &add_branch}, {&iscondition, &add_condition_cmd}, - {&iscase_pattern, &add_pattern}, {&iscase, &add_case_cmd}, {&iscase_branch, &add_branch}, - {&ismath, &add_null}, - {&ismath_expr, &add_pattern}, {&issubshell, &add_subshell_cmd}, {&isfunc_name, &add_null}, {&isfunc, &add_func_cmd}, {&isionumber, &add_ionumber}, {&isbang, &add_bang}, + {&isdir_sep, &add_redir_type}, + {&isdir_word, &add_redir_word}, {&isnull, &add_null}, }; @@ -42,7 +38,7 @@ int superflous_token(t_btree **ast, t_list **lst) if (*lst) { token = (*lst)->content; - if (token->type == TK_IN || token->type == TK_DSEMI) + if (token->type == TK_IN) return (1); } return (0); @@ -51,15 +47,19 @@ int superflous_token(t_btree **ast, t_list **lst) static int no_del_token(t_btree **ast, t_list **lst) { t_astnode *node; + t_token *token; - (void)lst; node = NULL; + token = (*lst)->content; if (*ast) { node = (*ast)->item; + if (token->type == TK_WORD && (node->type == TK_CASE + || node->type == TK_PAREN_OPEN)) + return (0); if (node->type != TK_DO && node->type != TK_THEN && node->type != CMD && node->type != REDIR - && node->type != TK_ASSIGNMENT_WORD) + && node->type != TK_ASSIGNMENT_WORD && node->type != TK_FOR) return (1); } return (0); @@ -72,7 +72,7 @@ int add_cmd(t_btree **ast, t_list **lst) int i; i = -1; - while (++i < 18) + while (++i < 14) { if (g_distrostree[i].test(ast, lst) == 1) { @@ -88,15 +88,18 @@ int add_cmd(t_btree **ast, t_list **lst) node = (*ast)->item; if (token->type == TK_IF) add_if(ast, lst); - else if (token->type != TK_WORD) - { - DG("type is %s", read_state(token->type)); + else if (token->type != TK_WORD && token->type != TK_NAME) node->type = token->type; - } - else + else if (node->type != TK_CASE && node->type != TK_PAREN_OPEN && node->type != TK_FOR) node->type = CMD; - if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD) + if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD || token->type == TK_NAME) + { + DG("type is %s", read_state(node->type)); ft_ld_pushback(&node->data.cmd.token, gen_tab(token->data, token->esc, token->esc2, 1)); + } + if ((token->type == TK_WORD || token->type == TK_NAME) + && (node->type == TK_CASE || node->type == TK_PAREN_OPEN)) + node->pattern = 1; return (0); } diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index c2419d00..a90a4b39 100644 --- a/42sh/src/parser/add_func.c +++ b/42sh/src/parser/add_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ -/* Updated: 2017/03/13 19:27:58 by ariard ### ########.fr */ +/* Updated: 2017/03/15 00:26:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index d8694a03..94cadf15 100644 --- a/42sh/src/parser/add_loop.c +++ b/42sh/src/parser/add_loop.c @@ -6,33 +6,13 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ -/* Updated: 2017/03/13 16:12:35 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:59:52 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" int isloop(t_btree **ast, t_list **lst) -{ - t_astnode *node; - - (void)lst; - node = NULL; - if (*ast) - { - node = (*ast)->item; - if ((node->type == TK_NEWLINE || node->type == TK_SEMI - || node->type == TK_AMP || node->type == TK_PIPE) - && isloop(&(*ast)->right, lst) == 1) - return (1); - if ((node->type == TK_WHILE || node->type == TK_UNTIL - || node->type == TK_FOR) && node->full == 0) - return (1); - } - return (0); -} - -int isloop_condition(t_btree **ast, t_list **lst) { t_astnode *node; t_token *token; @@ -42,8 +22,18 @@ int isloop_condition(t_btree **ast, t_list **lst) if (*ast) { node = (*ast)->item; + if (node->type == TK_FOR && (token->type == TK_NEWLINE + || token->type == TK_SEMI) && node->pattern == 0) + return (1); if (node->type == TK_FOR && (token->type == TK_WORD || token->type == TK_NAME) && node->pattern == 0) + return (0); + if ((node->type == TK_NEWLINE || node->type == TK_SEMI + || node->type == TK_AMP || node->type == TK_PIPE) + && isloop(&(*ast)->right, lst) == 1) + return (1); + if ((node->type == TK_WHILE || node->type == TK_UNTIL + || node->type == TK_FOR) && node->full == 0) return (1); } return (0); @@ -79,21 +69,18 @@ int add_loop_cmd(t_btree **ast, t_list **lst) int add_loop_sep(t_btree **ast, t_list **lst) { + t_astnode *node; + + node = NULL; + if (*ast) + { + node = (*ast)->item; + if (node->type == TK_FOR && node->pattern == 0) + return (0); + } if (!(*ast)->right) return (add_sep(&(*ast)->left, lst)); else return (add_sep(&(*ast)->right, lst)); return (0); } - -int add_loop_condition(t_btree **ast, t_list **lst) -{ - t_astnode *node; - t_token *token; - - token = (*lst)->content; - node = (*ast)->item; - ft_ld_pushback(&node->data.cmd.wordlist, - gen_tab(token->data, token->esc, token->esc2, 1)); - return (0); -} diff --git a/42sh/src/parser/add_math.c b/42sh/src/parser/add_math.c deleted file mode 100644 index 4aa68f2c..00000000 --- a/42sh/src/parser/add_math.c +++ /dev/null @@ -1,50 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* add_math.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/11 15:44:53 by ariard #+# #+# */ -/* Updated: 2017/03/11 15:45:21 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int ismath(t_btree **ast, t_list **lst) -{ - t_astnode *node; - t_token *token; - - node = NULL; - token = (*lst)->content; - if (*ast) - { - node = (*ast)->item; - if (node->type == SUBSHELL && token->type == SUBSHELL) - { - node->type = MATH; - return (1); - } - if (node->type == MATH && token->type == TK_PAREN_CLOSE) - return (1); - } - return (0); -} - -int ismath_expr(t_btree **ast, t_list **lst) -{ - t_astnode *node; - t_token *token; - - node = NULL; - token = (*lst)->content; - if (*ast) - { - node = (*ast)->item; - if (node->type == MATH && token->type == TK_WORD) - return (1); - } - return (0); -} diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 4d5276ff..b4f9611a 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/03/13 22:39:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 02:09:54 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index c57a0944..f61ba420 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/03/13 16:25:31 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:41:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 050a9c83..3b8108f2 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ -/* Updated: 2017/03/14 00:50:34 by ariard ### ########.fr */ +/* Updated: 2017/03/14 22:02:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,14 +22,12 @@ t_aggrematch g_aggrematch[] = {TK_WORD, TK_PIPE, PATTERN, 0}, {TK_WORD, TK_IN, FOR_WORDLIST, TK_IN}, {TK_WORD, FOR_WORDLIST, FOR_WORDLIST, FOR_WORDLIST}, - {TK_WORD, MATH, MATH, MATH}, {TK_SEMI, FOR_WORDLIST, SEQUENTIAL_SEP, 0}, {TK_DSEMI, CMD_SUPERIOR, PIPE_SEQUENCE, CMD_SUPERIOR}, {TK_DSEMI, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE}, {TK_DSEMI, PIPE_CLOSE_SEQUENCE, PIPE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, {TK_PAREN_OPEN, TK_IN, PATTERN_CASE, 0}, {TK_PAREN_OPEN, CASE_LIST_NS, PATTERN_CASE, 0}, - {TK_PAREN_OPEN, TK_PAREN_OPEN, MATH, TK_PAREN_OPEN}, {TK_PAREN_OPEN, CMD_SUPERIOR, OPEN_FUNC, 0}, {TK_ASSIGNMENT_WORD, CMD_PREFIX, CMD_PREFIX, 0}, {TK_PIPE, CMD_SUPERIOR, SEQUENCE, CMD_SUPERIOR}, @@ -45,8 +43,6 @@ t_aggrematch g_aggrematch[] = {TK_ESAC, TK_IN, CASE_CLAUSE, TK_CASE}, {TK_ESAC, CASE_LIST_NS, CASE_CLAUSE, TK_CASE}, {TK_RBRACE, COMPOUND_LIST, BRACE_GROUP, TK_LBRACE}, - {TK_PAREN_CLOSE, MATH, MATH_PLUS, MATH}, - {TK_PAREN_CLOSE, MATH_PLUS, MATH_SUP, MATH_PLUS}, {TK_PAREN_CLOSE, COMPOUND_LIST, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, CMD_SUPERIOR, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, PIPE_SEMI_SEQUENCE, SUBSHELL, TK_PAREN_OPEN}, @@ -65,19 +61,16 @@ t_aggrematch g_aggrematch[] = {TK_OR_IF, PIPE_SEMI_SEQUENCE, AND_OR_MINOR, PIPE_SEMI_SEQUENCE}, {TK_OR_IF, CMD_SUPERIOR, AND_OR_MINOR, CMD_SUPERIOR}, {TK_OR_IF, PIPE_CLOSE_SEQUENCE, AND_OR_MINOR, PIPE_CLOSE_SEQUENCE}, - {SEPARATOR_OP, MATH_SUP, CMD_SUPERIOR, MATH_SUP}, {SEPARATOR_OP, CMD_SUPERIOR, SEPARATOR, 0}, {SEPARATOR_OP, COMPOUND_LIST, SEPARATOR, 0}, {SEPARATOR_OP, CASE_LIST_NS, SEPARATOR, 0}, {SEPARATOR_OP, PIPE_SEMI_SEQUENCE, SEPARATOR, 0}, {SEPARATOR_OP, PIPE_CLOSE_SEQUENCE, SEPARATOR, 0}, - {SEPARATOR, MATH_SUP, CMD_SUPERIOR, MATH_SUP}, {SEPARATOR, CMD_SUPERIOR, END_COMMAND, CMD_SUPERIOR}, {SEPARATOR, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {SEPARATOR, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST}, {SEPARATOR, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE}, {SEPARATOR, PIPE_CLOSE_SEQUENCE, PIPE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, - {LINEBREAK, MATH_SUP, CMD_SUPERIOR, MATH_SUP}, {LINEBREAK, SEPARATOR_OP, SEPARATOR, SEPARATOR_OP}, {LINEBREAK, TK_SEMI, SEQUENTIAL_SEP, TK_SEMI}, {LINEBREAK, TK_PAREN_CLOSE, FUNC, FNAME}, @@ -87,7 +80,6 @@ t_aggrematch g_aggrematch[] = {LINEBREAK, PIPE_CLOSE_SEQUENCE, PIPE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, {LINEBREAK, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST}, {LINEBREAK, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, - {NEWLINE_LIST, MATH_SUP, CMD_SUPERIOR, MATH_SUP}, {NEWLINE_LIST, CMD_NAME, CMD_SUPERIOR, CMD_NAME}, {NEWLINE_LIST, SEQUENTIAL_SEP, SEQUENTIAL_SEP, SEQUENTIAL_SEP}, {NEWLINE_LIST, TK_DO, TK_DO, TK_DO}, diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index cce99ead..ffaf9334 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:11:21 by ariard #+# #+# */ -/* Updated: 2017/03/14 00:50:34 by ariard ### ########.fr */ +/* Updated: 2017/03/14 22:01:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,6 @@ t_stackmatch g_stackmatch[] = {TK_WORD, COMPLETE_COMMANDS}, {TK_WORD, TK_IN}, {TK_WORD, FOR_WORDLIST}, - {TK_WORD, MATH}, {TK_ASSIGNMENT_WORD, CMD_PREFIX}, {TK_IO_NUMBER, REDIRECT_LIST}, {TK_IO_NUMBER, CMD_SUFFIX}, @@ -501,14 +500,12 @@ t_stackmatch g_stackmatch[] = {END_COMMAND, CASE_LIST_NS}, {END_COMMAND, COMPLETE_CONDITION}, {END_COMMAND, CONDITION}, - {SEPARATOR, MATH_SUP}, {SEPARATOR, CMD_SUPERIOR}, {SEPARATOR, TERM}, {SEPARATOR, COMPOUND_LIST}, {SEPARATOR, CASE_LIST_NS}, {SEPARATOR, PIPE_SEMI_SEQUENCE}, {SEPARATOR, PIPE_CLOSE_SEQUENCE}, - {SEPARATOR_OP, MATH_SUP}, {SEPARATOR_OP, CMD_SUPERIOR}, {SEPARATOR_OP, LIST}, {SEPARATOR_OP, TERM}, @@ -516,7 +513,6 @@ t_stackmatch g_stackmatch[] = {SEPARATOR_OP, COMPOUND_LIST}, {SEPARATOR_OP, PIPE_SEMI_SEQUENCE}, {SEPARATOR_OP, PIPE_CLOSE_SEQUENCE}, - {LINEBREAK, MATH_SUP}, {LINEBREAK, TK_SEMI}, {LINEBREAK, END_COMMAND}, {LINEBREAK, SEPARATOR_OP}, @@ -537,8 +533,6 @@ t_stackmatch g_stackmatch[] = {LINEBREAK, PROGRAM}, {LINEBREAK, TK_PAREN_OPEN}, {LINEBREAK, TK_LBRACE}, - {TK_PAREN_CLOSE, MATH}, - {TK_PAREN_CLOSE, MATH_PLUS}, {TK_PAREN_CLOSE, TK_SEMI}, {TK_PAREN_CLOSE, END_COMMAND}, {TK_PAREN_CLOSE, SEPARATOR_OP}, @@ -557,8 +551,6 @@ t_stackmatch g_stackmatch[] = {TK_PAREN_CLOSE, COMPOUND_LIST}, {TK_PAREN_CLOSE, FUNC_NAME}, {TK_PAREN_CLOSE, OPEN_FUNC}, - {TK_RBRACE, MATH}, - {TK_RBRACE, MATH_PLUS}, {TK_RBRACE, TK_SEMI}, {TK_RBRACE, END_COMMAND}, {TK_RBRACE, SEPARATOR_OP}, @@ -577,7 +569,6 @@ t_stackmatch g_stackmatch[] = {TK_RBRACE, PATTERN}, {TK_RBRACE, COMPOUND_LIST}, {TK_RBRACE, FUNC_NAME}, - {NEWLINE_LIST, MATH_SUP}, {NEWLINE_LIST, TK_DO}, {NEWLINE_LIST, CASE_LIST_NS}, {NEWLINE_LIST, TK_PAREN_CLOSE}, @@ -780,66 +771,6 @@ t_stackmatch g_stackmatch[] = {CMD_SUPERIOR, AND_OR_MAJOR}, {CLOSE_FUNC, CMD_SUPERIOR}, {CLOSE_FUNC, OPEN_FUNC}, - {MATH, LINEBREAK}, - {MATH, NEWLINE_LIST}, - {MATH, SEPARATOR}, - {MATH, SEPARATOR_OP}, - {MATH, TK_WHILE}, - {MATH, TK_UNTIL}, - {MATH, TK_DO}, - {MATH, TK_IF}, - {MATH, TK_ELIF}, - {MATH, TK_THEN}, - {MATH, TK_ELSE}, - {MATH, COMPOUND_LIST}, - {MATH, COMPLETE_CONDITION}, - {MATH, CONDITION}, - {MATH, TK_PAREN_OPEN}, - {MATH, TK_LBRACE}, - {MATH, SEQUENCE}, - {MATH, COMPLETE_COMMANDS}, - {MATH, AND_OR_MAJOR}, - {MATH, TK_BANG}, - {MATH_PLUS, LINEBREAK}, - {MATH_PLUS, NEWLINE_LIST}, - {MATH_PLUS, SEPARATOR}, - {MATH_PLUS, SEPARATOR_OP}, - {MATH_PLUS, TK_WHILE}, - {MATH_PLUS, TK_UNTIL}, - {MATH_PLUS, TK_DO}, - {MATH_PLUS, TK_IF}, - {MATH_PLUS, TK_ELIF}, - {MATH_PLUS, TK_THEN}, - {MATH_PLUS, TK_ELSE}, - {MATH_PLUS, COMPOUND_LIST}, - {MATH_PLUS, COMPLETE_CONDITION}, - {MATH_PLUS, CONDITION}, - {MATH_PLUS, TK_PAREN_OPEN}, - {MATH_PLUS, TK_LBRACE}, - {MATH_PLUS, SEQUENCE}, - {MATH_PLUS, COMPLETE_COMMANDS}, - {MATH_PLUS, AND_OR_MAJOR}, - {MATH_PLUS, TK_BANG}, - {MATH_SUP, LINEBREAK}, - {MATH_SUP, NEWLINE_LIST}, - {MATH_SUP, SEPARATOR}, - {MATH_SUP, SEPARATOR_OP}, - {MATH_SUP, TK_WHILE}, - {MATH_SUP, TK_UNTIL}, - {MATH_SUP, TK_DO}, - {MATH_SUP, TK_IF}, - {MATH_SUP, TK_ELIF}, - {MATH_SUP, TK_THEN}, - {MATH_SUP, TK_ELSE}, - {MATH_SUP, COMPOUND_LIST}, - {MATH_SUP, COMPLETE_CONDITION}, - {MATH_SUP, CONDITION}, - {MATH_SUP, TK_PAREN_OPEN}, - {MATH_SUP, TK_LBRACE}, - {MATH_SUP, SEQUENCE}, - {MATH_SUP, COMPLETE_COMMANDS}, - {MATH_SUP, AND_OR_MAJOR}, - {MATH_SUP, TK_BANG}, {SIMPLE_COMMAND, TK_WHILE}, {SIMPLE_COMMAND, TK_UNTIL}, {SIMPLE_COMMAND, TK_DO}, diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 0034e1c4..bc71df07 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ -/* Updated: 2017/03/14 00:50:34 by ariard ### ########.fr */ +/* Updated: 2017/03/14 22:03:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -80,7 +80,6 @@ t_prodmatch g_prodmatch[] = {TK_NAME, SEPARATOR_OP, FNAME}, {TK_NAME, NEWLINE_LIST, FNAME}, {TK_NAME, TK_FOR, NAME}, - {TK_NEWLINE, MATH_SUP, NEWLINE_LIST}, {TK_NEWLINE, CASE_LIST_NS, NEWLINE_LIST}, {TK_NEWLINE, TK_DO, NEWLINE_LIST}, {TK_NEWLINE, TK_PAREN_CLOSE, NEWLINE_LIST}, @@ -111,12 +110,10 @@ t_prodmatch g_prodmatch[] = {TK_NEWLINE, FOR_WORDLIST, NEWLINE_LIST}, {TK_NEWLINE, SEQUENTIAL_SEP, NEWLINE_LIST}, {TK_NEWLINE, PROGRAM, NEWLINE_LIST}, - {TK_SEMI, MATH_SUP, SEPARATOR_OP}, {TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP}, {TK_SEMI, LIST, SEPARATOR_OP}, {TK_SEMI, PIPE_SEMI_SEQUENCE, SEPARATOR_OP}, {TK_SEMI, PIPE_CLOSE_SEQUENCE, SEPARATOR_OP}, - {TK_AMP, MATH_SUP, SEPARATOR_OP}, {TK_AMP, CMD_SUPERIOR, SEPARATOR_OP}, {TK_AMP, LIST, SEPARATOR_OP}, {TK_AMP, PIPE_SEMI_SEQUENCE, SEPARATOR_OP}, diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index 889b437f..398023aa 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/03/14 00:50:34 by ariard ### ########.fr */ +/* Updated: 2017/03/14 22:11:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */