From 0d162c50f5b6210cdb264c7213768dafd266d787 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 8 Mar 2017 17:46:38 +0100 Subject: [PATCH] started rapiring jobc and heredoc lexer now OK' --- 42sh/includes/exec.h | 4 ++-- 42sh/includes/job_control.h | 2 +- 42sh/includes/lexer.h | 2 +- 42sh/src/exec/exec_ampersand.c | 13 +++---------- 42sh/src/exec/exec_leaf.c | 2 +- 42sh/src/exec/exec_semi.c | 3 +-- 42sh/src/exec/launch_file.c | 6 ++---- 42sh/src/exec/mark_process_status.c | 5 +++-- 42sh/src/exec/set_process.c | 6 ++---- 42sh/src/exec/set_process_cmd.c | 6 +++--- 42sh/src/job-control/do_job_notification.c | 2 +- 42sh/src/job-control/job_addprocess.c | 8 +++----- 42sh/src/job-control/job_notify_change.c | 2 +- 42sh/src/job-control/job_notify_new.c | 2 +- 42sh/src/job-control/job_remove.c | 2 +- 42sh/src/job-control/job_update_status.c | 2 +- 42sh/src/job-control/job_wait.c | 2 +- 42sh/src/job-control/put_job_in_foreground.c | 2 +- 42sh/src/job-control/sigchld_handler.c | 5 +---- 42sh/src/lexer/lexer_heredoc.c | 6 ++++-- 42sh/src/lexer/lexer_sep.c | 2 +- 42sh/src/lexer/token_append.c | 2 +- 42sh/src/line-editing/control_c_and_d.c | 2 +- 42sh/src/line-editing/ft_prompt.c | 2 +- 24 files changed, 38 insertions(+), 52 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index baf2e7d6..cdf63189 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/08 14:58:19 by wescande ### ########.fr */ +/* Updated: 2017/03/08 16:45:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ # define IS_PIPEEND(p) ((p).fdout == STDOUT) # define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p)) -# define EXEC_BG (1 << 1) +/* # define EXEC_BG (1 << 1) */ # define EXEC_AND_IF (1 << 2) # define EXEC_OR_IF (1 << 3) # define EXEC_IF_BRANCH (1 << 4) diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 62c32983..b92c31cc 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/05 16:28:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 16:45:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 21b7209a..f4cb38a0 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/03/08 15:52:11 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 16:44:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_ampersand.c b/42sh/src/exec/exec_ampersand.c index a95c357c..d9b65bbf 100644 --- a/42sh/src/exec/exec_ampersand.c +++ b/42sh/src/exec/exec_ampersand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */ -/* Updated: 2017/03/07 18:24:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 16:46:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,15 +21,8 @@ int exec_ampersand(t_btree **ast) exec = &data_singleton()->exec; push(&exec->op_stack, TK_AMP); ft_exec(&(*ast)->left); - exec->attrs &= ~EXEC_BG; + exec->attrs &= ~EXEC_AOL_MASK; + exec->job.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); } diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 95f1d38b..b4a770c2 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/08 14:47:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:40:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_semi.c b/42sh/src/exec/exec_semi.c index 4a0d2699..7f8b91ce 100644 --- a/42sh/src/exec/exec_semi.c +++ b/42sh/src/exec/exec_semi.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */ -/* Updated: 2017/03/06 18:09:54 by ariard ### ########.fr */ +/* Updated: 2017/03/08 16:41:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,5 @@ int exec_semi(t_btree **ast) ft_exec(&(*ast)->left); exec->attrs &= ~EXEC_AOL_MASK; ft_exec(&(*ast)->right); -// btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index 180d0f58..249c49d1 100644 --- a/42sh/src/exec/launch_file.c +++ b/42sh/src/exec/launch_file.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/08 14:46:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:35:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ int launch_file(t_process *p) { int pid; - DG("in file"); + /* DG("in file"); */ pid = fork(); if (pid == 0) { @@ -40,13 +40,11 @@ int launch_file(t_process *p) ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]); exit(126); } - // for all leaves process_setgroup(p, 0); process_setsig(); if (process_redirect(p)) exit (1); exec_reset(); - // (*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env); ft_dprintf(2, "{red}%s: internal execve error on %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]); exit(42); diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index ecc3c9ea..aa9597b3 100644 --- a/42sh/src/exec/mark_process_status.c +++ b/42sh/src/exec/mark_process_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/06 12:28:55 by wescande ### ########.fr */ +/* Updated: 2017/03/08 17:44:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,8 @@ int mark_process_status(pid_t pid, int status) } return (0); } - ft_dprintf(2, "No child process %d.\n", pid); + ft_dprintf(2, "{red}No child process %d.\n", pid); + return (0); } return (-1); } diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index b8135905..cf7f2fbf 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/08 15:55:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 16:46:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,6 @@ int set_process(t_process *p, t_btree *ast) int op; int fds[2]; -// cmd = &((t_astnode *)ast->item)->data.cmd; - /* process_reset(p); */ exec = &data_singleton()->exec; op = pop(&exec->op_stack); if ((EXEC_IS_AND_IF(exec->attrs) @@ -31,7 +29,7 @@ int set_process(t_process *p, t_btree *ast) fds[PIPE_WRITE] = STDOUT; fds[PIPE_READ] = STDIN; if (op == TK_AMP) - exec->attrs |= JOB_BG; + exec->job.attrs |= JOB_BG; else if (op == TK_PIPE) pipe(fds); p->fdin = exec->fdin; diff --git a/42sh/src/exec/set_process_cmd.c b/42sh/src/exec/set_process_cmd.c index 9367917a..d923aa72 100644 --- a/42sh/src/exec/set_process_cmd.c +++ b/42sh/src/exec/set_process_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/08 15:55:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:13:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ int set_process_cmd(t_process *p, t_btree *ast) p->data.cmd.path = NULL; p->data.cmd.execf = NULL; p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); - DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]); + /* DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]); */ p->type = PROCESS_FILE; if ((func = is_function(p))) { @@ -40,7 +40,7 @@ int set_process_cmd(t_process *p, t_btree *ast) else if (ft_hash(p)) { p->data.cmd.execf = &execve; - DG("found hash at [%s]", p->data.cmd.path); + /* DG("found hash at [%s]", p->data.cmd.path); */ if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) { ft_memdel((void**)&p->data.cmd.stat); diff --git a/42sh/src/job-control/do_job_notification.c b/42sh/src/job-control/do_job_notification.c index 48829692..5977c224 100644 --- a/42sh/src/job-control/do_job_notification.c +++ b/42sh/src/job-control/do_job_notification.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ -/* Updated: 2017/03/03 16:46:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:36:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index 42c5229e..393aad41 100644 --- a/42sh/src/job-control/job_addprocess.c +++ b/42sh/src/job-control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:12:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:40:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ int job_addprocess(t_process *p) jobc = &data_singleton()->jobc; job = &data_singleton()->exec.job; + DG("adding pid=[%i] to job"); if (IS_PIPESTART(*p)) { job_update_id(); @@ -27,10 +28,7 @@ int job_addprocess(t_process *p) 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))); - } + ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p))); if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p)) job_notify_new(job); return (0); diff --git a/42sh/src/job-control/job_notify_change.c b/42sh/src/job-control/job_notify_change.c index 3ec46e79..9535b95a 100644 --- a/42sh/src/job-control/job_notify_change.c +++ b/42sh/src/job-control/job_notify_change.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */ -/* Updated: 2017/01/31 14:46:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:18:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_notify_new.c b/42sh/src/job-control/job_notify_new.c index d19feb96..3a4a19a8 100644 --- a/42sh/src/job-control/job_notify_new.c +++ b/42sh/src/job-control/job_notify_new.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:15:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:22:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index 5dcade64..64e3f7ee 100644 --- a/42sh/src/job-control/job_remove.c +++ b/42sh/src/job-control/job_remove.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ -/* Updated: 2017/03/08 15:06:12 by wescande ### ########.fr */ +/* Updated: 2017/03/08 17:41:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_update_status.c b/42sh/src/job-control/job_update_status.c index cae2b934..3549ee93 100644 --- a/42sh/src/job-control/job_update_status.c +++ b/42sh/src/job-control/job_update_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:56:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:41:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 966b5f3c..e0cd6195 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/03 19:42:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:24:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 9532bb25..fe5126ac 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2017/03/08 15:05:31 by wescande ### ########.fr */ +/* Updated: 2017/03/08 17:40:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/sigchld_handler.c b/42sh/src/job-control/sigchld_handler.c index 4fe9724a..22d4c8a6 100644 --- a/42sh/src/job-control/sigchld_handler.c +++ b/42sh/src/job-control/sigchld_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:30:35 by wescande ### ########.fr */ +/* Updated: 2017/03/08 17:21:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,5 @@ void sigchld_handler(int signo) { -// t_data *data; - (void)signo; -// data = data_singleton(); } diff --git a/42sh/src/lexer/lexer_heredoc.c b/42sh/src/lexer/lexer_heredoc.c index e655aee2..ba7fcecb 100644 --- a/42sh/src/lexer/lexer_heredoc.c +++ b/42sh/src/lexer/lexer_heredoc.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 15:51:17 by jhalford #+# #+# */ -/* Updated: 2017/03/08 15:53:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:46:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,9 @@ int lexer_heredoc(t_list **alst, t_lexer *lexer) token = (*alst)->content; token->type = HEREDOCDATA; - token_append_str(token, lexer->str, 0, 0); + while (lexer->str[lexer->pos]) + if (token_append_char(token, lexer->str[lexer->pos++], esc, esc2)) + return (1); return (0); /* heredoc_lst = *(t_list**)lexer->heredoc_stack->content; */ /* heredoc_tok = heredoc_lst->content; */ diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/src/lexer/lexer_sep.c index b44b41c5..980aad75 100644 --- a/42sh/src/lexer/lexer_sep.c +++ b/42sh/src/lexer/lexer_sep.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:20:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:11:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/token_append.c b/42sh/src/lexer/token_append.c index 45a45b97..72a5617b 100644 --- a/42sh/src/lexer/token_append.c +++ b/42sh/src/lexer/token_append.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */ -/* Updated: 2017/03/03 15:12:41 by wescande ### ########.fr */ +/* Updated: 2017/03/08 17:45:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/control_c_and_d.c b/42sh/src/line-editing/control_c_and_d.c index b80a982c..c4a24893 100644 --- a/42sh/src/line-editing/control_c_and_d.c +++ b/42sh/src/line-editing/control_c_and_d.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */ -/* Updated: 2017/03/08 12:56:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 17:37:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index a9a87efa..83817667 100644 --- a/42sh/src/line-editing/ft_prompt.c +++ b/42sh/src/line-editing/ft_prompt.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ -/* Updated: 2017/02/16 14:27:57 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 17:21:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */