diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 7c5e0999..618939db 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -23,7 +23,7 @@ | TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE) enum e_lexstate { - DEFAULT, + DEFAULT, //#define DEFAULT 0 PAREN, HEREDOC, NEWLINE, diff --git a/42sh/src/completion/c_printer.c b/42sh/src/completion/c_printer.c index 57908b3a..050212e8 100644 --- a/42sh/src/completion/c_printer.c +++ b/42sh/src/completion/c_printer.c @@ -123,7 +123,7 @@ void c_printer(t_comp *c) t_clst *ptr; int loop; int max_line; - int offset; + //int offset; loop = c->c_line; @@ -133,7 +133,7 @@ void c_printer(t_comp *c) max_line = (c->c_line % (c->m_size - 1)); else max_line = c->m_size - 1; - offset = (c->m_size - 1) - max_line; +// offset = (c->m_size - 1) - max_line; while (loop && max_line) { c_printer_line(c, ptr, c->c_pline, 1); diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 10d7b78f..c367c141 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -22,9 +22,9 @@ 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)); + /* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */ if (IS_PIPEEND(p)) { if (JOB_IS_FG(job->attrs)) diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index 977b944e..3a005fa9 100644 --- a/42sh/src/exec/launch_file.c +++ b/42sh/src/exec/launch_file.c @@ -21,7 +21,7 @@ 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]); + /* DG("fork! [%s]", p->data.cmd.av[0]); */ process_setgroup(p, 0); process_setsig(); if (process_redirect(p)) diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 666620c4..57bb96dd 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -29,7 +29,6 @@ int launch_process(t_process *p) { int pid; - DG("launchprocess"); if (p->type >= PROCESS_MAX) return (-1); if (!g_launchmap[p->type].f) @@ -38,7 +37,6 @@ int launch_process(t_process *p) p->attrs |= PROCESS_RUNNING; if (!(pid = (*g_launchmap[p->type].f)(p))) { - DG("gonna reset fds"); process_resetfds(p); return (1); } diff --git a/42sh/src/exec/launch_subshell.c b/42sh/src/exec/launch_subshell.c index 1861e144..cc7cd24d 100644 --- a/42sh/src/exec/launch_subshell.c +++ b/42sh/src/exec/launch_subshell.c @@ -14,11 +14,14 @@ static int do_subshell(t_process *p) { - int ret; + int ret; ft_exec(&p->data.subshell.content); ret = ft_atoi(ft_getenv(data_singleton()->env, "?")); DG("CHECK, ret=[%i]", ret); + /* p = ft_lstlast(j->first_process)->content; */ + /* ret = p->status */ + /* DG("CHECK, ret=[%i]", ret); */ return (ret); } diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 02d74dc6..6a7eca78 100644 --- a/42sh/src/exec/mark_process_status.c +++ b/42sh/src/exec/mark_process_status.c @@ -32,7 +32,7 @@ int mark_process_status(pid_t pid, int status) { p = plist->content; p->status = status; - DG("marking pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]); + /* DG("found pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]); */ if (WIFSTOPPED(status)) { p->attrs &= ~PROCESS_STATE_MASK; diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index 35214223..ddceb6af 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -34,7 +34,7 @@ int process_redirect(t_process *p) { redir = redirs->content; DG("redirs content : %p", redirs->content); - DG("redir.type [%i]", redir->type); +// 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 f23c2100..35b83760 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -21,13 +21,16 @@ int process_setgroup(t_process *p, pid_t pid) (void)p; data = data_singleton(); j = &data->exec.job; + if (!SH_IS_INTERACTIVE(data_singleton()->opts)) + 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); if (pid == 0 && JOB_IS_FG(j->attrs)) { - DG("I'm taking the terminal !"); + DG("tcsetpgrp[%i]", j->pgid); tcsetpgrp(STDIN, j->pgid); + DG("after tcsetpgrp"); } return (0); } diff --git a/42sh/src/exec/process_setsig.c b/42sh/src/exec/process_setsig.c index 03c2ed46..96b44ad1 100644 --- a/42sh/src/exec/process_setsig.c +++ b/42sh/src/exec/process_setsig.c @@ -19,5 +19,7 @@ void process_setsig(void) signal(SIGTSTP, SIG_DFL); signal(SIGTTIN, SIG_DFL); signal(SIGTTOU, SIG_DFL); + /* signal(SIGTTIN, sigttin_handler); */ + /* signal(SIGTTOU, sigttou_handler); */ signal(SIGCHLD, SIG_DFL); } diff --git a/42sh/src/glob/dir_glob.c b/42sh/src/glob/dir_glob.c index 18401efe..895d6d08 100644 --- a/42sh/src/glob/dir_glob.c +++ b/42sh/src/glob/dir_glob.c @@ -58,7 +58,7 @@ int dir_research(t_glob *gl, char *p, ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p + gl->cur_dir * 2 * (p[0] == '.' && p[1] == '/'), "/")); else - ft_ld_pushfront(&gl->match_tmp, ft_strdup("")); + ft_ld_pushfront(&gl->match_tmp, ft_strdup(CH(gl->m_pat)[0])); return (0); } if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p)) diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index 255cfdb4..f56a02e5 100644 --- a/42sh/src/job-control/job_addprocess.c +++ b/42sh/src/job-control/job_addprocess.c @@ -23,8 +23,8 @@ int job_addprocess(t_process *p) { job_update_id(); job->id = jobc->current_id; - /* job->pgid = SH_HAS_JOBC(data_singleton()->opts) ? p->pid : getpid(); */ - job->pgid = p->pid; + job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ? p->pid : getpgid(0); + /* job->pgid = p->pid; */ ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); } DG("adding pid=[%i] to pgid=[%i]", p->pid, job->pgid); diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index 45f24e9f..fed549a5 100644 --- a/42sh/src/job-control/job_remove.c +++ b/42sh/src/job-control/job_remove.c @@ -23,6 +23,7 @@ void job_remove(int id) if (job_is_completed(id)) { p = ft_lstlast(j->first_process)->content; + /* DG("remove, status=%i", p->status); */ set_exitstatus(p->status, 0); if (id < data_singleton()->jobc.current_id) data_singleton()->jobc.current_id = id; diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index b90d2c7a..d2e9479b 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -17,9 +17,9 @@ int put_job_in_foreground(t_job *j, int cont) t_jobc *jobc; jobc = &data_singleton()->jobc; - DG("giving terminal to pgid->[%i]", j->pgid); - tcsetpgrp(STDIN, j->pgid); - + DG("tcsetpgrp[%i]", j->pgid); + if (SH_IS_INTERACTIVE(data_singleton()->opts)) + tcsetpgrp(STDIN, j->pgid); if (cont) { tcsetattr(STDIN, TCSADRAIN, &j->tmodes); @@ -28,8 +28,7 @@ int put_job_in_foreground(t_job *j, int cont) } job_wait(j->id); job_remove(j->id); - - if (SH_HAS_JOBC(data_singleton()->opts)) + if (SH_IS_INTERACTIVE(data_singleton()->opts)) { tcsetpgrp(STDIN, jobc->shell_pgid); tcgetattr(STDIN, &j->tmodes); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index adbc9de5..78c251b6 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/11 20:05:07 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:08:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -124,7 +124,6 @@ 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) { - DG(); // lexer_clean; // parser_clean; ; diff --git a/42sh/src/parser/add_condition.c b/42sh/src/parser/add_condition.c index 2825ace2..426d3572 100644 --- a/42sh/src/parser/add_condition.c +++ b/42sh/src/parser/add_condition.c @@ -15,10 +15,10 @@ int iscondition(t_btree **ast, t_list **lst) { t_astnode *node; - t_token *token; +// t_token *token; node = NULL; - token = (*lst)->content; +// token = (*lst)->content; if (*ast) { node = (*ast)->item; diff --git a/42sh/src/parser/add_redir_condition.c b/42sh/src/parser/add_redir_condition.c index 30569f8d..2ccf221d 100644 --- a/42sh/src/parser/add_redir_condition.c +++ b/42sh/src/parser/add_redir_condition.c @@ -6,18 +6,18 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 14:54:18 by ariard #+# #+# */ -/* Updated: 2017/03/11 20:05:41 by ariard ### ########.fr */ +/* Updated: 2017/03/13 14:08:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int isdir_sep_condition(t_btree **ast, t_list **lst) +static int isdir_sep_condition(t_btree **ast)//, t_list **lst) { - t_token *token; +// t_token *token; t_astnode *node; - token = (*lst)->content; +// token = (*lst)->content; if (*ast) { node = (*ast)->item; @@ -27,12 +27,12 @@ static int isdir_sep_condition(t_btree **ast, t_list **lst) return (0); } -static int isdir_word_condition(t_btree **ast, t_list **lst) +static int isdir_word_condition(t_btree **ast)//, t_list **lst) { - t_token *token; +// t_token *token; t_astnode *node; - token = (*lst)->content; +// token = (*lst)->content; if (*ast) { node = (*ast)->item; @@ -45,19 +45,19 @@ static int isdir_word_condition(t_btree **ast, t_list **lst) int isdir_condition(t_btree **ast, t_list **lst) { t_token *token; - t_astnode *node; +// t_astnode *node; token = (*lst)->content; if (*ast) { - node = (*ast)->item; +// node = (*ast)->item; if ((token->type == TK_LESS || token->type == TK_GREAT || token->type == TK_GREATAND || token->type == TK_LESSAND || token->type == TK_DLESS || token->type == TK_DGREAT) - && isdir_sep_condition(&(*ast)->left, lst) == 1) + && isdir_sep_condition(&(*ast)->left) == 1) return (1); if (token->type == TK_WORD - && isdir_word_condition(&(*ast)->left, lst) == 1) + && isdir_word_condition(&(*ast)->left) == 1) return (1); } return (0);