execution if/elif/else + while ok
This commit is contained in:
parent
3dc47431ba
commit
7d660fec7c
13 changed files with 34 additions and 45 deletions
|
|
@ -1,10 +1,9 @@
|
|||
if ls
|
||||
if cat wef4eeef
|
||||
then
|
||||
ls
|
||||
elif ls
|
||||
echo Conditon 1
|
||||
elif cat yulu
|
||||
then
|
||||
ls
|
||||
elif ls
|
||||
then
|
||||
ls
|
||||
echo Condition 2
|
||||
else
|
||||
echo Condition 3
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
while ls
|
||||
while pwd
|
||||
do
|
||||
while ls
|
||||
while cat rwgwghe
|
||||
do
|
||||
pwd
|
||||
echo Hello World
|
||||
done
|
||||
while ls
|
||||
while pwd
|
||||
do
|
||||
pwd
|
||||
echo Bonjour ca va
|
||||
done
|
||||
done
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/03 19:59:33 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/04 17:09:11 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/03 20:28:21 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/04 17:11:10 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 18:08:53 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/03 16:14:25 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/04 17:45:29 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,14 +17,11 @@ int exec_elif(t_btree **ast)
|
|||
t_exec *exec;
|
||||
|
||||
exec = &data_singleton()->exec;
|
||||
/* if (data_singleton()->exec.process.if_branch == 1) */
|
||||
if (EXEC_IS_IF_BRANCH(exec->attrs))
|
||||
return (0);
|
||||
ft_exec(&(*ast)->left);
|
||||
if (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))
|
||||
/* if (data_singleton()->exec.process.status == 1) */
|
||||
if (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)
|
||||
{
|
||||
/* data_singleton()->exec.process.if_branch = 1; */
|
||||
exec->attrs |= EXEC_IF_BRANCH;
|
||||
ft_exec(&(*ast)->right);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 18:55:07 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/03 15:56:25 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/04 18:00:47 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,11 +18,8 @@ int exec_else(t_btree **ast)
|
|||
|
||||
exec = &data_singleton()->exec;
|
||||
if (EXEC_IS_IF_BRANCH(exec->attrs))
|
||||
/* if (data_singleton()->exec.process.if_branch == 0) */
|
||||
{
|
||||
return (0);
|
||||
exec->attrs |= EXEC_IF_BRANCH;
|
||||
/* data_singleton()->exec.process.if_branch = 1; */
|
||||
ft_exec(&(*ast)->right);
|
||||
}
|
||||
ft_exec(&(*ast)->left);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/03 16:30:46 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/04 17:37:11 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,13 +18,10 @@ int exec_if(t_btree **ast)
|
|||
|
||||
exec = &data_singleton()->exec;
|
||||
|
||||
/* data_singleton()->exec.process.if_branch = 0; */
|
||||
exec->attrs &= ~EXEC_IF_BRANCH;
|
||||
ft_exec(&(*ast)->left);
|
||||
/* if (data_singleton()->exec.process.status == 1) */
|
||||
if (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)
|
||||
{
|
||||
/* data_singleton()->exec.process.if_branch = 1; */
|
||||
exec->attrs |= EXEC_IF_BRANCH;
|
||||
ft_exec(&(*ast)->right);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/03 18:10:34 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/04 17:23:50 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/03 16:05:12 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/04 17:19:18 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,9 +14,12 @@
|
|||
|
||||
int exec_while(t_btree **ast)
|
||||
{
|
||||
DG("exec while condition");
|
||||
ft_exec(&(*ast)->left);
|
||||
while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))
|
||||
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);
|
||||
ft_exec(&(*ast)->left);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/03 19:03:46 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/04 17:16:30 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -42,11 +42,7 @@ int ft_exec(t_btree **ast)
|
|||
while (g_execmap[i].type)
|
||||
{
|
||||
if (item->type == g_execmap[i].type)
|
||||
{
|
||||
DG("match : %s and %s",
|
||||
read_state(item->type), read_state(g_execmap[i].type));
|
||||
return ((*g_execmap[i].f)(ast));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/04 16:49:23 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/04 17:35:55 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -36,14 +36,11 @@ int handle_instruction(int fd)
|
|||
return (parser.state == UNDEFINED ? error_EOF(&token,
|
||||
&parser, &ast) : 1);
|
||||
}
|
||||
DG("after readline %s", str);
|
||||
DG("in lexer %s", lexer.str);
|
||||
ft_strappend(&lexer.str, str);
|
||||
if (get_lexer_stack(lexer) == BACKSLASH)
|
||||
pop(&lexer.stack);
|
||||
else if (get_lexer_stack(lexer) == DLESS)
|
||||
lexer.state = DLESS;
|
||||
DG("after readline %s", lexer.str);
|
||||
ltoken = ft_lstlast(token);
|
||||
if (lexer_lex(token ? <oken : &token, &lexer))
|
||||
return (1);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/03 20:04:08 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/04 17:08:04 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -51,6 +51,9 @@ int add_cmd(t_btree **ast, t_list **lst)
|
|||
&& node->type != REDIR)
|
||||
return (add_cmd(&(*ast)->right, lst));
|
||||
node = (*ast)->item;
|
||||
if (token->type != TK_WORD)
|
||||
node->type = token->type;
|
||||
else
|
||||
node->type = CMD;
|
||||
if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
|||
else
|
||||
parser->state = UNDEFINED;
|
||||
build_tree(ast, token);
|
||||
// btree_print(STDBUG, *ast, &ft_putast);
|
||||
btree_print(STDBUG, *ast, &ft_putast);
|
||||
if ((end_instruction(&parser->stack) && !(*token)->next))
|
||||
insert_linebreak(token);
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in a new issue