merge fixed

This commit is contained in:
ariard@student.42.fr 2017-03-01 16:28:44 +01:00
commit 9f9d799bbe
21 changed files with 176 additions and 67 deletions

View file

@ -74,12 +74,14 @@ exec/exec_redir.c\
exec/exec_semi.c\
exec/exec_until.c\
exec/exec_while.c\
exec/exec_var.c\
exec/exec_for.c\
exec/exec_case.c\
exec/exec_case_branch.c\
exec/fd_is_valid.c\
exec/ft_exec.c\
exec/ft_findexec.c\
exec/launch_process.c\
exec/loop_del.c\
exec/loop_exec.c\
exec/process_redirect.c\
exec/process_reset.c\
exec/process_resetfds.c\

View file

@ -35,8 +35,6 @@
# define IS_PIPEEND(a) (a & PROCESS_PIPEEND)
# define IS_PIPESINGLE(a) ((a & PROCESS_PIPESTART) && (a & PROCESS_PIPEEND))
# define SCRIPT_LOOP (1 << 0)
# include "libft.h"
# include "types.h"
# include "job_control.h"
@ -53,7 +51,9 @@ struct s_process
int toclose;
int status;
t_flag attributes;
t_flag script;
t_condition if_branch;
t_condition case_branch;
char *case_pattern;
};
struct s_exec
@ -102,7 +102,10 @@ int exec_elif(t_btree **ast);
int exec_else(t_btree **ast);
int exec_until(t_btree **ast);
int exec_default(t_btree **ast);
int exec_var(t_btree **ast);
int exec_for(t_btree **ast);
int exec_case(t_btree **ast);
int exec_case_branch(t_btree **ast);
int launch_process(t_process *p);
int process_setexec(t_type type, t_process *p);
@ -128,7 +131,6 @@ void set_exitstatus(int status, int override);
void ast_free(void *data, size_t content_size);
char **token_to_argv(t_astnode *node);
#endif

View file

@ -65,6 +65,8 @@ struct s_data
t_comp *comp;
t_exec exec;
t_jobc jobc;
char **local_var;
t_list *lst_func;
};
extern t_stof g_builtins[];

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
/* Updated: 2017/03/01 16:24:58 by ariard ### ########.fr */
/* Updated: 2017/03/01 16:28:29 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -114,15 +114,28 @@ int add_condition_sep(t_btree **ast, t_list **lst);
int add_branch(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_case_cmd(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_subshell_cmd(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_sep(t_btree **ast, t_list **lst);
int add_one_func(t_btree **ast, t_list **lst);
int isloop(t_btree **ast, t_list **lst);
int isdir(t_btree **ast, t_list **lst);
int iscase(t_btree **ast, t_list **lst);
int iscondition(t_btree **ast, t_list **lst);
int issubshell(t_btree **ast, t_list **lst);
int isfunc(t_btree **ast, t_list **lst);
int join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast);
int isloop(t_btree **ast);
int isdir(t_btree **ast);
int iscondition(t_btree **ast, t_list **list);
int isdir_sep(t_list **list);
int isdir_word(t_btree **ast, t_list **list);
int join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast);
/*
* Build AST
*
@ -158,7 +171,7 @@ union u_astdata
struct s_astnode
{
int pattern;
int nest;
int full;
t_type type;

View file

@ -35,6 +35,7 @@ typedef union u_astdata t_astdata;
typedef union u_word t_word;
typedef long long t_type;
typedef int t_condition;
typedef struct s_job t_job;
typedef struct s_execmap t_execmap;
typedef struct s_redirmap t_redirmap;

View file

@ -1,27 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* loop_exec.c :+: :+: :+: */
/* exec_if.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 21:02:10 by ariard #+# #+# */
/* Updated: 2017/01/31 19:27:49 by ariard ### ########.fr */
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
/* Updated: 2017/02/20 22:31:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
int loop_exec(t_list *list_ast)
int exec_case(t_btree **ast)
{
t_astnode *node;
char **av;
// DG("begin exec loop");
// ft_print_all_ast(*list_ast);
while (list_ast)
{
if (ft_exec((t_btree **)list_ast->content))
return (1);
list_ast = list_ast->next;
}
data_singleton()->exec.process.case_branch = 0;
node = (*ast)->item;
av = token_to_argv(node);
data_singleton()->exec.process.case_pattern = av[0];
return (0);
}

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_if.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
/* Updated: 2017/02/20 22:31:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
int exec_case_branch(t_btree **ast)
{
t_astnode *node;
char **av;
if (data_singleton()->exec.process.case_branch == 1)
return (0);
node = (*ast)->item;
av = token_to_argv(node);
if (ft_strcmp(av[0], data_singleton()->exec.process.case_pattern) == 1)
{
data_singleton()->exec.process.case_branch = 1;
ft_exec(&(*ast)->right);
}
return (0);
}

View file

@ -12,7 +12,7 @@
#include "exec.h"
static char **token_to_argv(t_astnode *node)
char **token_to_argv(t_astnode *node)
{
char **my_tab;
int index;
@ -20,7 +20,7 @@ static char **token_to_argv(t_astnode *node)
char **content;
t_ld *ld;
if (node->type == TK_COMMAND)
if (node->type == TK_WORD || node->type == TK_ASSIGNEMENT_WORD)
{
ld = node->data.token;
my_tab = NULL;

View file

@ -14,14 +14,13 @@
int exec_elif(t_btree **ast)
{
int test;
(void)ast;
test = 0;
if (test)
if (data_singleton()->exec.process.if_branch == 1)
return (0);
ft_exec(&(*ast)->left);
if (data_singleton()->exec.process.status == 1)
{
data_singleton()->exec.process.if_branch = 1;
ft_exec(&(*ast)->right);
}
// btree_delone(ast, &ast_free);
return (0);
}

View file

@ -14,7 +14,10 @@
int exec_else(t_btree **ast)
{
ft_exec(&(*ast)->right);
//btree_delone(ast, &ast_free);
if (data_singleton()->exec.process.if_branch == 0)
{
data_singleton()->exec.process.if_branch = 1;
ft_exec(&(*ast)->right);
}
return (0);
}

35
42sh/src/exec/exec_for.c Normal file
View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_until.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
/* Updated: 2017/02/06 20:42:21 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
int exec_for(t_btree **ast)
{
t_astnode *node;
t_list *temp;
// char **av = NULL;
char *var;
node = (*ast)->item;
temp = node->data.wordlist;
var = temp->content;
builtin_setenv("setenv", (char*[]){var, 0}, data_singleton()->local_var);
while (temp)
{
//process expansion av = token_to_char(temp->content)
builtin_setenv("setenv", (char*[]){var, 0}, data_singleton()->local_var);
ft_exec(&(*ast)->right);
temp = temp->next;
}
return (0);
}

15
42sh/src/exec/exec_func.c Normal file
View file

@ -0,0 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_while.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
/* Updated: 2017/02/06 22:05:35 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"

View file

@ -14,7 +14,12 @@
int exec_if(t_btree **ast)
{
ft_exec(&(*ast)->right);
// btree_delone(ast, &ast_free);
data_singleton()->exec.process.if_branch = 0;
ft_exec(&(*ast)->left);
if (data_singleton()->exec.process.status == 1)
{
data_singleton()->exec.process.if_branch = 1;
ft_exec(&(*ast)->right);
}
return (0);
}

View file

@ -14,12 +14,11 @@
int exec_until(t_btree **ast)
{
int test;
test = 0;
while (test++ != 10)
ft_exec(&(*ast)->left);
while (data_singleton()->exec.process.status == 0)
{
ft_exec(&(*ast)->right);
// btree_delone(ast, &ast_free);
ft_exec(&(*ast)->left);
}
return (0);
}

View file

@ -1,27 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* loop_del.c :+: :+: :+: */
/* exec_while.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/31 22:39:20 by ariard #+# #+# */
/* Updated: 2017/01/31 23:20:40 by ariard ### ########.fr */
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
/* Updated: 2017/02/06 22:05:35 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
int loop_del(t_list *list_ast)
int exec_var(t_btree **ast)
{
t_list *temp;
t_astnode *node;
char **av;
while (list_ast)
{
btree_del((t_btree **)list_ast->content, &ast_free);
temp = list_ast;
list_ast = list_ast->next;
ft_lstdelone(&temp, NULL);
}
node = (*ast)->item;
av = token_to_argv(node);
builtin_setenv("setenv", av, data_singleton()->local_var);
return (0);
}

View file

@ -14,12 +14,11 @@
int exec_while(t_btree **ast)
{
int test;
test = 10;
while (test--)
ft_exec(&(*ast)->left);
while (data_singleton()->exec.process.status == 1)
{
ft_exec(&(*ast)->right);
// btree_delone(ast, &ast_free);
ft_exec(&(*ast)->left);
}
return (0);
}

View file

@ -23,7 +23,6 @@ int data_init(void)
data->env = ft_sstrdup(environ);
data->comp = NULL;
data->opts = SH_OPTS_JOBC;
data->exec.process.path = NULL;
data->exec.process.av = NULL;
data->exec.process.toclose = STDIN;
@ -45,6 +44,9 @@ int data_init(void)
data->jobc.first_job = NULL;
data->jobc.current_id = 1;
data->local_var = NULL;
data->lst_func = NULL;
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
return (-1);
if (tgetent(NULL, term_name) != 1)

View file

@ -48,7 +48,7 @@ int add_cmd(t_btree **ast, t_list **lst)
my_tab = NULL;
node = (*ast)->item;
node->type = token->type;
if (token->type == TK_WORD)
if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD)
{
DG("add data");
my_tab = ft_sstradd(my_tab, token->data);

View file

@ -23,7 +23,10 @@ int isfunc(t_btree **ast, t_list **lst)
{
node = (*ast)->item;
if (node->type == TK_WORD && token->type == CLOSE_LIST)
{
node->type = FNAME;
add_one_func(ast, lst);
}
if (node->type == FNAME && node->full == 0)
return (1);
if (isfunc(&(*ast)->right, lst) == 1)
@ -62,4 +65,9 @@ int add_func_sep(t_btree **ast, t_list **lst)
return (add_sep(&(*ast)->right, lst));
}
int add_one_func(t_btree **ast, t_list **lst)
{
(void)lst;
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(ast, sizeof(*ast)));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */
/* Updated: 2017/03/01 14:45:19 by ariard ### ########.fr */
/* Updated: 2017/03/01 16:27:17 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -187,7 +187,7 @@ t_aggrematch g_aggrematch[] =
{CLOSE_LIST, PATTERN, CASE_LIST_NS, PATTERN_CASE},
{CLOSE_LIST, FUNC_NAME, FUNCTION_DEFINITION, FUNC_NAME},
{SUBSHELL, ALL, COMPOUND_COMMAND, 0},
{BRACE_CLAUSE, ALL, COMPOUND_COMMAND, 0},
{BRACE_CLAUSE, ALL, COMPOUND_COMMAND, 0},
{COMPOUND_COMMAND, ALL, COMMAND, 0},
{AND_OR_MINOR, PIPE_SEMI_SEQUENCE, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE},
{AND_OR_MINOR, LINEBREAK, AND_OR_MAJOR, 0},

View file

@ -1 +0,0 @@
{ hello }