exec while ok nxt: resoudre bug empty tree
This commit is contained in:
parent
000ae4116a
commit
0dc029406f
33 changed files with 162 additions and 60 deletions
1
42sh/file2
Normal file
1
42sh/file2
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/Users/ariard/Projects/42sh
|
||||||
0
42sh/file3
Normal file
0
42sh/file3
Normal file
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 18:57:16 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 22:32:57 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -85,6 +85,7 @@ int exec_dgreat(t_btree **ast);
|
||||||
int exec_command(t_btree **ast);
|
int exec_command(t_btree **ast);
|
||||||
|
|
||||||
int exec_while(t_btree **ast);
|
int exec_while(t_btree **ast);
|
||||||
|
int exec_list(t_btree **ast);
|
||||||
|
|
||||||
int launch_process(t_process *p);
|
int launch_process(t_process *p);
|
||||||
int process_setexec(t_type type, t_process *p);
|
int process_setexec(t_type type, t_process *p);
|
||||||
|
|
@ -102,4 +103,6 @@ void set_exitstatus(int status);
|
||||||
|
|
||||||
void ast_free(void *data, size_t content_size);
|
void ast_free(void *data, size_t content_size);
|
||||||
|
|
||||||
|
int loop_exec(t_list *list_ast);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 18:05:43 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:41:17 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 19:23:44 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:10:05 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -81,7 +81,7 @@ int shell_single_command(char *command);
|
||||||
|
|
||||||
int read_script(char *file);
|
int read_script(char *file);
|
||||||
int shell_script(void);
|
int shell_script(void);
|
||||||
t_list *shell_get_ast(char *command);
|
t_list **shell_get_ast(char *command);
|
||||||
|
|
||||||
void ft_expand_dollar(char **av, char **env);
|
void ft_expand_dollar(char **av, char **env);
|
||||||
char *ft_findexec(char *path, char *file);
|
char *ft_findexec(char *path, char *file);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
while echo bonjour toi > file1 ; do
|
echo "begin script"
|
||||||
echo hello world > file2
|
while [ 1 ]
|
||||||
done
|
do sleep 1 ; echo "hello 42sh"
|
||||||
|
done
|
||||||
|
echo "end script"
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
|
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/22 22:08:34 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 21:11:38 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,12 +14,17 @@
|
||||||
|
|
||||||
int exec_ampersand(t_btree **ast)
|
int exec_ampersand(t_btree **ast)
|
||||||
{
|
{
|
||||||
|
t_process *p;
|
||||||
|
|
||||||
if (SHELL_HAS_JOBC(data_singleton()->opts))
|
if (SHELL_HAS_JOBC(data_singleton()->opts))
|
||||||
data_singleton()->exec.job.attributes |= JOB_BG;
|
data_singleton()->exec.job.attributes |= JOB_BG;
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
if (SHELL_HAS_JOBC(data_singleton()->opts))
|
if (SHELL_HAS_JOBC(data_singleton()->opts))
|
||||||
data_singleton()->exec.job.attributes &= ~JOB_BG;
|
data_singleton()->exec.job.attributes &= ~JOB_BG;
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
btree_delone(ast, &ast_free);
|
|
||||||
|
p = &data_singleton()->exec.process;
|
||||||
|
if (!(p->script & SCRIPT_LOOP))
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */
|
/* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/12 18:01:06 by jhalford ### ########.fr */
|
/* Updated: 2017/01/30 20:53:56 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,7 +14,8 @@
|
||||||
|
|
||||||
int exec_and_if(t_btree **ast)
|
int exec_and_if(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_data *data;
|
t_data *data;
|
||||||
|
t_process *p;
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
if (data->exec.aol_status == NULL
|
if (data->exec.aol_status == NULL
|
||||||
|
|
@ -32,6 +33,9 @@ int exec_and_if(t_btree **ast)
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
data->exec.aol_status = NULL;
|
data->exec.aol_status = NULL;
|
||||||
data->exec.aol_search = 0;
|
data->exec.aol_search = 0;
|
||||||
btree_delone(ast, &ast_free);
|
|
||||||
|
p = &data_singleton()->exec.process;
|
||||||
|
if (!(p->script & SCRIPT_LOOP))
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 18:29:22 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:25:44 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -37,6 +37,8 @@ int exec_command(t_btree **ast)
|
||||||
p->av = NULL;
|
p->av = NULL;
|
||||||
p->pid = 0;
|
p->pid = 0;
|
||||||
p->attributes = PROCESS_PIPESTART | PROCESS_PIPEEND;
|
p->attributes = PROCESS_PIPESTART | PROCESS_PIPEEND;
|
||||||
btree_delone(ast, &ast_free);
|
|
||||||
|
if (!(p->script & SCRIPT_LOOP))
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 18:15:13 by jhalford #+# #+# */
|
/* Created: 2016/11/28 18:15:13 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:13:58 by jhalford ### ########.fr */
|
/* Updated: 2017/01/30 20:55:31 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
int exec_dgreat(t_btree **ast)
|
int exec_dgreat(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
|
t_process *p;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
|
|
@ -22,6 +23,9 @@ int exec_dgreat(t_btree **ast)
|
||||||
data_singleton()->exec.process.fdout = fd;
|
data_singleton()->exec.process.fdout = fd;
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
data_singleton()->exec.process.fdout = STDOUT;
|
data_singleton()->exec.process.fdout = STDOUT;
|
||||||
btree_delone(ast, &ast_free);
|
|
||||||
|
p = &data_singleton()->exec.process;
|
||||||
|
if (!(p->script & SCRIPT_LOOP))
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */
|
/* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:14:19 by jhalford ### ########.fr */
|
/* Updated: 2017/01/30 21:09:36 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
int exec_great(t_btree **ast)
|
int exec_great(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
|
t_process *p;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
|
|
@ -22,6 +23,9 @@ int exec_great(t_btree **ast)
|
||||||
data_singleton()->exec.process.fdout = fd;
|
data_singleton()->exec.process.fdout = fd;
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
data_singleton()->exec.process.fdout = STDOUT;
|
data_singleton()->exec.process.fdout = STDOUT;
|
||||||
btree_delone(ast, &ast_free);
|
|
||||||
|
p = &data_singleton()->exec.process;
|
||||||
|
if (!(p->script & SCRIPT_LOOP))
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 17:27:08 by jhalford #+# #+# */
|
/* Created: 2016/11/14 17:27:08 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:14:46 by jhalford ### ########.fr */
|
/* Updated: 2017/01/30 20:56:55 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
int exec_less(t_btree **ast)
|
int exec_less(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
|
t_process *p;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
|
|
@ -25,6 +26,9 @@ int exec_less(t_btree **ast)
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
data_singleton()->exec.process.fdin = STDIN;
|
data_singleton()->exec.process.fdin = STDIN;
|
||||||
/* data->exec.process.command = NULL; */
|
/* data->exec.process.command = NULL; */
|
||||||
btree_delone(ast, &ast_free);
|
|
||||||
|
p = &data_singleton()->exec.process;
|
||||||
|
if (!(p->script & SCRIPT_LOOP))
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
42sh/src/exec/exec_list.c
Normal file
23
42sh/src/exec/exec_list.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* exec_list.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/01/30 20:19:29 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/01/30 20:57:51 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "exec.h"
|
||||||
|
|
||||||
|
int exec_list(t_btree **ast)
|
||||||
|
{
|
||||||
|
t_process *p;
|
||||||
|
|
||||||
|
p = &data_singleton()->exec.process;
|
||||||
|
if (!(p->script & SCRIPT_LOOP))
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */
|
/* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/02 18:10:21 by jhalford ### ########.fr */
|
/* Updated: 2017/01/30 21:09:55 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
int exec_or_if(t_btree **ast)
|
int exec_or_if(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_data *data;
|
t_data *data;
|
||||||
|
t_process *p;
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
if (data->exec.aol_status == NULL
|
if (data->exec.aol_status == NULL
|
||||||
|
|
@ -32,6 +33,9 @@ int exec_or_if(t_btree **ast)
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
data->exec.aol_status = NULL;
|
data->exec.aol_status = NULL;
|
||||||
data->exec.aol_search = 0;
|
data->exec.aol_search = 0;
|
||||||
btree_delone(ast, &ast_free);
|
|
||||||
|
p = &data_singleton()->exec.process;
|
||||||
|
if (!(p->script & SCRIPT_LOOP))
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */
|
/* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 17:32:39 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 21:01:33 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -41,6 +41,8 @@ int exec_pipe(t_btree **ast)
|
||||||
|
|
||||||
close(fds[PIPE_READ]);
|
close(fds[PIPE_READ]);
|
||||||
p->fdin = STDIN;
|
p->fdin = STDIN;
|
||||||
btree_delone(ast, &ast_free);
|
|
||||||
|
if (!(p->script & SCRIPT_LOOP))
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
|
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 17:34:07 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:25:33 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,8 +14,13 @@
|
||||||
|
|
||||||
int exec_semi(t_btree **ast)
|
int exec_semi(t_btree **ast)
|
||||||
{
|
{
|
||||||
|
t_process *p;
|
||||||
|
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
btree_delone(ast, &ast_free);
|
|
||||||
|
p = &data_singleton()->exec.process;
|
||||||
|
if (!(p->script & SCRIPT_LOOP))
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
||||||
/* Updated: 2017/01/30 19:30:16 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:41:55 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,25 +14,33 @@
|
||||||
|
|
||||||
int exec_while(t_btree **ast)
|
int exec_while(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_list *test_commands;
|
t_list **test_commands;
|
||||||
t_list *consequent_commands;
|
t_list **consequent_commands;
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
t_process *p;
|
t_process *p;
|
||||||
|
int test;
|
||||||
|
|
||||||
node = ((*ast)->left)->item;
|
node = ((*ast)->left)->item;
|
||||||
DG("test command data '%s'", node->data.str);
|
DG("test command data '%s'", node->data.str);
|
||||||
test_commands = shell_get_ast(node->data.str);
|
test_commands = shell_get_ast(node->data.str);
|
||||||
|
// ft_print_all_ast(*test_commands);
|
||||||
node = ((*ast)->right)->item;
|
node = ((*ast)->right)->item;
|
||||||
|
|
||||||
DG("consequent command data '%s'", node->data.str);
|
DG("consequent command data '%s'", node->data.str);
|
||||||
consequent_commands = shell_get_ast(node->data.str);
|
consequent_commands = shell_get_ast(node->data.str);
|
||||||
|
|
||||||
p = &data_singleton()->exec.process;
|
p = &data_singleton()->exec.process;
|
||||||
p->script &= ~SCRIPT_LOOP;
|
p->script |= SCRIPT_LOOP;
|
||||||
|
|
||||||
// while (ft_test(test_commands))
|
// ft_print_all_ast(consequent_commands);
|
||||||
// ft_exec(consequent_commands)
|
|
||||||
|
test = 10;
|
||||||
|
while (test--)
|
||||||
|
loop_exec(*consequent_commands);
|
||||||
// del tree (test_commands);
|
// del tree (test_commands);
|
||||||
// del tree (test_commands);
|
// del tree (test_commands);
|
||||||
btree_delone(ast, &ast_free);
|
p->script &= 0;
|
||||||
|
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 17:33:34 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:15:15 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,6 +23,7 @@ t_execmap g_execmap[] =
|
||||||
{TK_GREAT, &exec_great},
|
{TK_GREAT, &exec_great},
|
||||||
{TK_DGREAT, &exec_dgreat},
|
{TK_DGREAT, &exec_dgreat},
|
||||||
{TK_WHILE, &exec_while},
|
{TK_WHILE, &exec_while},
|
||||||
|
{TK_LIST, &exec_list},
|
||||||
{TK_COMMAND | TK_SUBSHELL, &exec_command},
|
{TK_COMMAND | TK_SUBSHELL, &exec_command},
|
||||||
{0, 0},
|
{0, 0},
|
||||||
};
|
};
|
||||||
|
|
@ -39,8 +40,10 @@ int ft_exec(t_btree **ast)
|
||||||
while (g_execmap[i].type)
|
while (g_execmap[i].type)
|
||||||
{
|
{
|
||||||
if (item->type & g_execmap[i].type)
|
if (item->type & g_execmap[i].type)
|
||||||
|
{
|
||||||
/* return ((*g_execmap[i].f)(ast)); */
|
/* return ((*g_execmap[i].f)(ast)); */
|
||||||
(*g_execmap[i].f)(ast);
|
(*g_execmap[i].f)(ast);
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 18:30:31 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 19:36:21 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
27
42sh/src/exec/loop_exec.c
Normal file
27
42sh/src/exec/loop_exec.c
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* loop_exec.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/01/30 21:02:10 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/01/30 23:17:24 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "exec.h"
|
||||||
|
|
||||||
|
int loop_exec(t_list *list_ast)
|
||||||
|
{
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/08 15:58:20 by jhalford ### ########.fr */
|
/* Updated: 2017/01/30 21:05:42 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 00:55:33 by ariard #+# #+# */
|
/* Created: 2017/01/26 00:55:33 by ariard #+# #+# */
|
||||||
/* Updated: 2017/01/26 19:24:50 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:14:45 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
int lexer_list(t_list **alst, char *str)
|
int lexer_list(t_list **alst, char *str)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
char lim;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = TK_LIST;
|
token->type = TK_LIST;
|
||||||
|
|
@ -22,12 +23,14 @@ int lexer_list(t_list **alst, char *str)
|
||||||
{
|
{
|
||||||
if (ft_is_delim_list(*str))
|
if (ft_is_delim_list(*str))
|
||||||
{
|
{
|
||||||
str++;
|
lim = *str++;
|
||||||
while (ft_is_delim(*str) || *str == '\n')
|
while (ft_is_delim(*str) || *str == '\n')
|
||||||
str++;
|
str++;
|
||||||
if (ft_strncmp(str, "done", 4) == 0
|
if (ft_strncmp(str, "done", 4) == 0
|
||||||
|| ft_strncmp(str, "do", 2) == 0)
|
|| ft_strncmp(str, "do", 2) == 0)
|
||||||
return (ft_tokenize(alst, str, DO_GROUP));
|
return (ft_tokenize(alst, str, DO_GROUP));
|
||||||
|
else
|
||||||
|
token_append(token, lim);
|
||||||
}
|
}
|
||||||
token_append(token, *str++);
|
token_append(token, *str++);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/01/27 12:51:00 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:17:43 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 19:23:49 by ariard #+# #+# */
|
/* Created: 2017/01/30 19:23:49 by ariard #+# #+# */
|
||||||
/* Updated: 2017/01/30 19:26:42 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 22:11:21 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 18:59:13 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 20:45:01 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/21 22:49:31 by ariard #+# #+# */
|
/* Created: 2017/01/21 22:49:31 by ariard #+# #+# */
|
||||||
/* Updated: 2017/01/26 17:52:25 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 20:32:24 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,21 +6,21 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 18:19:13 by ariard #+# #+# */
|
/* Created: 2017/01/30 18:19:13 by ariard #+# #+# */
|
||||||
/* Updated: 2017/01/30 19:28:19 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:14:32 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
t_list *shell_get_ast(char *command)
|
t_list **shell_get_ast(char *command)
|
||||||
{
|
{
|
||||||
t_list *token;
|
t_list *token;
|
||||||
t_btree *ast;
|
t_btree *ast;
|
||||||
t_list *list_ast;
|
t_list **list_ast;
|
||||||
|
|
||||||
token = NULL;
|
token = NULL;
|
||||||
ast = NULL;
|
ast = NULL;
|
||||||
list_ast = NULL;
|
list_ast = ft_memalloc(sizeof(*list_ast));
|
||||||
if (ft_tokenize(&token, command, DEFAULT))
|
if (ft_tokenize(&token, command, DEFAULT))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (!token)
|
if (!token)
|
||||||
|
|
@ -29,8 +29,7 @@ t_list *shell_get_ast(char *command)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
DG("after post_tokenize");
|
DG("after post_tokenize");
|
||||||
token_print(token);
|
token_print(token);
|
||||||
if (ft_parse(&list_ast, &ast, &token))
|
if (ft_parse(list_ast, &ast, &token))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
// ft_print_all_ast(list_ast);
|
|
||||||
return (list_ast);
|
return (list_ast);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */
|
/* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 18:11:18 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 20:29:48 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
|
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
|
||||||
/* Updated: 2017/01/30 19:00:50 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:13:44 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -40,11 +40,12 @@ int shell_script()
|
||||||
btree_print(STDBUG, *ast2, &ft_putast);
|
btree_print(STDBUG, *ast2, &ft_putast);
|
||||||
tmp2 = tmp2->next;
|
tmp2 = tmp2->next;
|
||||||
}
|
}
|
||||||
while (list_ast)
|
/* while (list_ast)
|
||||||
{
|
{
|
||||||
if (ft_exec((t_btree **)list_ast->content))
|
if (ft_exec((t_btree **)list_ast->content))
|
||||||
return (1);
|
return (1);
|
||||||
list_ast = list_ast->next;
|
list_ast = list_ast->next;
|
||||||
}
|
}
|
||||||
|
*/ loop_exec(list_ast);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 16:34:21 by ariard #+# #+# */
|
/* Created: 2017/01/30 16:34:21 by ariard #+# #+# */
|
||||||
/* Updated: 2017/01/30 18:48:24 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 23:38:15 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ int parse_list(t_list **list_ast, t_btree **ast,
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
node->type = TK_LIST;
|
node->type = TK_LIST;
|
||||||
node->data.str = ft_strdup(token->data);
|
node->data.str = ft_strdup(token->data);
|
||||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 19:26:41 by ariard #+# #+# */
|
/* Created: 2017/01/26 19:26:41 by ariard #+# #+# */
|
||||||
/* Updated: 2017/01/30 17:14:05 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 20:02:09 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,7 +17,6 @@ int parse_newline(t_list **list_ast, t_btree **ast,
|
||||||
{
|
{
|
||||||
t_list *temp;
|
t_list *temp;
|
||||||
|
|
||||||
DG("parsing newline");
|
|
||||||
temp = (*lst)->next;
|
temp = (*lst)->next;
|
||||||
(*lst)->next = NULL;
|
(*lst)->next = NULL;
|
||||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */
|
/* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 17:11:05 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 20:25:22 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,7 +18,6 @@ int parse_separator(t_list **list_ast, t_btree **ast,
|
||||||
t_token *token;
|
t_token *token;
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
|
|
||||||
DG("parsing separator");
|
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
node->type = token->type;
|
node->type = token->type;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 16:03:28 by ariard #+# #+# */
|
/* Created: 2017/01/30 16:03:28 by ariard #+# #+# */
|
||||||
/* Updated: 2017/01/30 17:22:36 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 19:52:17 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue