execution much simpler with new parser, thx ariard!
This commit is contained in:
parent
62d3ef01d2
commit
3857b06785
34 changed files with 234 additions and 242 deletions
|
|
@ -6,7 +6,7 @@
|
|||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||
# Updated: 2017/03/01 16:42:16 by ariard ### ########.fr #
|
||||
# Updated: 2017/03/02 16:23:48 by jhalford ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ NAME = 42sh
|
|||
|
||||
CC = gcc
|
||||
FLAGS = -Wall -Wextra -Werror
|
||||
D_FLAGS = -g
|
||||
D_FLAGS = -g
|
||||
|
||||
DELTA = $$(echo "$$(tput cols)-47"|bc)
|
||||
|
||||
|
|
@ -62,22 +62,22 @@ exec/ast_free.c\
|
|||
exec/bad_fd.c\
|
||||
exec/exec_ampersand.c\
|
||||
exec/exec_and_if.c\
|
||||
exec/exec_case.c\
|
||||
exec/exec_case_branch.c\
|
||||
exec/exec_command.c\
|
||||
exec/exec_default.c\
|
||||
exec/exec_elif.c\
|
||||
exec/exec_else.c\
|
||||
exec/exec_for.c\
|
||||
exec/exec_func.c\
|
||||
exec/exec_if.c\
|
||||
exec/exec_less.c\
|
||||
exec/exec_or_if.c\
|
||||
exec/exec_pipe.c\
|
||||
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/exec_while.c\
|
||||
exec/fd_is_valid.c\
|
||||
exec/ft_exec.c\
|
||||
exec/ft_findexec.c\
|
||||
|
|
@ -173,9 +173,11 @@ lexer/get_reserved_words.c\
|
|||
lexer/get_state_global.c\
|
||||
lexer/get_state_redir.c\
|
||||
lexer/insert_newline.c\
|
||||
lexer/lexer_assignement_word.c\
|
||||
lexer/lexer_backslash.c\
|
||||
lexer/lexer_bquote.c\
|
||||
lexer/lexer_comment.c\
|
||||
lexer/lexer_curly_brackets.c\
|
||||
lexer/lexer_default.c\
|
||||
lexer/lexer_delim.c\
|
||||
lexer/lexer_dless.c\
|
||||
|
|
@ -190,8 +192,6 @@ lexer/lexer_lex.c\
|
|||
lexer/lexer_newline.c\
|
||||
lexer/lexer_number.c\
|
||||
lexer/lexer_paren.c\
|
||||
lexer/lexer_curly_brackets.c\
|
||||
lexer/lexer_assignement_word.c\
|
||||
lexer/lexer_quote.c\
|
||||
lexer/lexer_sep.c\
|
||||
lexer/lexer_word.c\
|
||||
|
|
@ -227,14 +227,14 @@ main/shell_exit.c\
|
|||
main/shell_get_avdata.c\
|
||||
main/shell_get_opts.c\
|
||||
main/shell_init.c\
|
||||
parser/add_cmd.c\
|
||||
parser/add_subshell.c\
|
||||
parser/add_condition.c\
|
||||
parser/add_loop.c\
|
||||
parser/add_sep.c\
|
||||
parser/add_case.c\
|
||||
parser/add_cmd.c\
|
||||
parser/add_condition.c\
|
||||
parser/add_func.c\
|
||||
parser/add_loop.c\
|
||||
parser/add_redir.c\
|
||||
parser/add_sep.c\
|
||||
parser/add_subshell.c\
|
||||
parser/aggregate_sym.c\
|
||||
parser/build_tree.c\
|
||||
parser/error_syntax.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 21:41:18 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 21:02:14 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,6 +33,15 @@
|
|||
# define IS_PIPEEND(p) (p->fdout == STDOUT)
|
||||
# define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
|
||||
|
||||
# define EXEC_BG (1 << 1)
|
||||
# define EXEC_AND_IF (1 << 2)
|
||||
# define EXEC_OR_IF (1 << 3)
|
||||
# define EXEC_IS_BG(j) (j & EXEC_BG)
|
||||
# define EXEC_IS_FG(j) (!EXEC_IS_BG(j))
|
||||
# define EXEC_IS_AND_IF(j) (j & EXEC_AND_IF)
|
||||
# define EXEC_IS_OR_IF(j) (j & EXEC_JOB_OR_IF)
|
||||
# define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF)
|
||||
|
||||
# include "libft.h"
|
||||
# include "types.h"
|
||||
# include "job_control.h"
|
||||
|
|
@ -45,7 +54,6 @@ struct s_process
|
|||
pid_t pid;
|
||||
int fdin;
|
||||
int fdout;
|
||||
int pipe_count;
|
||||
int to_close;
|
||||
t_list *redirs;
|
||||
int status;
|
||||
|
|
@ -57,13 +65,13 @@ struct s_process
|
|||
|
||||
struct s_exec
|
||||
{
|
||||
char *aol_status;
|
||||
int aol_search;
|
||||
t_job job;
|
||||
t_process process;
|
||||
int fd0save;
|
||||
int fd1save;
|
||||
int fd2save;
|
||||
/* char *aol_status; */
|
||||
/* int aol_search; */
|
||||
/* t_job job; */
|
||||
/* t_process process; */
|
||||
int fd_save[3];
|
||||
t_flag attrs;
|
||||
t_list *op_stack;
|
||||
};
|
||||
|
||||
struct s_execmap
|
||||
|
|
@ -92,8 +100,8 @@ int exec_ampersand(t_btree **ast);
|
|||
int exec_or_if(t_btree **ast);
|
||||
int exec_and_if(t_btree **ast);
|
||||
int exec_pipe(t_btree **ast);
|
||||
int exec_redir(t_btree **ast);
|
||||
int exec_command(t_btree **ast);
|
||||
/* int exec_redir(t_btree **ast); */
|
||||
int exec_job(t_btree **ast);
|
||||
|
||||
int exec_while(t_btree **ast);
|
||||
int exec_if(t_btree **ast);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/03 14:43:34 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 21:01:59 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,10 +21,8 @@
|
|||
|
||||
# define JOB_NOTIFIED (1 << 0)
|
||||
# define JOB_BG (1 << 1)
|
||||
# define JOB_IS_BG(j) (j & JOB_BG)
|
||||
# define JOB_IS_FG(j) !(j & JOB_BG)
|
||||
|
||||
#define JOBS_OPTS_L (1 << 0)
|
||||
# define JOBS_OPTS_L (1 << 0)
|
||||
|
||||
struct s_job
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/24 21:46:08 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 17:15:15 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 18:51:18 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 17:15:12 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* */ /* ::: :::::::: */
|
||||
/* parser.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/01 22:39:00 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 17:10:21 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/01 22:39:16 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 17:49:22 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit bfc8ca207ab4d39f0140322c0f1d368137304a3c
|
||||
Subproject commit 8f6e64fa9b4ac1dd3e3d5200fb93471ddfeedd40
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 22:40:59 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 21:00:13 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/05 22:10:08 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 21:02:41 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,13 +14,21 @@
|
|||
|
||||
int exec_ampersand(t_btree **ast)
|
||||
{
|
||||
if (SH_HAS_JOBC(data_singleton()->opts))
|
||||
data_singleton()->exec.job.attributes |= JOB_BG;
|
||||
t_exec *exec;
|
||||
|
||||
exec = &data_singleton()->exec;
|
||||
push(&exec->op_stack, TK_AMP);
|
||||
ft_exec(&(*ast)->left);
|
||||
if (SH_HAS_JOBC(data_singleton()->opts))
|
||||
data_singleton()->exec.job.attributes &= ~JOB_BG;
|
||||
exec->attrs &= ~JOB_BG;
|
||||
ft_exec(&(*ast)->right);
|
||||
|
||||
/* if (SH_HAS_JOBC(data_singleton()->opts)) */
|
||||
/* data_singleton()->exec.job.attributes |= JOB_BG; */
|
||||
/* ft_exec(&(*ast)->left); */
|
||||
/* if (SH_HAS_JOBC(data_singleton()->opts)) */
|
||||
/* data_singleton()->exec.job.attributes &= ~JOB_BG; */
|
||||
/* ft_exec(&(*ast)->right); */
|
||||
|
||||
// btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/05 22:10:38 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 20:41:02 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,24 +14,31 @@
|
|||
|
||||
int exec_and_if(t_btree **ast)
|
||||
{
|
||||
t_data *data;
|
||||
/* t_data *data; */
|
||||
t_exec *exec;
|
||||
|
||||
data = data_singleton();
|
||||
if (data->exec.aol_status == NULL
|
||||
|| (data->exec.aol_search == TK_AND_IF
|
||||
&& *data->exec.aol_status == '0')
|
||||
|| (data->exec.aol_search == TK_OR_IF
|
||||
&& *data->exec.aol_status != '0'))
|
||||
{
|
||||
ft_exec(&(*ast)->left);
|
||||
data->exec.aol_status = ft_getenv(data->env, "?");
|
||||
}
|
||||
data->exec.aol_search = TK_AND_IF;
|
||||
if (*data->exec.aol_status == '0'
|
||||
|| ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND)
|
||||
ft_exec(&(*ast)->right);
|
||||
data->exec.aol_status = NULL;
|
||||
data->exec.aol_search = 0;
|
||||
exec = &data_singleton()->exec;
|
||||
push(&exec->op_stack, TK_AND_IF);
|
||||
ft_exec(&(*ast)->left);
|
||||
exec->attrs |= JOB_AND_IF;
|
||||
ft_exec(&(*ast)->right);
|
||||
|
||||
/* data = data_singleton(); */
|
||||
/* if (data->exec.aol_status == NULL */
|
||||
/* || (data->exec.aol_search == TK_AND_IF */
|
||||
/* && *data->exec.aol_status == '0') */
|
||||
/* || (data->exec.aol_search == TK_OR_IF */
|
||||
/* && *data->exec.aol_status != '0')) */
|
||||
/* { */
|
||||
/* ft_exec(&(*ast)->left); */
|
||||
/* data->exec.aol_status = ft_getenv(data->env, "?"); */
|
||||
/* } */
|
||||
/* data->exec.aol_search = TK_AND_IF; */
|
||||
/* if (*data->exec.aol_status == '0' */
|
||||
/* || ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) */
|
||||
/* ft_exec(&(*ast)->right); */
|
||||
/* data->exec.aol_status = NULL; */
|
||||
/* data->exec.aol_search = 0; */
|
||||
|
||||
// btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/02 12:36:28 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 21:16:23 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
char **token_to_argv(t_astnode *node)
|
||||
char **token_to_argv(t_cmd *cmd)
|
||||
{
|
||||
char **my_tab;
|
||||
int index;
|
||||
|
|
@ -20,66 +20,50 @@ char **token_to_argv(t_astnode *node)
|
|||
char **content;
|
||||
t_ld *ld;
|
||||
|
||||
if (node->type == TK_WORD || node->type == TK_ASSIGNEMENT_WORD)
|
||||
ld = cmd->token;
|
||||
my_tab = NULL;
|
||||
while (ld)
|
||||
{
|
||||
ld = node->data.cmd.token;
|
||||
my_tab = NULL;
|
||||
while (ld)
|
||||
content = ld->content;
|
||||
if ((expand = glob(content[0], (unsigned char *)content[1], (unsigned char *)content[2])))
|
||||
{
|
||||
content = ld->content;
|
||||
if ((expand = glob(content[0], (unsigned char *)content[1], (unsigned char *)content[2])))
|
||||
{
|
||||
index = -1;
|
||||
while (expand[++index])
|
||||
my_tab = ft_sstradd(my_tab, expand[index]);
|
||||
ft_tabdel(&expand);
|
||||
}
|
||||
ld = ld->next;
|
||||
index = -1;
|
||||
while (expand[++index])
|
||||
my_tab = ft_sstradd(my_tab, expand[index]);
|
||||
ft_tabdel(&expand);
|
||||
}
|
||||
return (my_tab);
|
||||
ld = ld->next;
|
||||
}
|
||||
else if (node->type == TK_SUBSHELL)
|
||||
return (ft_sstrdup(node->data.sstr));
|
||||
return (NULL);
|
||||
return (my_tab);
|
||||
}
|
||||
|
||||
int exec_command(t_btree **ast)
|
||||
int exec_job(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_process *p;
|
||||
t_job *job;
|
||||
t_list *cmd;
|
||||
t_process p;
|
||||
t_list *first_process;
|
||||
int fds[2];
|
||||
|
||||
node = (*ast)->item;
|
||||
p = &data_singleton()->exec.process;
|
||||
job = &data_singleton()->exec.job;
|
||||
if (!(p->av = token_to_argv(node)))
|
||||
cmd = ((t_astnode *)(*ast)->item)->data;
|
||||
exec = &data_singleton()->exec;
|
||||
if (pop(&exec.op_stack) == TK_AMP)
|
||||
exec->attrs |= JOB_BG;
|
||||
first_process = NULL;
|
||||
fds[PIPE_READ] = STDIN;
|
||||
while (cmd)
|
||||
{
|
||||
DG("globbing error");
|
||||
return (1);
|
||||
p.fdin = fds[PIPE_READ];
|
||||
p.fdout = cmd->next ? pipe(fds) && fds[PIPE_WRITE] : STDOUT;
|
||||
process_reset(&p);
|
||||
if (!(p.av = token_to_argv(cmd->content)))
|
||||
return (1);
|
||||
process_setexec(cmd->content, &p);
|
||||
if (!(launch_process(p)))
|
||||
ft_lstadd(&first_process, ft_lstnew(&p, sizeof(p)));
|
||||
cmd = cmd->next;
|
||||
}
|
||||
process_setexec(node->type, p);
|
||||
if (p->pipe_count)
|
||||
{
|
||||
pipe(fds);
|
||||
p->fdout = fds[PIPE_WRITE];
|
||||
p->to_close = fds[PIPE_READ];
|
||||
p->pipe_count--;
|
||||
}
|
||||
if (!(launch_process(p)))
|
||||
{
|
||||
job_addprocess(p);
|
||||
if (IS_PIPEEND(p))
|
||||
{
|
||||
JOB_IS_FG(job->attributes) ?
|
||||
put_job_in_foreground(job, 0):
|
||||
put_job_in_background(job, 0);
|
||||
job->pgid = 0;
|
||||
}
|
||||
}
|
||||
if (p->fdout == fds[PIPE_WRITE])
|
||||
p->fdin = fds[PIPE_READ];
|
||||
process_reset(p);
|
||||
add_new_job(first_process, EXEC_IS_FG(exec->attrs));
|
||||
ft_lstadd(&jobc->first_job, ft_lstnew(&job, sizeof(*job)));
|
||||
// btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/05 22:12:08 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 21:02:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,24 +14,31 @@
|
|||
|
||||
int exec_or_if(t_btree **ast)
|
||||
{
|
||||
t_data *data;
|
||||
/* t_data *data; */
|
||||
t_exec *exec;
|
||||
|
||||
data = data_singleton();
|
||||
if (data->exec.aol_status == NULL
|
||||
|| (data->exec.aol_search == TK_AND_IF
|
||||
&& *data->exec.aol_status == '0')
|
||||
|| (data->exec.aol_search == TK_OR_IF
|
||||
&& *data->exec.aol_status != '0'))
|
||||
{
|
||||
ft_exec(&(*ast)->left);
|
||||
data->exec.aol_status = ft_getenv(data->env, "?");
|
||||
}
|
||||
data->exec.aol_search = TK_OR_IF;
|
||||
if (*data->exec.aol_status != '0'
|
||||
|| ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND)
|
||||
ft_exec(&(*ast)->right);
|
||||
data->exec.aol_status = NULL;
|
||||
data->exec.aol_search = 0;
|
||||
exec = &data_singleton()->exec;
|
||||
push(&exec->op_stack, TK_OR_IF);
|
||||
ft_exec(&(*ast)->left);
|
||||
exec->attrs |= JOB_OR_IF;
|
||||
ft_exec(&(*ast)->right);
|
||||
|
||||
/* data = data_singleton(); */
|
||||
/* if (data->exec.aol_status == NULL */
|
||||
/* || (data->exec.aol_search == TK_AND_IF */
|
||||
/* && *data->exec.aol_status == '0') */
|
||||
/* || (data->exec.aol_search == TK_OR_IF */
|
||||
/* && *data->exec.aol_status != '0')) */
|
||||
/* { */
|
||||
/* ft_exec(&(*ast)->left); */
|
||||
/* data->exec.aol_status = ft_getenv(data->env, "?"); */
|
||||
/* } */
|
||||
/* data->exec.aol_search = TK_OR_IF; */
|
||||
/* if (*data->exec.aol_status != '0' */
|
||||
/* || ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) */
|
||||
/* ft_exec(&(*ast)->right); */
|
||||
/* data->exec.aol_status = NULL; */
|
||||
/* data->exec.aol_search = 0; */
|
||||
|
||||
// btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_redir.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/01 16:38:01 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
int exec_redir(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_process *p;
|
||||
|
||||
p = &data_singleton()->exec.process;
|
||||
node = (*ast)->item;
|
||||
// node->data.redir.type = node->type;
|
||||
// ft_lsteadd(&p->redirs, ft_lstnew(&node->data.redir,sizeof(node->data.redir)));
|
||||
ft_exec(&(*ast)->left);
|
||||
// btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/06 18:34:38 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 20:41:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,9 +14,13 @@
|
|||
|
||||
int exec_semi(t_btree **ast)
|
||||
{
|
||||
ft_exec(&(*ast)->left);
|
||||
ft_exec(&(*ast)->right);
|
||||
t_exec *exec;
|
||||
|
||||
exec = &data_singleton()->exec;
|
||||
push(&exec->op_stack, TK_SEMI);
|
||||
ft_exec(&(*ast)->left);
|
||||
exec->attrs ~= ~JOB_AOL_MASK;
|
||||
ft_exec(&(*ast)->right);
|
||||
// btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 18:50:05 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 20:53:28 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,24 +15,18 @@
|
|||
t_execmap g_execmap[] =
|
||||
{
|
||||
{TK_NEWLINE, &exec_semi},
|
||||
{TK_AND_IF, &exec_and_if},
|
||||
{TK_OR_IF, &exec_or_if},
|
||||
{TK_SEMI, &exec_semi},
|
||||
{TK_AMP, &exec_ampersand},
|
||||
{TK_PIPE, &exec_pipe},
|
||||
{TK_LESS, &exec_redir},
|
||||
{TK_GREAT, &exec_redir},
|
||||
{TK_DLESS, &exec_redir},
|
||||
{TK_DGREAT, &exec_redir},
|
||||
{TK_LESSAND, &exec_redir},
|
||||
{TK_GREATAND, &exec_redir},
|
||||
{TK_AND_IF, &exec_and_if},
|
||||
{TK_OR_IF, &exec_or_if},
|
||||
/* {TK_PIPE, &exec_pipe}, */
|
||||
{TK_WHILE, &exec_while},
|
||||
{TK_IF, &exec_if},
|
||||
{TK_ELIF, &exec_elif},
|
||||
{TK_ELSE, &exec_else},
|
||||
{TK_UNTIL, &exec_until},
|
||||
{TK_SUBSHELL, &exec_command},
|
||||
{TK_WORD, &exec_command},
|
||||
/* {TK_SUBSHELL, &exec_}, */
|
||||
{TK_WORD, &exec_job},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
|
|
@ -51,8 +45,7 @@ int ft_exec(t_btree **ast)
|
|||
{
|
||||
/* DG("match : %s and %s", */
|
||||
/* read_state(item->type), read_state(g_execmap[i].type)); */
|
||||
/* return ((*g_execmap[i].f)(ast)); */
|
||||
(*g_execmap[i].f)(ast);
|
||||
return ((*g_execmap[i].f)(ast));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 21:39:15 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 20:29:33 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 21:44:23 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 19:44:42 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/07 17:44:22 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 21:42:40 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 20:44:12 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,10 +14,14 @@
|
|||
|
||||
void process_reset(t_process *p)
|
||||
{
|
||||
p->fdout = STDOUT;
|
||||
p->to_close = 0;
|
||||
p->av = NULL;
|
||||
p->path = NULL;
|
||||
p->execf = NULL;
|
||||
p->pid = 0;
|
||||
/* p->fdin = STDIN; */
|
||||
/* p->fdout = STDOUT; */
|
||||
p->to_close = 0;
|
||||
p->redirs = NULL;
|
||||
p->attributes &= ~(PROCESS_STATE_MASK | PROCESS_TYPE_MASK);
|
||||
p->status = -1;
|
||||
p->attributes = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,25 +6,26 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 22:41:44 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 21:00:51 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int process_setexec(t_type type, t_process *p)
|
||||
int process_setexec(t_cmd *cmd, t_process *p)
|
||||
{
|
||||
t_flag type;
|
||||
|
||||
type = cmd->type;
|
||||
p->path = NULL;
|
||||
if (type == TK_SUBSHELL)
|
||||
{
|
||||
p->execf = &execve;
|
||||
p->attributes |= PROCESS_SUBSHELL;
|
||||
p->path = ft_strdup(p->av[0]);
|
||||
}
|
||||
/* if (type == TK_SUBSHELL) */
|
||||
/* { */
|
||||
/* p->execf = &execve; */
|
||||
/* p->attributes |= PROCESS_SUBSHELL; */
|
||||
/* p->path = ft_strdup(p->av[0]); */
|
||||
/* } */
|
||||
else if ((p->execf = is_builtin(p)))
|
||||
{
|
||||
p->attributes |= PROCESS_BUILTIN;
|
||||
}
|
||||
else if (ft_strchr(p->av[0], '/'))
|
||||
{
|
||||
p->execf = &execve;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/11 14:45:36 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 20:13:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,37 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* job_addprocess.c :+: :+: :+: */
|
||||
/* add_new_job.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 21:42:53 by jhalford ### ########.fr */
|
||||
/* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/02 21:04:51 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "job_control.h"
|
||||
|
||||
int job_addprocess(t_process *p)
|
||||
int add_new_job(t_list *first_process, int foreground)
|
||||
{
|
||||
t_jobc *jobc;
|
||||
t_job *job;
|
||||
t_job job;
|
||||
|
||||
if (!first_process)
|
||||
return (1);
|
||||
jobc = &data_singleton()->jobc;
|
||||
job = &data_singleton()->exec.job;
|
||||
if (IS_PIPESTART(p))
|
||||
{
|
||||
job_update_id();
|
||||
job->id = jobc->current_id;
|
||||
job->pgid = p->pid;
|
||||
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
||||
}
|
||||
job = jobc->first_job->content;
|
||||
if (p->pid > 0)
|
||||
{
|
||||
ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
|
||||
}
|
||||
if (JOB_IS_BG(job->attributes) && IS_PIPEEND(p))
|
||||
job_update_id();
|
||||
job->id = jobc->current_id;
|
||||
job->pgid = ((t_process*)first_process->content)->pid;
|
||||
job->attrs = foreground ? 0 : JOB_BG;
|
||||
job->first_process = first_process;
|
||||
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
||||
if (JOB_IS_FG(job->attrs))
|
||||
put_job_in_foreground(job, 0);
|
||||
else
|
||||
job_notify_new(job);
|
||||
put_job_in_background(job, 0);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 13:33:08 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 13:22:11 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 20:59:46 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/03 13:59:25 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 17:48:50 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/20 21:52:28 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 20:57:36 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/31 15:10:45 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 20:59:44 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/24 21:39:47 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 18:20:18 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/24 20:28:13 by ariard #+# #+# */
|
||||
/* Updated: 2017/02/24 21:00:13 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 19:11:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/01 14:06:03 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 18:12:10 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 22:41:46 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 21:02:17 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,25 +23,26 @@ 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.to_close = 0;
|
||||
data->exec.process.fdin = STDIN;
|
||||
data->exec.process.fdout = STDOUT;
|
||||
data->exec.process.pid = 0;
|
||||
data->exec.process.attributes = 0;
|
||||
data->exec.process.redirs = NULL;
|
||||
data->exec.process.pipe_count = 0;
|
||||
data->exec.fd0save = fcntl(0, F_DUPFD_CLOEXEC);
|
||||
data->exec.fd1save = fcntl(1, F_DUPFD_CLOEXEC);
|
||||
data->exec.fd2save = fcntl(2, F_DUPFD_CLOEXEC);
|
||||
/* data->exec.process.path = NULL; */
|
||||
/* data->exec.process.av = NULL; */
|
||||
/* data->exec.process.to_close = 0; */
|
||||
/* data->exec.process.fdin = STDIN; */
|
||||
/* data->exec.process.fdout = STDOUT; */
|
||||
/* data->exec.process.pid = 0; */
|
||||
/* data->exec.process.attributes = 0; */
|
||||
/* data->exec.process.redirs = NULL; */
|
||||
data->exec.fd_save[0] = fcntl(0, F_DUPFD_CLOEXEC);
|
||||
data->exec.fd_save[1] = fcntl(1, F_DUPFD_CLOEXEC);
|
||||
data->exec.fd_save[2] = fcntl(2, F_DUPFD_CLOEXEC);
|
||||
data->exec.op_stack = NULL;
|
||||
data->attrs = 0;
|
||||
|
||||
data->exec.aol_status = NULL;
|
||||
data->exec.aol_search = 0;
|
||||
data->exec.job.id = 0;
|
||||
data->exec.job.pgid = 0;
|
||||
data->exec.job.attributes = 0;
|
||||
data->exec.job.first_process = 0;
|
||||
/* data->exec.aol_status = NULL; */
|
||||
/* data->exec.aol_search = 0; */
|
||||
/* data->exec.job.id = 0; */
|
||||
/* data->exec.job.pgid = 0; */
|
||||
/* data->exec.job.attributes = 0; */
|
||||
/* data->exec.job.first_process = 0; */
|
||||
|
||||
data->jobc.first_job = NULL;
|
||||
data->jobc.current_id = 1;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/01 15:56:54 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 17:16:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/02 12:37:07 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 21:00:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/21 20:14:44 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/02 20:38:23 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/01 22:46:31 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/02 19:11:18 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -48,14 +48,21 @@ int add_cmd(t_btree **ast, t_list **lst)
|
|||
&& node->type != TK_PAREN_CLOSE && node->type != TK_WORD
|
||||
&& node->type != REDIR)
|
||||
return (add_cmd(&(*ast)->right, lst));
|
||||
my_tab = NULL;
|
||||
node = (*ast)->item;
|
||||
node->type = token->type;
|
||||
if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD)
|
||||
{
|
||||
DG("add data");
|
||||
my_tab = ft_sstradd(my_tab, token->data);
|
||||
my_tab = ft_sstradd(my_tab, (char *)token->esc);
|
||||
/* my_tab = ft_sstradd(NULL, token->data); */
|
||||
/* my_tab = ft_sstradd(my_tab, (char *)token->esc); */
|
||||
/* my_tab = ft_sstradd(my_tab, (char *)token->esc2); */
|
||||
if ((my_tab = (char **)malloc(sizeof(char *) * 4)))
|
||||
{
|
||||
my_tab[0] = ft_strdup(token->data);
|
||||
my_tab[1] = (char *)dup_char_esc(token->esc, token->size >> 3);
|
||||
my_tab[2] = (char *)dup_char_esc(token->esc2, token->size >> 3);
|
||||
my_tab[3] = NULL;
|
||||
}
|
||||
ft_ld_pushback(&node->data.cmd.token, my_tab);
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue