exec func + correction syntax if
This commit is contained in:
parent
7b690e7e4c
commit
e8b9befea2
19 changed files with 102 additions and 90 deletions
|
|
@ -72,6 +72,7 @@ exec/exec_bang.c\
|
|||
exec/exec_case_branch.c\
|
||||
exec/exec_elif.c\
|
||||
exec/exec_else.c\
|
||||
exec/exec_func.c\
|
||||
exec/exec_leaf.c\
|
||||
exec/exec_or_if.c\
|
||||
exec/exec_pipe.c\
|
||||
|
|
|
|||
1
42sh/file
Normal file
1
42sh/file
Normal file
|
|
@ -0,0 +1 @@
|
|||
YOLO
|
||||
1
42sh/file1
Normal file
1
42sh/file1
Normal file
|
|
@ -0,0 +1 @@
|
|||
nous
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/22 16:35:00 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/23 16:27:10 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -227,5 +227,6 @@ int exec_var(t_btree **ast);
|
|||
int exec_case_branch(t_btree **ast);
|
||||
int exec_math(t_btree **ast);
|
||||
int exec_bang(t_btree **ast);
|
||||
int exec_func(t_btree **ast);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/17 18:54:00 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/23 01:08:14 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/23 15:06:18 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,8 +25,6 @@ static char *do_math(char *value, char operator, char *operand)
|
|||
|
||||
ope1 = ft_atoi(value);
|
||||
ope2 = ft_atoi(operand);
|
||||
DG("value %s -> %i", value, ope1);
|
||||
DG("operand %s -> %i", operand, ope2);
|
||||
if ((operator == '/') && ope2 == 0)
|
||||
return (SH_ERR(MATHERR_4) ? NULL : NULL);
|
||||
if ((operator == '%') && ope2 == 0)
|
||||
|
|
@ -36,7 +34,6 @@ static char *do_math(char *value, char operator, char *operand)
|
|||
ope1 = (operator == '/') ? ope1 / ope2 : ope1;
|
||||
ope1 = (operator == '*') ? ope1 * ope2 : ope1;
|
||||
ope1 = (operator == '%') ? ope1 % ope2 : ope1;
|
||||
DG("output=%s (%i)", ft_itoa(ope1), ope1);
|
||||
return (ft_itoa(ope1));
|
||||
}
|
||||
|
||||
|
|
@ -48,8 +45,10 @@ int builtin_math(const char *path, char *const av[], char *const envp[])
|
|||
|
||||
(void)path;
|
||||
(void)envp;
|
||||
if (!av || !av[1] || !av[2] || !av[3] || av[4])
|
||||
DG();
|
||||
if (!av || !av[0] || !av[1] || !av[2] || !av[3] || av[4])
|
||||
return (SH_ERR(MATHERR_0));
|
||||
DG();
|
||||
value = ft_getenv(data_singleton()->local_var, av[1]);
|
||||
operator = av[2][0];
|
||||
if (!(ft_strchr("+-/*%", operator)))
|
||||
|
|
|
|||
56
42sh/src/exec/exec_func.c
Normal file
56
42sh/src/exec/exec_func.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_func.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/23 16:25:23 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/23 16:27:57 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
t_list *is_already_func(t_btree **new)
|
||||
{
|
||||
t_list *tmp;
|
||||
t_btree **ast;
|
||||
char **new_name;
|
||||
char **old_name;
|
||||
int ret;
|
||||
|
||||
tmp = data_singleton()->lst_func;
|
||||
new_name = token_to_argv(((t_astnode *)(*new)->item)->data.cmd.token, 1);
|
||||
ret = 1;
|
||||
while (tmp && ret)
|
||||
{
|
||||
if ((ast = tmp->content) && !*ast)
|
||||
break ;
|
||||
old_name = token_to_argv(((t_astnode *)
|
||||
(*ast)->item)->data.cmd.token, 1);
|
||||
ret = (new_name && new_name[0] && old_name && old_name[0]
|
||||
&& !ft_strcmp(new_name[0], old_name[0])) ? 0 : 1;
|
||||
ft_tabdel(&old_name);
|
||||
tmp = (ret) ? tmp->next : tmp;
|
||||
}
|
||||
ft_tabdel(&new_name);
|
||||
if (!ret)
|
||||
return (tmp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int exec_func(t_btree **ast)
|
||||
{
|
||||
t_btree *func_ast;
|
||||
t_list *old_func;
|
||||
|
||||
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, &tree_func_free);
|
||||
}
|
||||
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast)));
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/22 19:52:58 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/23 16:25:01 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -32,6 +32,7 @@ t_itof g_execmap[] =
|
|||
{SUBSHELL, &exec_leaf},
|
||||
{TK_LBRACE, &exec_leaf},
|
||||
{TK_BANG, &exec_bang},
|
||||
{FNAME, &exec_func},
|
||||
{CMD, &exec_leaf},
|
||||
{0, 0},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 03:38:36 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/22 21:50:06 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/23 16:28:41 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,13 +25,7 @@ void *node_copy(void *data)
|
|||
new->full = old->full;
|
||||
new->type = old->type;
|
||||
new->pattern = old->pattern;
|
||||
if (old->type == CMD || old->type == TK_ASSIGNMENT_WORD)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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.redir = ft_lstmap(old->data.cmd.redir, &redir_copy);
|
||||
new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy);
|
||||
return (new);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/23 06:19:00 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/23 15:06:30 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,24 +17,14 @@
|
|||
|
||||
int plaunch_function(t_process *p)
|
||||
{
|
||||
static int protection= 0;
|
||||
/* char *val; */
|
||||
|
||||
/* if (ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) > FUNC_LVL) */
|
||||
/* return(SH_ERR(FUNCERR_0)); */
|
||||
static int protection;
|
||||
|
||||
if (!protection)
|
||||
protection = 0;
|
||||
if (protection >= FUNC_LVL)
|
||||
return(SH_ERR(FUNCERR_0));
|
||||
protection++;
|
||||
|
||||
// jack faut qu on parle
|
||||
/* val = ft_itoa(ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) + 1); */
|
||||
/* builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", val, NULL}, NULL); */
|
||||
/* ft_strdel(&val); */
|
||||
ft_exec(&p->data.function.content);
|
||||
/* val = ft_itoa(ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) - 1); */
|
||||
/* builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", val, NULL}, NULL); */
|
||||
/* ft_strdel(&val); */
|
||||
protection--;
|
||||
return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/21 17:40:35 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/23 16:06:39 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -37,6 +37,7 @@ int process_redirect(t_process *p)
|
|||
while (redirs)
|
||||
{
|
||||
redir = redirs->content;
|
||||
DG("redir type is %s", read_state(redir->type));
|
||||
if (redir->n > 9)
|
||||
return (bad_fd(redir->n));
|
||||
i = -1;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/20 12:41:54 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/23 06:29:11 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/23 14:48:58 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/23 06:19:27 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/23 14:57:19 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -66,9 +66,6 @@ int data_init(int ac, char **av)
|
|||
data->lst_func = NULL;
|
||||
lexer_init(&data->lexer);
|
||||
parser_init(&data->parser);
|
||||
/* if (!ft_getenv(data_singleton()->env, "FUNC_LVL")) */
|
||||
/* builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", "-1", */
|
||||
/* NULL}, NULL); */
|
||||
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
|
||||
{
|
||||
term_name = "dumb";
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/23 00:28:58 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/23 15:16:07 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -49,6 +49,7 @@ static int handle_instruction(t_list **token, t_btree **ast)
|
|||
else if (ret > 0)
|
||||
break ;
|
||||
}
|
||||
btree_print(STDBUG, *ast, &ft_putast);
|
||||
if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
|
||||
exit(1);
|
||||
else if (data->parser.state != SUCCESS)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/17 19:31:52 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/23 16:29:12 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/22 19:21:58 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/23 16:26:09 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -73,53 +73,6 @@ int add_func_cmd(t_btree **ast, t_list **lst)
|
|||
|| token->type == TK_FI || token->type == TK_RBRACE
|
||||
|| token->type == TK_PAREN_CLOSE) && node->type == FNAME
|
||||
&& node->nest == 0)
|
||||
{
|
||||
node->full = 1;
|
||||
add_one_func(ast, lst);
|
||||
}
|
||||
return (add_cmd(&(*ast)->right, lst));
|
||||
}
|
||||
|
||||
t_list *is_already_func(t_btree **new)
|
||||
{
|
||||
t_list *tmp;
|
||||
t_btree **ast;
|
||||
char **new_name;
|
||||
char **old_name;
|
||||
int ret;
|
||||
|
||||
tmp = data_singleton()->lst_func;
|
||||
new_name = token_to_argv(((t_astnode *)(*new)->item)->data.cmd.token, 1);
|
||||
ret = 1;
|
||||
while (tmp && ret)
|
||||
{
|
||||
if ((ast = tmp->content) && !*ast)
|
||||
break ;
|
||||
old_name = token_to_argv(((t_astnode *)
|
||||
(*ast)->item)->data.cmd.token, 1);
|
||||
ret = (new_name && new_name[0] && old_name && old_name[0]
|
||||
&& !ft_strcmp(new_name[0], old_name[0])) ? 0 : 1;
|
||||
ft_tabdel(&old_name);
|
||||
tmp = (ret) ? tmp->next : tmp;
|
||||
}
|
||||
ft_tabdel(&new_name);
|
||||
if (!ret)
|
||||
return (tmp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int add_one_func(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_btree *func_ast;
|
||||
t_list *old_func;
|
||||
|
||||
(void)lst;
|
||||
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, &tree_func_free);
|
||||
}
|
||||
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast)));
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/17 17:54:49 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/23 16:29:03 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/11 15:58:38 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/22 19:00:06 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/23 16:03:22 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/17 19:50:08 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/23 15:26:31 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -84,6 +84,7 @@ int build_tree(t_btree **ast, t_list **lst)
|
|||
i = 0;
|
||||
token = (*lst)->content;
|
||||
check_cache(token, cache);
|
||||
DG("new");
|
||||
while (g_treematch[i].type)
|
||||
{
|
||||
if ((isseparator(token, cache) && g_treematch[i].type == token->type))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/11 16:11:21 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/22 19:00:15 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/23 16:04:51 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -842,6 +842,21 @@ t_stackmatch g_stackmatch[] =
|
|||
{COMPLETE_CONDITION, COMPLETE_COMMANDS},
|
||||
{COMPLETE_CONDITION, COMPLETE_CONDITION},
|
||||
{COMPLETE_CONDITION, SEQUENCE},
|
||||
{COMPLETE_CONDITION, TK_WHILE},
|
||||
{COMPLETE_CONDITION, TK_UNTIL},
|
||||
{COMPLETE_CONDITION, TK_DO},
|
||||
{COMPLETE_CONDITION, TK_IF},
|
||||
{COMPLETE_CONDITION, TK_ELIF},
|
||||
{COMPLETE_CONDITION, TK_THEN},
|
||||
{COMPLETE_CONDITION, TK_ELSE},
|
||||
{COMPLETE_CONDITION, COMPOUND_LIST},
|
||||
{COMPLETE_CONDITION, CASE_LIST_NS},
|
||||
{COMPLETE_CONDITION, TK_BANG},
|
||||
{COMPLETE_CONDITION, SEPARATOR_OP},
|
||||
{COMPLETE_CONDITION, NEWLINE_LIST},
|
||||
{COMPLETE_CONDITION, AND_OR_MAJOR},
|
||||
{COMPLETE_CONDITION, CASE_LIST_NS},
|
||||
{COMPLETE_CONDITION, FUNC_NAME},
|
||||
{FNAME, LINEBREAK},
|
||||
{FNAME, TK_PAREN_OPEN},
|
||||
{FNAME, TK_LBRACE},
|
||||
|
|
|
|||
Loading…
Reference in a new issue