This commit is contained in:
Antoine Riard 2017-03-15 19:57:08 +01:00
parent 80cfacb577
commit 95186a124f
16 changed files with 68 additions and 30 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/15 01:07:00 by ariard ### ########.fr */ /* Updated: 2017/03/15 17:25:13 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -116,7 +116,6 @@ int add_pattern(t_btree **ast, t_list **lst);
int add_subshell_cmd(t_btree **ast, t_list **lst); int add_subshell_cmd(t_btree **ast, t_list **lst);
int add_subshell_sep(t_btree **ast, t_list **lst); int add_subshell_sep(t_btree **ast, t_list **lst);
int add_func_cmd(t_btree **ast, t_list **lst); int add_func_cmd(t_btree **ast, t_list **lst);
int add_func_sep(t_btree **ast, t_list **lst);
int add_one_func(t_btree **ast, t_list **lst); int add_one_func(t_btree **ast, t_list **lst);
int add_pipe(t_btree **ast, t_list **lst); int add_pipe(t_btree **ast, t_list **lst);
int add_null(t_btree **ast, t_list **lst); int add_null(t_btree **ast, t_list **lst);
@ -178,10 +177,10 @@ union u_astdata
struct s_astnode struct s_astnode
{ {
int pattern; int pattern;
int nest; int nest;
int full; int full;
int cache; int cache;
t_type type; t_type type;
t_astdata data; t_astdata data;
}; };

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
/* Updated: 2017/03/14 22:32:24 by ariard ### ########.fr */ /* Updated: 2017/03/15 18:31:21 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,6 +36,7 @@ t_execf *is_builtin(t_process *p)
{ {
int i; int i;
DG("in builtin");
i = -1; i = -1;
while (g_builtin[++i].name) while (g_builtin[++i].name)
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
/* Updated: 2017/03/08 00:59:53 by ariard ### ########.fr */ /* Updated: 2017/03/15 19:18:02 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/15 02:04:30 by ariard ### ########.fr */ /* Updated: 2017/03/15 18:46:46 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 02:45:15 by wescande #+# #+# */ /* Created: 2017/03/08 02:45:15 by wescande #+# #+# */
/* Updated: 2017/03/08 03:22:34 by wescande ### ########.fr */ /* Updated: 2017/03/15 18:57:03 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,13 +14,21 @@
t_btree *is_function(t_process *p) t_btree *is_function(t_process *p)
{ {
t_list *tmp; t_list *tmp;
t_btree **ast;
char **av;
tmp = data_singleton()->lst_func; tmp = data_singleton()->lst_func;
while (tmp) while (tmp)
{ {
if (!ft_strcmp(((t_astnode *)tmp->content)->data.str, p->data.cmd.av[0])) ast = tmp->content;
return (btree_map(p->data.subshell.content, node_copy)); if (!*ast)
return (NULL);
av = token_to_argv(((t_astnode *)(*ast)->item)->data.cmd.token, 1);
if (!av || !av[0])
return (NULL);
if (!ft_strcmp(av[0], p->data.cmd.av[0]))
return (btree_map((*ast)->right, node_copy));
tmp = tmp->next; tmp = tmp->next;
} }
return (NULL); return (NULL);

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ /* Created: 2017/03/08 03:38:36 by wescande #+# #+# */
/* Updated: 2017/03/15 01:24:26 by ariard ### ########.fr */ /* Updated: 2017/03/15 16:48:40 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,7 +30,8 @@ void *node_copy(void *data)
new->data.cmd.redir = ft_lstmap(old->data.cmd.redir, &redir_copy); new->data.cmd.redir = ft_lstmap(old->data.cmd.redir, &redir_copy);
new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy);
} }
if (old->type == TK_FOR || old->type == TK_PAREN_OPEN || old->type == TK_CASE) if (old->type == TK_FOR || old->type == TK_PAREN_OPEN || old->type == TK_CASE
|| old->type == FNAME)
new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy);
return (new); return (new);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ /* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */
/* Updated: 2017/03/14 00:04:09 by jhalford ### ########.fr */ /* Updated: 2017/03/15 18:13:05 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,8 +14,10 @@
int plaunch_brace(t_process *p) int plaunch_brace(t_process *p)
{ {
DG(" do brace");
if (IS_PIPESINGLE(*p)) if (IS_PIPESINGLE(*p))
{ {
DG("is pipgesingle");
if (process_redirect(p)) if (process_redirect(p))
set_exitstatus(1, 1); set_exitstatus(1, 1);
else else

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */ /* Updated: 2017/03/15 19:17:01 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,6 +14,7 @@
static int do_function(t_process *p) static int do_function(t_process *p)
{ {
DG("do function");
ft_exec(&p->data.function.content); ft_exec(&p->data.function.content);
return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/15 00:57:31 by ariard ### ########.fr */ /* Updated: 2017/03/15 18:20:38 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -34,6 +34,7 @@ static int process_set_spec(t_process *p, t_btree *ast)
if (!ast) if (!ast)
return (0); return (0);
item = ast->item; item = ast->item;
DG("process set spec");
while (g_setprocessmap[++i].id) while (g_setprocessmap[++i].id)
if (item->type == g_setprocessmap[i].id) if (item->type == g_setprocessmap[i].id)
{ {

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */
/* Updated: 2017/03/14 21:25:01 by ariard ### ########.fr */ /* Updated: 2017/03/15 18:48:13 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,7 +27,8 @@ int pset_cmd(t_process *p, t_btree *ast)
p->type = PROCESS_FILE; p->type = PROCESS_FILE;
if ((func = is_function(p))) if ((func = is_function(p)))
{ {
p->data.subshell.content = func; btree_print(STDBUG, func, &ft_putast);
p->data.function.content = func;
p->type = PROCESS_FUNCTION; p->type = PROCESS_FUNCTION;
} }
else if ((p->data.cmd.execf = is_builtin(p))) else if ((p->data.cmd.execf = is_builtin(p)))

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/15 02:12:28 by ariard ### ########.fr */ /* Updated: 2017/03/15 16:46:16 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -95,6 +95,7 @@ int add_cmd(t_btree **ast, t_list **lst)
if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD || token->type == TK_NAME) if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD || token->type == TK_NAME)
{ {
DG("type is %s", read_state(node->type)); DG("type is %s", read_state(node->type));
DG("data is %s", token->data);
ft_ld_pushback(&node->data.cmd.token, ft_ld_pushback(&node->data.cmd.token,
gen_tab(token->data, token->esc, token->esc2, 1)); gen_tab(token->data, token->esc, token->esc2, 1));
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
/* Updated: 2017/03/15 00:26:57 by ariard ### ########.fr */ /* Updated: 2017/03/15 19:50:49 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,7 +24,6 @@ int isfunc_name(t_btree **ast, t_list **lst)
if (node->type == CMD && token->type == TK_PAREN_OPEN) if (node->type == CMD && token->type == TK_PAREN_OPEN)
{ {
node->type = FNAME; node->type = FNAME;
node->data.str = ft_strdup(token->data);
return (1); return (1);
} }
if (node->type == FNAME && token->type == TK_PAREN_CLOSE if (node->type == FNAME && token->type == TK_PAREN_CLOSE
@ -81,17 +80,39 @@ int add_func_cmd(t_btree **ast, t_list **lst)
return (add_cmd(&(*ast)->right, lst)); return (add_cmd(&(*ast)->right, lst));
} }
int add_func_sep(t_btree **ast, t_list **lst) t_list *is_already_func(t_btree **new)
{ {
return (add_sep(&(*ast)->right, lst)); t_list *tmp;
t_btree **ast;
char **new_name;
char **old_name;
tmp = data_singleton()->lst_func;
new_name = token_to_argv(((t_astnode *)(*new)->item)->data.cmd.token, 1);
while (tmp)
{
ast = tmp->content;
if (!*ast)
return (NULL);
old_name = token_to_argv(((t_astnode *)(*ast)->item)->data.cmd.token, 1);
if (!new_name || !new_name[0] || !old_name || !old_name[0])
return (NULL);
if (!ft_strcmp(new_name[0], old_name[0]))
return (tmp);
tmp = tmp->next;
}
return (NULL);
} }
int add_one_func(t_btree **ast, t_list **lst) int add_one_func(t_btree **ast, t_list **lst)
{ {
t_btree *func_ast; t_btree *func_ast;
t_list *old_func;
(void)lst; (void)lst;
func_ast = btree_map(*ast, node_copy); func_ast = btree_map(*ast, node_copy);
if ((old_func = is_already_func(&func_ast)))
ft_lst_delif(&data_singleton()->lst_func, old_func->content, &ft_addrcmp, &ast_free);
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast)));
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/15 19:12:07 by ariard #+# #+# */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */
/* Updated: 2017/03/15 01:41:06 by ariard ### ########.fr */ /* Updated: 2017/03/15 18:57:13 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,7 +27,7 @@ int add_sep(t_btree **ast, t_list **lst)
else if (issubshell(ast, lst)) else if (issubshell(ast, lst))
return (add_subshell_sep(ast, lst)); return (add_subshell_sep(ast, lst));
else if (isfunc(ast, lst)) else if (isfunc(ast, lst))
return (add_func_sep(ast, lst)); return (add_subshell_sep(ast, lst));
else if (isbang_sep(ast, lst)) else if (isbang_sep(ast, lst))
return (add_bang_sep(ast, lst)); return (add_bang_sep(ast, lst));
if (!*ast) if (!*ast)

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */ /* Created: 2017/03/11 16:17:38 by ariard #+# #+# */
/* Updated: 2017/03/13 17:42:06 by ariard ### ########.fr */ /* Updated: 2017/03/15 17:25:09 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -56,7 +56,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
else else
parser->state = UNDEFINED; parser->state = UNDEFINED;
build_tree(ast, token); build_tree(ast, token);
btree_print(STDBUG, *ast, &ft_putast); // btree_print(STDBUG, *ast, &ft_putast);
if ((end_instruction(&parser->stack) && !(*token)->next)) if ((end_instruction(&parser->stack) && !(*token)->next))
insert_linebreak(token); insert_linebreak(token);
else else

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
/* Updated: 2017/03/14 22:11:43 by ariard ### ########.fr */ /* Updated: 2017/03/15 16:33:57 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,6 +14,8 @@
char *read_state(t_sym current) char *read_state(t_sym current)
{ {
if (current == FNAME)
return ("FNAME");
if (current == PIPE_CLOSE_SEQUENCE) if (current == PIPE_CLOSE_SEQUENCE)
return ("PIPE_CLOSE_SEQUENCE"); return ("PIPE_CLOSE_SEQUENCE");
if (current == TK_BANG) if (current == TK_BANG)