generation subtree test_commands + consequent_commands
This commit is contained in:
parent
2212c927f8
commit
000ae4116a
21 changed files with 129 additions and 21 deletions
|
|
@ -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/24 20:01:46 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:57:16 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -34,6 +34,8 @@
|
||||||
# define IS_PIPESTART(a) (a & PROCESS_PIPESTART)
|
# define IS_PIPESTART(a) (a & PROCESS_PIPESTART)
|
||||||
# define IS_PIPEEND(a) (a & PROCESS_PIPEEND)
|
# define IS_PIPEEND(a) (a & PROCESS_PIPEEND)
|
||||||
|
|
||||||
|
# define SCRIPT_LOOP (1 << 0)
|
||||||
|
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
# include "job_control.h"
|
# include "job_control.h"
|
||||||
|
|
@ -48,6 +50,7 @@ struct s_process
|
||||||
int fdout;
|
int fdout;
|
||||||
int status;
|
int status;
|
||||||
t_flag attributes;
|
t_flag attributes;
|
||||||
|
t_flag script;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_exec
|
struct s_exec
|
||||||
|
|
@ -81,6 +84,8 @@ int exec_great(t_btree **ast);
|
||||||
int exec_dgreat(t_btree **ast);
|
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 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);
|
||||||
int process_setgroup(t_process *p);
|
int process_setgroup(t_process *p);
|
||||||
|
|
|
||||||
|
|
@ -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 16:32:37 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:05:43 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/26 20:57:21 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 19:23:44 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -81,11 +81,13 @@ 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);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
char *ft_putast(void *node);
|
char *ft_putast(void *node);
|
||||||
void ft_putast2(void *node);
|
void ft_putast2(void *node);
|
||||||
|
void ft_print_all_ast(t_list *lst_ast);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 17:14:02 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:52:54 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/24 16:01:58 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:11:14 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
ls ; while [ 1 ]; do
|
while echo bonjour toi > file1 ; do
|
||||||
echo hello
|
echo hello world > file2
|
||||||
done > file1 ; pwd
|
done
|
||||||
|
|
|
||||||
|
|
@ -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/22 22:16:06 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:29:22 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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/20 00:17:05 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 17:32:39 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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: 2016/12/12 18:00:21 by jhalford ### ########.fr */
|
/* Updated: 2017/01/30 17:34:07 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
38
42sh/src/exec/exec_while.c
Normal file
38
42sh/src/exec/exec_while.c
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* exec_while.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/01/30 19:30:16 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "exec.h"
|
||||||
|
|
||||||
|
int exec_while(t_btree **ast)
|
||||||
|
{
|
||||||
|
t_list *test_commands;
|
||||||
|
t_list *consequent_commands;
|
||||||
|
t_astnode *node;
|
||||||
|
t_process *p;
|
||||||
|
|
||||||
|
node = ((*ast)->left)->item;
|
||||||
|
DG("test command data '%s'", node->data.str);
|
||||||
|
test_commands = shell_get_ast(node->data.str);
|
||||||
|
node = ((*ast)->right)->item;
|
||||||
|
DG("consequent command data '%s'", node->data.str);
|
||||||
|
consequent_commands = shell_get_ast(node->data.str);
|
||||||
|
|
||||||
|
p = &data_singleton()->exec.process;
|
||||||
|
p->script &= ~SCRIPT_LOOP;
|
||||||
|
|
||||||
|
// while (ft_test(test_commands))
|
||||||
|
// ft_exec(consequent_commands)
|
||||||
|
// del tree (test_commands);
|
||||||
|
// del tree (test_commands);
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
|
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/24 20:03:01 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 17:33:34 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,6 +22,7 @@ t_execmap g_execmap[] =
|
||||||
{TK_LESS, &exec_less},
|
{TK_LESS, &exec_less},
|
||||||
{TK_GREAT, &exec_great},
|
{TK_GREAT, &exec_great},
|
||||||
{TK_DGREAT, &exec_dgreat},
|
{TK_DGREAT, &exec_dgreat},
|
||||||
|
{TK_WHILE, &exec_while},
|
||||||
{TK_COMMAND | TK_SUBSHELL, &exec_command},
|
{TK_COMMAND | TK_SUBSHELL, &exec_command},
|
||||||
{0, 0},
|
{0, 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/22 22:11:35 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:30:31 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/22 22:16:52 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:29:23 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
27
42sh/src/main/ft_print_all_ast.c
Normal file
27
42sh/src/main/ft_print_all_ast.c
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_print_all_ast.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/01/30 19:23:49 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/01/30 19:26:42 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void ft_print_all_ast(t_list *lst_ast)
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_btree **ast;
|
||||||
|
|
||||||
|
tmp = lst_ast;
|
||||||
|
while (tmp)
|
||||||
|
{
|
||||||
|
ast = tmp->content;
|
||||||
|
btree_print(STDBUG, *ast, &ft_putast);
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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/26 21:08:49 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:59:13 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
36
42sh/src/main/shell_get_ast.c
Normal file
36
42sh/src/main/shell_get_ast.c
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* shell_set_ast.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/01/30 18:19:13 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/01/30 19:28:19 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
t_list *shell_get_ast(char *command)
|
||||||
|
{
|
||||||
|
t_list *token;
|
||||||
|
t_btree *ast;
|
||||||
|
t_list *list_ast;
|
||||||
|
|
||||||
|
token = NULL;
|
||||||
|
ast = NULL;
|
||||||
|
list_ast = NULL;
|
||||||
|
if (ft_tokenize(&token, command, DEFAULT))
|
||||||
|
return (NULL);
|
||||||
|
if (!token)
|
||||||
|
return (NULL);
|
||||||
|
if (ft_post_tokenize(&token, command))
|
||||||
|
return (NULL);
|
||||||
|
DG("after post_tokenize");
|
||||||
|
token_print(token);
|
||||||
|
if (ft_parse(&list_ast, &ast, &token))
|
||||||
|
return (NULL);
|
||||||
|
// ft_print_all_ast(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/23 23:36:11 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:11:18 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 17:15:37 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 19:00:50 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -40,7 +40,6 @@ int shell_script()
|
||||||
btree_print(STDBUG, *ast2, &ft_putast);
|
btree_print(STDBUG, *ast2, &ft_putast);
|
||||||
tmp2 = tmp2->next;
|
tmp2 = tmp2->next;
|
||||||
}
|
}
|
||||||
return (0);
|
|
||||||
while (list_ast)
|
while (list_ast)
|
||||||
{
|
{
|
||||||
if (ft_exec((t_btree **)list_ast->content))
|
if (ft_exec((t_btree **)list_ast->content))
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -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 17:22:54 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:48:24 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.sstr = ft_sstradd(node->data.sstr, 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: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 16:45:53 by ariard ### ########.fr */
|
/* Updated: 2017/01/30 18:37:21 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue