merge resolved

This commit is contained in:
Jack Halford 2017-03-13 16:24:25 +01:00
commit 3ae1cf2100
20 changed files with 48 additions and 41 deletions

5
42sh/.gitignore vendored
View file

@ -13,3 +13,8 @@ debug
*.swn *.swn
STDBUG STDBUG
STDEBUG STDEBUG
display_env
read_on_stdin
write_on_stderr
write_on_stdout
write_on_stdout_and_stderr

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ # # By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# # # Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/10 17:40:02 by gwojda ### ########.fr # # Updated: 2017/03/12 15:48:20 by ariard ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #

View file

@ -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/10 19:59:56 by ariard ### ########.fr */ /* Updated: 2017/03/12 01:01:44 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -111,6 +111,7 @@ 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_redir_condition(t_btree **ast, t_list **lst);
int redir_init(t_type type, t_redir *redir);
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);

View file

@ -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/11 16:40:08 by jhalford ### ########.fr */ /* Updated: 2017/03/12 01:01:33 by ariard ### ########.fr */
/* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */ /* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

@ -1 +1 @@
Subproject commit 690840914077a838e13238356db33e35127baa7d Subproject commit 9382dc10fdb91892ab26604a5776e5301ab88b71

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 18:59:11 by wescande #+# #+# */ /* Created: 2017/03/07 18:59:11 by wescande #+# #+# */
/* Updated: 2017/03/07 21:20:53 by wescande ### ########.fr */ /* Updated: 2017/03/11 20:47:05 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,4 +32,3 @@ int word_is_assignment(char **content)
} }
return (1); return (1);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 20:28:13 by ariard #+# #+# */ /* Created: 2017/02/24 20:28:13 by ariard #+# #+# */
/* Updated: 2017/03/07 18:36:23 by jhalford ### ########.fr */ /* Updated: 2017/03/11 20:48:34 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,6 +32,6 @@ int lexer_assignement_word(t_list **alst, t_lexer *lexer)
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
if ((lexer->state = get_state_redir(lexer))) if ((lexer->state = get_state_redir(lexer)))
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
lexer->state = ft_isdigit(c) ? NUMBER : ASSIGNEMENT_WORD; lexer->state = ASSIGNEMENT_WORD;
return(lexer_lex(alst, lexer)); return(lexer_lex(alst, lexer));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */ /* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */
/* Updated: 2017/03/10 13:12:43 by jhalford ### ########.fr */ /* Updated: 2017/03/11 20:48:19 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2017/03/08 23:36:13 by ariard ### ########.fr */ /* Updated: 2017/03/11 20:46:32 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/13 16:02:00 by jhalford ### ########.fr */ /* Updated: 2017/03/13 16:12:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -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/11 15:34:23 by ariard ### ########.fr */ /* Updated: 2017/03/13 14:37:18 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -74,8 +74,13 @@ int add_cmd(t_btree **ast, t_list **lst)
i = -1; i = -1;
while (++i < 19) while (++i < 19)
{
if (g_distrostree[i].test(ast, lst) == 1) if (g_distrostree[i].test(ast, lst) == 1)
{
DG("add to %d", i);
return (g_distrostree[i].add(ast, lst)); return (g_distrostree[i].add(ast, lst));
}
}
if (!*ast) if (!*ast)
gen_node(ast); gen_node(ast);
else if (no_del_token(ast, lst)) else if (no_del_token(ast, lst))

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
/* Updated: 2017/03/11 15:44:47 by ariard ### ########.fr */ /* Updated: 2017/03/13 14:23:53 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */ /* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
/* Updated: 2017/03/11 16:45:07 by ariard ### ########.fr */ /* Updated: 2017/03/13 16:21:50 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -38,13 +38,13 @@ int add_ionumber(t_btree **ast, t_list **lst)
t_token *token; t_token *token;
t_redir redir; t_redir redir;
DG("add io_number");
if (!*ast) if (!*ast)
gen_node(ast); gen_node(ast);
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
node->cache = node->type; node->cache = node->type;
node->type = token->type; node->type = token->type;
redir_init(token->type, &redir);
redir.n = ft_atoi(token->data); redir.n = ft_atoi(token->data);
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir))); ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
return (0); return (0);

View file

@ -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/13 16:11:16 by jhalford ### ########.fr */ /* Updated: 2017/03/13 16:23:35 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,7 +52,10 @@ int isdir_word(t_btree **ast, t_list **list)
node = (*ast)->item; node = (*ast)->item;
if (token->type == TK_WORD && node->type == REDIR) if (token->type == TK_WORD && node->type == REDIR)
{ {
node->type = node->cache; if (node->cache != TK_NEWLINE)
node->type = node->cache;
else
node->type = CMD;
node->cache = 0; node->cache = 0;
return (1); return (1);
} }
@ -65,7 +68,6 @@ int add_redir_word(t_btree **ast, t_list **lst)
t_astnode *node; t_astnode *node;
t_token *token; t_token *token;
t_redir *redir; t_redir *redir;
/* t_redir *temp; */
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
@ -73,32 +75,26 @@ int add_redir_word(t_btree **ast, t_list **lst)
{ {
redir = (ft_lstlast(node->data.cmd.redir))->content; redir = (ft_lstlast(node->data.cmd.redir))->content;
redir->word = ft_strdup(token->data); redir->word = ft_strdup(token->data);
/* DG("redir1 @ %p word=[%s]", redir, redir->word); */
/* if (redir->type == TK_DLESS) */
/* { */
/* temp = ft_lstlast((data_singleton()->heredoc_queue))->content; */
/* temp->word = redir->word; */
/* } */
} }
return (0); return (0);
} }
static int add_redir_type_number(t_btree **ast, t_list **lst) static int add_redir_type_number(t_btree **ast, t_list **lst)
{ {
t_redir *temp; t_redir *redir;
t_redir *temp_heredoc;
t_astnode *node; t_astnode *node;
t_token *token; t_token *token;
t_list **queue;
t_list *redir_lst;
queue = &data_singleton()->heredoc_queue;
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
temp = (ft_lstlast(node->data.cmd.redir))->content; redir_lst = ft_lstlast(node->data.cmd.redir);
temp->type = token->type; redir = redir_lst->content;
redir->type = token->type;
if (token->type == TK_DLESS) if (token->type == TK_DLESS)
{ ft_lsteadd(queue, ft_lstnew(&redir_lst->content, sizeof(t_redir*)));
temp_heredoc = data_singleton()->heredoc_queue->content;
temp_heredoc->n = temp->n;
}
return (0); return (0);
} }
@ -130,12 +126,8 @@ int add_redir_type(t_btree **ast, t_list **lst)
redir_init(token->type, &redir); redir_init(token->type, &redir);
redir_lst = ft_lstnew(&redir, sizeof(redir)); redir_lst = ft_lstnew(&redir, sizeof(redir));
ft_lsteadd(&node->data.cmd.redir, redir_lst); ft_lsteadd(&node->data.cmd.redir, redir_lst);
/* DG("redir1 @ %p word=[%s]", redir_lst->content, ((t_redir*)redir_lst->content)->word); */
if (token->type == TK_DLESS) if (token->type == TK_DLESS)
{
ft_lsteadd(queue, ft_lstnew(&redir_lst->content, sizeof(t_redir*))); ft_lsteadd(queue, ft_lstnew(&redir_lst->content, sizeof(t_redir*)));
/* DG("redir2 @ %p word=[%s]", *(t_redir**)(*queue)->content, (*(t_redir**)(*queue)->content)->word); */
}
} }
else else
add_redir_type_number(ast, lst); add_redir_type_number(ast, lst);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 14:54:18 by ariard #+# #+# */ /* Created: 2017/03/11 14:54:18 by ariard #+# #+# */
/* Updated: 2017/03/11 15:54:52 by ariard ### ########.fr */ /* Updated: 2017/03/13 14:08:09 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */
/* Updated: 2017/03/11 15:56:12 by ariard ### ########.fr */ /* Updated: 2017/03/13 14:25:12 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,6 +21,10 @@ int issubshell(t_btree **ast, t_list **lst)
if (*ast) if (*ast)
{ {
node = (*ast)->item; node = (*ast)->item;
if ((node->type == TK_NEWLINE || node->type == TK_SEMI
|| node->type == TK_AMP || node->type == TK_PIPE)
&& issubshell(&(*ast)->right, lst) == 1)
return (1);
if (node->type == SUBSHELL && node->full == 0) if (node->type == SUBSHELL && node->full == 0)
return (1); return (1);
if (node->type == TK_LBRACE && node->full == 0) if (node->type == TK_LBRACE && node->full == 0)

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */
/* Updated: 2017/03/11 16:05:58 by ariard ### ########.fr */ /* Updated: 2017/03/12 00:50:41 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/03/11 16:08:26 by ariard ### ########.fr */ /* Updated: 2017/03/13 14:37:11 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -78,6 +78,7 @@ int build_tree(t_btree **ast, t_list **lst)
{ {
if ((isseparator(token, cache) && g_treematch[i].type == token->type)) if ((isseparator(token, cache) && g_treematch[i].type == token->type))
{ {
DG("build %s", read_state(g_treematch[i].type));
cache = token->type; cache = token->type;
return (g_treematch[i].add(ast, lst)); return (g_treematch[i].add(ast, lst));
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */ /* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
/* Updated: 2017/03/13 16:10:14 by jhalford ### ########.fr */ /* Updated: 2017/03/13 16:12:23 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */