From 4849c899e4f6a238b259c9fccf8a25fbb25b3e17 Mon Sep 17 00:00:00 2001 From: AntoHesse Date: Mon, 6 Mar 2017 01:10:54 +0100 Subject: [PATCH] execution for without expansion --- 42sh/sample/for/for.sh | 6 +++++- 42sh/src/exec/exec_for.c | 9 +++++---- 42sh/src/exec/ft_exec.c | 1 + 42sh/src/lexer/get_state_global.c | 1 - 42sh/src/parser/add_number.c | 15 ++++++++++++--- 42sh/src/parser/add_redir.c | 20 ++++++++++++++++---- 42sh/src/parser/aggregate_sym.c | 8 ++++---- 42sh/src/parser/eval_sym.c | 2 +- 42sh/src/parser/ft_parse.c | 2 +- 42sh/src/parser/produce_sym.c | 6 +++--- 10 files changed, 48 insertions(+), 22 deletions(-) diff --git a/42sh/sample/for/for.sh b/42sh/sample/for/for.sh index 9d942c9e..d381c710 100644 --- a/42sh/sample/for/for.sh +++ b/42sh/sample/for/for.sh @@ -1,4 +1,8 @@ for i in hello bonjour salut comment do - ls + while cat efezf + do + echo INSIDE + done + ls | cat done diff --git a/42sh/src/exec/exec_for.c b/42sh/src/exec/exec_for.c index 270e12e2..91606fe6 100644 --- a/42sh/src/exec/exec_for.c +++ b/42sh/src/exec/exec_for.c @@ -22,11 +22,12 @@ int exec_for(t_btree **ast) node = (*ast)->item; temp = node->data.cmd.wordlist; var = temp->content; - builtin_setenv("setenv", (char*[]){var, 0}, data_singleton()->local_var); + temp = temp->next; +// declare error bad identifier while (temp) - { - //process expansion av = token_to_char(temp->content) - builtin_setenv("setenv", (char*[]){var, 0}, data_singleton()->local_var); + { + builtin_setenv("setenv", (char*[]){var, temp->content, 0}, + data_singleton()->local_var); ft_exec(&(*ast)->right); temp = temp->next; } diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index ae3234c0..8f30eb66 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -25,6 +25,7 @@ t_execmap g_execmap[] = {TK_ELIF, &exec_elif}, {TK_ELSE, &exec_else}, {TK_UNTIL, &exec_until}, + {TK_FOR, &exec_for}, /* {TK_SUBSHELL, &exec_}, */ {CMD, &exec_cmd}, {0, 0}, diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index d6af9653..b49264f9 100644 --- a/42sh/src/lexer/get_state_global.c +++ b/42sh/src/lexer/get_state_global.c @@ -17,7 +17,6 @@ t_lexstate get_state_global(t_lexer *lexer) char c; c = lexer->str[lexer->pos]; - DG("check, c=%c", lexer->str[lexer->pos]); if (ft_is_delim(c)) return (DELIM); else if (c == '#') diff --git a/42sh/src/parser/add_number.c b/42sh/src/parser/add_number.c index 84ffe8ca..f2c6d3e0 100644 --- a/42sh/src/parser/add_number.c +++ b/42sh/src/parser/add_number.c @@ -15,11 +15,20 @@ int isionumber(t_btree **ast, t_list **lst) { t_token *token; + t_astnode *node; - (void)ast; token = (*lst)->content; - if (token->type == TK_IO_NUMBER) - return (1); + if (*ast) + { + node = (*ast)->item; + if (node->type == CMD && token->type == TK_IO_NUMBER) + return (1); + } + if (!*ast) + { + if (token->type == TK_IO_NUMBER) + return (1); + } return (0); } diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 46d89b71..78cce0f4 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -15,13 +15,25 @@ int isdir_sep(t_btree **ast, t_list **list) { t_token *token; + t_astnode *node; - (void)ast; token = (*list)->content; - if (token->type == TK_LESS || token->type == TK_GREAT - || token->type == TK_GREATAND || token->type == TK_LESSAND - || token->type == TK_DLESS || token->type == TK_DGREAT) + if (*ast) + { + node = (*ast)->item; + if ((node->type == CMD || node->type == TK_IO_NUMBER) && + (token->type == TK_LESS || token->type == TK_GREAT + || token->type == TK_GREATAND || token->type == TK_LESSAND + || token->type == TK_DLESS || token->type == TK_DGREAT)) + return (1); + } + if (!*ast) + { + if (token->type == TK_LESS || token->type == TK_GREAT + || token->type == TK_GREATAND || token->type == TK_LESSAND + || token->type == TK_DLESS || token->type == TK_DGREAT) return (1); + } return (0); } diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index fb79eb04..a0fdff7a 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -315,21 +315,21 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) i = 0; head = (*stack)->content; -// DG("aggregate head %s && sym %s", -// read_state(*head), read_state(*new_sym)); + DG("aggregate head %s && sym %s", + read_state(*head), read_state(*new_sym)); while (g_aggrematch[i].top) { if (*new_sym == g_aggrematch[i].top && MATCH_STACK(*head, g_aggrematch[i].under)) { -// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); + DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; if (g_aggrematch[i].erase_sym) { pop_stack(stack, g_aggrematch[i].erase_sym); head = (*stack)->content; -// DG("stack after pop: %s", read_state(*head)); + DG("stack after pop: %s", read_state(*head)); } if (eval_sym(stack, *new_sym)) return ((*state = ERROR)); diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 6a5f0724..9acbc37a 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -1027,7 +1027,7 @@ int eval_sym(t_list **stack, t_sym new_sym) int i; head = (*stack)->content; -// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); + DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); i = 0; while (g_stackmatch[i].top) { diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index b959f9c5..cd00ce9a 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -37,7 +37,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) while (*token) { produce_sym(&parser->stack, parser->new_sym, token); -// DG("new sym %s", read_state(*parser->new_sym)); + DG("new sym %s", read_state(*parser->new_sym)); if (eval_sym(&parser->stack, *parser->new_sym)) return ((parser->state = ERROR)); else diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index c2302123..bea5760b 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -107,8 +107,8 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst) token = (*lst)->content; head = (*stack)->content; -// DG("produce stack : %s && token : %s", read_state(*head), -// read_state(token->type)); + DG("produce stack : %s && token : %s", read_state(*head), + read_state(token->type)); i = 0; *new_sym = 0; while (g_prodmatch[i].new_sym) @@ -116,7 +116,7 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst) if (token->type == g_prodmatch[i].token && *head == g_prodmatch[i].stack) { -// DG("MATCH : %s", read_state(g_prodmatch[i].new_sym)); + DG("MATCH : %s", read_state(g_prodmatch[i].new_sym)); *new_sym = g_prodmatch[i].new_sym; } i++;