modif redirect list

This commit is contained in:
ariard@student.42.fr 2017-02-17 17:15:58 +01:00
parent 7f83e231aa
commit b0a3e63ffc
15 changed files with 69 additions and 21 deletions

View file

@ -198,7 +198,8 @@ parser/error_syntax.c\
parser/build_tree.c\
parser/tree_wrapper.c\
parser/add_sep.c\
parser/add_cmd.c
parser/add_cmd.c\
parser/add_file.c
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))

BIN
42sh/includes/.parser.h.swn Normal file

Binary file not shown.

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
/* Updated: 2017/02/15 20:50:55 by ariard ### ########.fr */
/* Updated: 2017/02/17 17:11:45 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -200,6 +200,8 @@ int build_tree(t_btree **ast, t_list **lst);
int add_sep(t_btree **ast, t_list **lst);
int add_cmd(t_btree **ast, t_list **lst);
int add_file(t_btree **ast, t_list **lst);
int isdir(t_btree **ast);
int join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast);

1
42sh/sample/yale1.sh Normal file
View file

@ -0,0 +1 @@
< file1 ls | cat | cat | ls > file2

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/02/09 22:31:50 by ariard ### ########.fr */
/* Updated: 2017/02/17 17:09:18 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/02/15 20:57:47 by ariard ### ########.fr */
/* Updated: 2017/02/17 16:52:22 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,6 +20,8 @@ int add_cmd(t_btree **ast, t_list **lst)
if (!*ast)
gen_node(ast);
else if (isdir(ast))
return (add_file(ast, lst));
else
return (add_cmd(&(*ast)->right, lst));
my_tab = NULL;

View file

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
/* Updated: 2017/02/17 17:14:52 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int isdir(t_btree **ast)
{
t_astnode *node;
node = (*ast)->item;
if (node->data.redir.word.word)
return (0);
if (node->type == TK_LESS || node->type == TK_GREAT
|| node->type == TK_LESSAND || node->type == TK_GREATAND
|| node->type == TK_DGREAT || node->type == TK_LESSGREAT
|| node->type == TK_CLOBBER)
return (1);
return (0);
}
int add_file(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
DG("add file");
token = (*lst)->content;
node = (*ast)->item;
node->data.redir.n = ft_atoi(token->data);
node->data.redir.word.word = ft_strdup(token->data);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 19:12:07 by ariard #+# #+# */
/* Updated: 2017/02/15 20:48:17 by ariard ### ########.fr */
/* Updated: 2017/02/17 17:09:31 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */
/* Updated: 2017/02/15 19:52:56 by ariard ### ########.fr */
/* Updated: 2017/02/17 17:05:00 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -159,20 +159,20 @@ int aggregate_sym(t_sym **stack, t_sym *new_sym, t_parstate *state)
int i;
i = 0;
DG("aggregate head %s && sym %s",
read_state(**stack), read_state(*new_sym));
// DG("aggregate head %s && sym %s",
// read_state(**stack), read_state(*new_sym));
while (g_aggrematch[i].top)
{
if (*new_sym == g_aggrematch[i].top
&& MATCH_STACK(**stack, 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);
DG("stack after pop: %s", read_state(**stack));
// DG("stack after pop: %s", read_state(**stack));
}
if (eval_sym(**stack, *new_sym))
return ((*state = ERROR));

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/02/15 20:51:50 by ariard ### ########.fr */
/* Updated: 2017/02/17 16:39:38 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 16:26:30 by ariard #+# #+# */
/* Updated: 2017/02/15 19:52:12 by ariard ### ########.fr */
/* Updated: 2017/02/17 17:05:11 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -452,7 +452,7 @@ int eval_sym(t_sym stack, t_sym new_sym)
{
int i;
DG("eval head %s && sym %s", read_state(stack), read_state(new_sym));
// DG("eval head %s && sym %s", read_state(stack), read_state(new_sym));
i = 0;
while (g_stackmatch[i].top)
{

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 14:30:22 by ariard #+# #+# */
/* Updated: 2017/02/15 20:40:28 by ariard ### ########.fr */
/* Updated: 2017/02/17 17:05:21 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,7 +27,7 @@ int ft_parse2(t_btree **ast, t_list **token)
while (*token)
{
produce_sym(*stack, new_sym, token);
DG("new sym %s", read_state(*new_sym));
// DG("new sym %s", read_state(*new_sym));
if (eval_sym(*stack, *new_sym))
state = ERROR;
else

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
/* Updated: 2017/02/03 17:39:34 by ariard ### ########.fr */
/* Updated: 2017/02/17 16:45:35 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
/* Updated: 2017/02/15 19:50:59 by ariard ### ########.fr */
/* Updated: 2017/02/17 17:04:44 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -66,8 +66,8 @@ int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst)
int i;
token = (*lst)->content;
DG("produce stack : %s && token : %s", read_state(stack),
read_state(token->type));
// DG("produce stack : %s && token : %s", read_state(stack),
// read_state(token->type));
i = 0;
*new_sym = 0;
while (g_prodmatch[i].new_sym)
@ -75,7 +75,7 @@ int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst)
if (token->type == g_prodmatch[i].token
&& stack == 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++;

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:57:44 by ariard #+# #+# */
/* Updated: 2017/02/15 20:56:38 by ariard ### ########.fr */
/* Updated: 2017/02/17 17:14:34 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,6 +27,7 @@ int gen_node(t_btree **ast)
{
*ast = btree_create_node(&item, sizeof(item));
((t_astnode *)(*ast)->item)->data.token = NULL;
((t_astnode *)(*ast)->item)->data.redir.word.word = NULL;
}
return (0);
}