diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 32d1156a..00985ade 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/11 16:06:07 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:29:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 5ae9561a..c132a271 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -154,7 +154,7 @@ int join_ast(t_btree **ast, t_btree **new_node); int gen_node(t_btree **ast); int superflous_token(t_btree **ast, t_list **list); -int ft_show_heredoc_data(t_btree **ast); +int ft_show_heredoc_data(t_astnode *node); struct s_distrostree { diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index ea146188..f00c59da 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */ -/* Updated: 2017/03/09 15:14:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:47:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index c367c141..de370722 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/11 18:32:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:37:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,13 +22,14 @@ int exec_leaf(t_btree **ast) return (1); if (!(launch_process(&p))) { - /* DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]); */ + DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]); job_addprocess(&p); /* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */ if (IS_PIPEEND(p)) { if (JOB_IS_FG(job->attrs)) put_job_in_foreground(job, 0); + DG("job->pgid RESET (end of pipe)"); job->pgid = 0; } } diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 4d5e0762..9ed829d3 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:45:12 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:03:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index 3a005fa9..86d96c83 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/11 18:16:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 13:28:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,10 +22,10 @@ int launch_file(t_process *p) /* data_singleton()->opts &= ~SH_INTERACTIVE; */ /* data_singleton()->opts &= ~SH_OPTS_JOBC; */ /* DG("fork! [%s]", p->data.cmd.av[0]); */ - process_setgroup(p, 0); - process_setsig(); if (process_redirect(p)) exit (1); + process_setgroup(p, 0); + process_setsig(); exec_reset(); if (!p->data.cmd.path) { diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 57bb96dd..3d6a30ed 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/11 17:59:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:43:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_subshell.c b/42sh/src/exec/launch_subshell.c index cc7cd24d..087f2e73 100644 --- a/42sh/src/exec/launch_subshell.c +++ b/42sh/src/exec/launch_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ -/* Updated: 2017/03/11 18:09:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 13:27:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,10 +36,10 @@ int launch_subshell(t_process *p) { data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; - process_setgroup(p, 0); - process_setsig(); if (process_redirect(p)) exit (1); + process_setgroup(p, 0); + process_setsig(); exec_reset(); exit(do_subshell(p)); } diff --git a/42sh/src/exec/launch_while.c b/42sh/src/exec/launch_while.c index 81f49a83..7dfafe7d 100644 --- a/42sh/src/exec/launch_while.c +++ b/42sh/src/exec/launch_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/11 17:45:18 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:18:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index ddceb6af..b433aa4d 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/11 19:44:31 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:01:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,8 +33,9 @@ int process_redirect(t_process *p) while (redirs) { redir = redirs->content; - DG("redirs content : %p", redirs->content); -// DG("redir.type [%li]", redir->type); + /* DG("redirs content : %p", redirs->content); */ + DG("redir @ %p", redir); + DG("redir.type [%li]", redir->type); DG("redir.word [%s]", redir->word); DG("redir.n [%i]", redir->n); if (redir->n > 9) diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 35b83760..21577578 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/03/11 16:07:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 13:37:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,10 @@ int process_setgroup(t_process *p, pid_t pid) return (0); DG("setpgid(%i, %i)", pid, j->pgid); if (setpgid(pid, j->pgid) == -1) - ft_dprintf(2, "{red}%s: internal setpgid() error{eoc}\n", SHELL_NAME); + { + ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", SHELL_NAME, errno); + perror(""); + } if (pid == 0 && JOB_IS_FG(j->attrs)) { DG("tcsetpgrp[%i]", j->pgid); diff --git a/42sh/src/exec/redir_copy.c b/42sh/src/exec/redir_copy.c index 3dea51e4..055efcd4 100644 --- a/42sh/src/exec/redir_copy.c +++ b/42sh/src/exec/redir_copy.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:58 by ariard #+# #+# */ -/* Updated: 2017/03/08 11:53:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:20:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,5 +24,6 @@ void *redir_copy(void *data) new->type = old->type; new->n = old->n; new->word = ft_strdup(old->word); + new->heredoc_data = ft_strdup(old->heredoc_data); return (new); } diff --git a/42sh/src/exec/redirect_dless.c b/42sh/src/exec/redirect_dless.c index 5fb50aa9..5bcd3aa3 100644 --- a/42sh/src/exec/redirect_dless.c +++ b/42sh/src/exec/redirect_dless.c @@ -18,7 +18,8 @@ int redirect_dless(t_redir *redir) pipe(fds); str = redir->heredoc_data; - DG("[%s] && adr %p", str, redir); + DG("[%s] && adr %p", str, str); + DG("redir @ %p", redir); write(fds[PIPE_WRITE], str, ft_strlen(str)); close(fds[PIPE_WRITE]); dup2(fds[PIPE_READ], 0); diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index 2be25490..4461fc05 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/11 17:49:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:18:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/history/add_str_in_history.c b/42sh/src/history/add_str_in_history.c index 333f5225..0a8c95ee 100644 --- a/42sh/src/history/add_str_in_history.c +++ b/42sh/src/history/add_str_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/14 11:27:03 by gwojda #+# #+# */ -/* Updated: 2017/03/10 12:59:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:30:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/history/list_toolz.c b/42sh/src/history/list_toolz.c index b3b17fb1..a12fd6a8 100644 --- a/42sh/src/history/list_toolz.c +++ b/42sh/src/history/list_toolz.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */ -/* Updated: 2017/03/09 11:21:06 by gwojda ### ########.fr */ +/* Updated: 2017/03/13 14:47:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,13 +16,13 @@ void free_history_list(t_list_history *head) { t_list_history *prev; - free(head->prev); + if (!head) + return ; while (head) { ft_strdel(&head->str); prev = head; head = head->next; - free(prev); } } diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index d4f63cd6..15305beb 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/11 16:00:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 13:22:22 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 d2e9479b..726d899e 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/11 18:22:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 14:03:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,7 @@ int put_job_in_foreground(t_job *j, int cont) if (kill(-j->pgid, SIGCONT) < 0) DG("kill(SIGCONT) failed"); } + /* if (SH_IS_INTERACTIVE(data_singleton()->opts)) */ job_wait(j->id); job_remove(j->id); if (SH_IS_INTERACTIVE(data_singleton()->opts)) diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 5c75131c..a30d7d38 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/10 15:48:30 by gwojda ### ########.fr */ +/* Updated: 2017/03/13 14:43:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,15 +15,11 @@ int readline(int fd, int prompt, char **input) { if (!SH_IS_INTERACTIVE(data_singleton()->opts)) - { - if (get_next_line(fd, input) == 0) - return (1); - return (0); - } + return (get_next_line(fd, input) == 0); readline_init(prompt); *input = ft_read_stdin(); if (STR) - ft_current_str(STR, POS); + ft_current_str(STR, POS); ft_putchar('\n'); if (!prompt) *input = ft_history_parsing(); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 78c251b6..be0aeb36 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/13 14:08:29 by ariard ### ########.fr */ +/* Updated: 2017/03/13 15:03:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,11 +31,13 @@ int handle_instruction(int fd) if ((ret = readline(fd, get_lexer_stack(lexer) || parser.state == UNDEFINED || lexer.state == HEREDOC, &str))) { + DG("readline trap"); if (ret == -1) return (-1); return (parser.state == UNDEFINED ? error_eof(&token, &parser, &ast) : 1); } + DG("INPUT STRING IS [%s]", str); if (lexer.state == HEREDOC) { ft_strappend(&lexer.str, (char[]){'\n', 0}); @@ -70,12 +72,12 @@ int handle_instruction(int fd) return (error_syntax(&token, &parser, &ast)); } } -// ft_show_heredoc_data(&ast); btree_print(STDBUG, ast, &ft_putast); if (ft_exec(&ast)) return (1); instruction_free(&token, &parser, &ast); - ft_add_str_in_history(lexer.str); + if (SH_IS_INTERACTIVE(data_singleton()->opts)) + ft_add_str_in_history(lexer.str); return (0); } @@ -123,11 +125,8 @@ int main(int ac, char **av) } DG("JOBC is %s, fd=[%i]", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd); while (handle_instruction(fd) == 0) - { -// lexer_clean; -// parser_clean; ; - } + DG("gonna exit"); builtin_exit(NULL, NULL, NULL); return (0); } diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 90eda442..c66215e2 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,7 +6,6 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/03/13 14:58:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/error_syntax.c b/42sh/src/parser/error_syntax.c index 6165e443..f74ae423 100644 --- a/42sh/src/parser/error_syntax.c +++ b/42sh/src/parser/error_syntax.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:15:35 by ariard #+# #+# */ -/* Updated: 2017/03/11 16:10:56 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:41:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/heredoc_parser.c b/42sh/src/parser/heredoc_parser.c index eb4f8b68..2b84d738 100644 --- a/42sh/src/parser/heredoc_parser.c +++ b/42sh/src/parser/heredoc_parser.c @@ -6,7 +6,6 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 16:21:05 by ariard #+# #+# */ -/* Updated: 2017/03/13 14:58:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index b746dfa3..4d91117c 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/03/11 19:55:57 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:13:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -224,18 +224,16 @@ int ft_read_stack(t_sym *stack) } -int ft_show_heredoc_data(t_btree **ast) +int ft_show_heredoc_data(t_astnode *node) { - t_astnode *node; t_redir *redir; - if (*ast) - if ((*ast)->left) - { - node = ((*ast)->left)->item; - redir = (node->data.cmd.redir)->content; - if (redir->type == TK_DLESS) - DG("Show me heredoc data from node :%s", redir->heredoc_data); - } + if (node->type != CMD) + return (1); + redir = (node->data.cmd.redir)->content; + if (redir->type != TK_DLESS) + return (1); + DG("heredoc_data=[%s] @ %p", redir->heredoc_data, redir->heredoc_data); + DG("redir @ %p", redir); return (0); }