redir ok if + case
This commit is contained in:
parent
58c6491d23
commit
7708a456a9
8 changed files with 87 additions and 7 deletions
|
|
@ -280,6 +280,7 @@ parser/add_loop.c\
|
||||||
parser/add_math.c\
|
parser/add_math.c\
|
||||||
parser/add_number.c\
|
parser/add_number.c\
|
||||||
parser/add_redir.c\
|
parser/add_redir.c\
|
||||||
|
parser/add_redir_condition.c\
|
||||||
parser/add_sep.c\
|
parser/add_sep.c\
|
||||||
parser/add_subshell.c\
|
parser/add_subshell.c\
|
||||||
parser/add_var.c\
|
parser/add_var.c\
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/09 14:33:59 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 19:59:56 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ int add_condition_sep(t_btree **ast, t_list **lst);
|
||||||
int add_branch(t_btree **ast, t_list **lst);
|
int add_branch(t_btree **ast, t_list **lst);
|
||||||
int add_redir_word(t_btree **ast, t_list **lst);
|
int add_redir_word(t_btree **ast, t_list **lst);
|
||||||
int add_redir_type(t_btree **ast, t_list **lst);
|
int add_redir_type(t_btree **ast, t_list **lst);
|
||||||
|
int add_redir_condition(t_btree **ast, t_list **lst);
|
||||||
int add_case_cmd(t_btree **ast, t_list **lst);
|
int add_case_cmd(t_btree **ast, t_list **lst);
|
||||||
int add_case_sep(t_btree **ast, t_list **lst);
|
int add_case_sep(t_btree **ast, t_list **lst);
|
||||||
int add_pattern(t_btree **ast, t_list **lst);
|
int add_pattern(t_btree **ast, t_list **lst);
|
||||||
|
|
@ -139,6 +140,7 @@ int isfunc_name(t_btree **ast, t_list **lst);
|
||||||
int isdir(t_btree **ast);
|
int isdir(t_btree **ast);
|
||||||
int iscondition(t_btree **ast, t_list **list);
|
int iscondition(t_btree **ast, t_list **list);
|
||||||
int isdir_sep(t_btree **ast, t_list **list);
|
int isdir_sep(t_btree **ast, t_list **list);
|
||||||
|
int isdir_condition(t_btree **ast, t_list **list);
|
||||||
int isdir_word(t_btree **ast, t_list **list);
|
int isdir_word(t_btree **ast, t_list **list);
|
||||||
int isvar(t_btree **ast, t_list **list);
|
int isvar(t_btree **ast, t_list **list);
|
||||||
int isnull(t_btree **ast, t_list **list);
|
int isnull(t_btree **ast, t_list **list);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/09 17:58:18 by ariard ### ########.fr */
|
/* Updated: 2017/03/10 20:14:52 by ariard ### ########.fr */
|
||||||
/* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */
|
/* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
|
||||||
5
42sh/sample/while/while03.sh
Normal file
5
42sh/sample/while/while03.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
ls
|
||||||
|
for HELLLO in yolo ;
|
||||||
|
do
|
||||||
|
ls
|
||||||
|
done > file1
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/10 17:55:08 by ariard ### ########.fr */
|
/* Updated: 2017/03/11 15:06:03 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
t_distrostree g_distrostree[] =
|
t_distrostree g_distrostree[] =
|
||||||
{
|
{
|
||||||
{&superflous_token, &add_null},
|
{&superflous_token, &add_null},
|
||||||
|
{&isdir_condition, &add_redir_condition},
|
||||||
{&isdir_sep, &add_redir_type},
|
{&isdir_sep, &add_redir_type},
|
||||||
{&isdir_word, &add_redir_word},
|
{&isdir_word, &add_redir_word},
|
||||||
{&isvar, &add_var},
|
{&isvar, &add_var},
|
||||||
|
|
@ -72,7 +73,7 @@ int add_cmd(t_btree **ast, t_list **lst)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
while (++i < 18)
|
while (++i < 19)
|
||||||
if (g_distrostree[i].test(ast, lst) == 1)
|
if (g_distrostree[i].test(ast, lst) == 1)
|
||||||
{
|
{
|
||||||
DG("add : %d", i);
|
DG("add : %d", i);
|
||||||
|
|
@ -84,7 +85,6 @@ int add_cmd(t_btree **ast, t_list **lst)
|
||||||
return (add_cmd(&(*ast)->right, lst));
|
return (add_cmd(&(*ast)->right, lst));
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
DG("add cmd");
|
|
||||||
if (token->type == TK_IF)
|
if (token->type == TK_IF)
|
||||||
add_if(ast, lst);
|
add_if(ast, lst);
|
||||||
else if (token->type != TK_WORD)
|
else if (token->type != TK_WORD)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/10 19:43:10 by ariard ### ########.fr */
|
/* Updated: 2017/03/11 14:51:00 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -36,8 +36,11 @@ int isdir_sep(t_btree **ast, t_list **list)
|
||||||
if (token->type == TK_LESS || token->type == TK_GREAT
|
if (token->type == TK_LESS || token->type == TK_GREAT
|
||||||
|| token->type == TK_GREATAND || token->type == TK_LESSAND
|
|| token->type == TK_GREATAND || token->type == TK_LESSAND
|
||||||
|| token->type == TK_DLESS || token->type == TK_DGREAT)
|
|| token->type == TK_DLESS || token->type == TK_DGREAT)
|
||||||
|
{
|
||||||
|
DG("add dir sep");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
69
42sh/src/parser/add_redir_condition.c
Normal file
69
42sh/src/parser/add_redir_condition.c
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* add_redir_condition.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/11 14:54:18 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/03/11 15:17:58 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static int isdir_sep_condition(t_btree **ast, t_list **lst)
|
||||||
|
{
|
||||||
|
t_token *token;
|
||||||
|
t_astnode *node;
|
||||||
|
|
||||||
|
token = (*lst)->content;
|
||||||
|
if (*ast)
|
||||||
|
{
|
||||||
|
node = (*ast)->item;
|
||||||
|
if (node->type == TK_IF || node->type == TK_CASE)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int isdir_word_condition(t_btree **ast, t_list **lst)
|
||||||
|
{
|
||||||
|
t_token *token;
|
||||||
|
t_astnode *node;
|
||||||
|
|
||||||
|
token = (*lst)->content;
|
||||||
|
if (*ast)
|
||||||
|
{
|
||||||
|
node = (*ast)->item;
|
||||||
|
if (node->type == REDIR)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int isdir_condition(t_btree **ast, t_list **lst)
|
||||||
|
{
|
||||||
|
t_token *token;
|
||||||
|
t_astnode *node;
|
||||||
|
|
||||||
|
token = (*lst)->content;
|
||||||
|
if (*ast)
|
||||||
|
{
|
||||||
|
node = (*ast)->item;
|
||||||
|
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)
|
||||||
|
&& isdir_sep_condition(&(*ast)->left, lst) == 1)
|
||||||
|
return (1);
|
||||||
|
if (token->type == TK_WORD
|
||||||
|
&& isdir_word_condition(&(*ast)->left, lst) == 1)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int add_redir_condition(t_btree **ast, t_list **lst)
|
||||||
|
{
|
||||||
|
return (add_cmd(&(*ast)->left, lst));
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue