divers modifs + better tree case
This commit is contained in:
parent
de5f4b2a46
commit
fc8dcb8d24
8 changed files with 31 additions and 106 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/14 22:59:57 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/14 23:09:30 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,6 +17,8 @@
|
|||
# include "libft.h"
|
||||
# include "builtin_read.h"
|
||||
|
||||
# define BT_EXPORT_LP (1 << 0)
|
||||
|
||||
t_execf *is_builtin(t_process *p);
|
||||
int builtin_export(const char *path, char *const av[], char *const envp[]);
|
||||
int builtin_unset(const char *path, char *const av[], char *const envp[]);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 11:12:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/14 22:55:04 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/14 23:55:40 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,6 +30,8 @@ int exec_var(t_btree **ast)
|
|||
node = (*ast)->item;
|
||||
av = token_to_argv(node->data.cmd.token, 1);
|
||||
set_var(av[0], &var, &value);
|
||||
if (ft_getenv(data_singleton()->env, var))
|
||||
return (0);
|
||||
builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,29 +6,11 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 19:02:23 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/15 00:04:09 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
/*
|
||||
int exec_case(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
char **av;
|
||||
t_exec *exec;
|
||||
|
||||
(void)ast;
|
||||
exec = &data_singleton()->exec;
|
||||
exec->attrs &= ~EXEC_CASE_BRANCH;
|
||||
|
||||
node = (*ast)->item;
|
||||
av = token_to_argv(node->data.cmd.wordlist, 1);
|
||||
exec->case_pattern = av;
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
|
||||
static int do_case(t_process *p)
|
||||
{
|
||||
t_exec *exec;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 17:34:43 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/15 00:03:12 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,10 +30,9 @@ static int do_for(t_process *p)
|
|||
av = token_to_argv(temp, 1);
|
||||
while (av[++i])
|
||||
{
|
||||
builtin_setenv("setenv", (char*[]){var, av[i], 0},
|
||||
data_singleton()->local_var);
|
||||
builtin_setenv("setenv", (char*[]){"local" ,var, av[i], 0},
|
||||
NULL);
|
||||
ft_exec(&p->data.d_for.content);
|
||||
i++;
|
||||
}
|
||||
temp = temp->next;
|
||||
}
|
||||
|
|
@ -65,33 +64,3 @@ int plaunch_for(t_process *p)
|
|||
do_for(p);
|
||||
return (0);
|
||||
}
|
||||
/*
|
||||
int exec_for(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_ld *temp;
|
||||
char **av;
|
||||
char *var;
|
||||
int i;
|
||||
|
||||
node = (*ast)->item;
|
||||
temp = node->data.cmd.wordlist;
|
||||
var = ((char **)(temp->content))[0];
|
||||
if (ft_isdigit(var[0]))
|
||||
return (error_badidentifier(var));
|
||||
temp = temp->next;
|
||||
while (temp)
|
||||
{
|
||||
i = 0;
|
||||
av = token_to_argv(temp, 1);
|
||||
while (av[i])
|
||||
{
|
||||
builtin_setenv("setenv", (char*[]){var, av[i], 0},
|
||||
data_singleton()->local_var);
|
||||
ft_exec(&(*ast)->right);
|
||||
i++;
|
||||
}
|
||||
temp = temp->next;
|
||||
}
|
||||
return (0);
|
||||
}*/
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/14 23:06:10 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/15 00:07:41 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -71,8 +71,8 @@ int handle_instruction(int fd)
|
|||
}
|
||||
}
|
||||
btree_print(STDBUG, ast, &ft_putast);
|
||||
if (ft_exec(&ast))
|
||||
return (2);
|
||||
// if (ft_exec(&ast))
|
||||
// return (2);
|
||||
instruction_free(&token, &parser, &ast);
|
||||
if (SH_IS_INTERACTIVE(data_singleton()->opts) && *lexer.str)
|
||||
ft_add_str_in_history(lexer.str);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/04 20:42:13 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/14 21:45:03 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/15 00:46:52 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,24 +25,8 @@ int iscase(t_btree **ast, t_list **lst)
|
|||
|| node->type == TK_AMP || node->type == TK_PIPE)
|
||||
&& iscase(&(*ast)->right, lst) == 1)
|
||||
return (1);
|
||||
if (node->type == TK_CASE)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int iscase_pattern(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_token *token;
|
||||
|
||||
node = NULL;
|
||||
token = (*lst)->content;
|
||||
if (*ast)
|
||||
{
|
||||
node = (*ast)->item;
|
||||
if ((node->type == TK_CASE || node->type == TK_PAREN_OPEN)
|
||||
&& token->type == TK_WORD && node->pattern == 0)
|
||||
&& node->pattern == 1 && node->full == 0)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
|
|
@ -58,7 +42,7 @@ int iscase_branch(t_btree **ast, t_list **lst)
|
|||
if (*ast)
|
||||
{
|
||||
node = (*ast)->item;
|
||||
if ((node->type == TK_PAREN_OPEN || node->type == TK_CASE)
|
||||
if ((node->type == TK_PAREN_OPEN)
|
||||
&& node->nest == 0 && token->type == TK_PAREN_OPEN)
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -81,23 +65,10 @@ int add_case_cmd(t_btree **ast, t_list **lst)
|
|||
else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN
|
||||
&& node->nest == 0)
|
||||
return ((node->full = 1));
|
||||
else if ((token->type == TK_ESAC || token->type == TK_PAREN_CLOSE)
|
||||
else if ((token->type == TK_ESAC)
|
||||
&& node->nest == 0)
|
||||
return ((node->full = 1));
|
||||
else if (token->type == TK_PAREN_CLOSE)
|
||||
return (0);
|
||||
return (add_cmd(&(*ast)->right, lst));
|
||||
}
|
||||
|
||||
int add_pattern(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_token *token;
|
||||
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
DG("token type is %s", read_state(token->type));
|
||||
DG("node type is %s", read_state(node->type));
|
||||
ft_ld_pushback(&node->data.cmd.token,
|
||||
gen_tab(token->data, token->esc, token->esc2, 1));
|
||||
node->pattern = 1;
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/14 22:22:15 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/15 00:45:46 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,7 +21,6 @@ t_distrostree g_distrostree[] =
|
|||
{&isloop, &add_loop_cmd},
|
||||
{&iscondition_branch, &add_branch},
|
||||
{&iscondition, &add_condition_cmd},
|
||||
{&iscase_pattern, &add_pattern},
|
||||
{&iscase, &add_case_cmd},
|
||||
{&iscase_branch, &add_branch},
|
||||
{&issubshell, &add_subshell_cmd},
|
||||
|
|
@ -40,7 +39,7 @@ int superflous_token(t_btree **ast, t_list **lst)
|
|||
if (*lst)
|
||||
{
|
||||
token = (*lst)->content;
|
||||
if (token->type == TK_IN || token->type == TK_DSEMI)
|
||||
if (token->type == TK_IN)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
|
|
@ -49,12 +48,16 @@ int superflous_token(t_btree **ast, t_list **lst)
|
|||
static int no_del_token(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_token *token;
|
||||
|
||||
(void)lst;
|
||||
node = NULL;
|
||||
token = (*lst)->content;
|
||||
if (*ast)
|
||||
{
|
||||
node = (*ast)->item;
|
||||
if (token->type == TK_WORD && (node->type == TK_CASE
|
||||
|| node->type == TK_PAREN_OPEN))
|
||||
return (0);
|
||||
if (node->type != TK_DO && node->type != TK_THEN
|
||||
&& node->type != CMD && node->type != REDIR
|
||||
&& node->type != TK_ASSIGNMENT_WORD)
|
||||
|
|
@ -70,7 +73,7 @@ int add_cmd(t_btree **ast, t_list **lst)
|
|||
int i;
|
||||
|
||||
i = -1;
|
||||
while (++i < 16)
|
||||
while (++i < 15)
|
||||
{
|
||||
if (g_distrostree[i].test(ast, lst) == 1)
|
||||
{
|
||||
|
|
@ -87,17 +90,13 @@ int add_cmd(t_btree **ast, t_list **lst)
|
|||
if (token->type == TK_IF)
|
||||
add_if(ast, lst);
|
||||
else if (token->type != TK_WORD)
|
||||
{
|
||||
DG("type is %s", read_state(token->type));
|
||||
node->type = token->type;
|
||||
}
|
||||
else
|
||||
else if (node->type != TK_CASE && node->type != TK_PAREN_OPEN)
|
||||
node->type = CMD;
|
||||
if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD)
|
||||
{
|
||||
DG("token data is %s", token->data);
|
||||
ft_ld_pushback(&node->data.cmd.token,
|
||||
gen_tab(token->data, token->esc, token->esc2, 1));
|
||||
}
|
||||
if (token->type == TK_WORD)
|
||||
node->pattern = 1;
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/13 19:27:58 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/15 00:26:57 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue