pull ok
This commit is contained in:
commit
5c6abae6dc
17 changed files with 40 additions and 35 deletions
|
|
@ -23,7 +23,7 @@
|
||||||
| TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE)
|
| TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE)
|
||||||
enum e_lexstate
|
enum e_lexstate
|
||||||
{
|
{
|
||||||
DEFAULT,
|
DEFAULT, //#define DEFAULT 0
|
||||||
PAREN,
|
PAREN,
|
||||||
HEREDOC,
|
HEREDOC,
|
||||||
NEWLINE,
|
NEWLINE,
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ void c_printer(t_comp *c)
|
||||||
t_clst *ptr;
|
t_clst *ptr;
|
||||||
int loop;
|
int loop;
|
||||||
int max_line;
|
int max_line;
|
||||||
int offset;
|
//int offset;
|
||||||
|
|
||||||
loop = c->c_line;
|
loop = c->c_line;
|
||||||
|
|
||||||
|
|
@ -133,7 +133,7 @@ void c_printer(t_comp *c)
|
||||||
max_line = (c->c_line % (c->m_size - 1));
|
max_line = (c->c_line % (c->m_size - 1));
|
||||||
else
|
else
|
||||||
max_line = c->m_size - 1;
|
max_line = c->m_size - 1;
|
||||||
offset = (c->m_size - 1) - max_line;
|
// offset = (c->m_size - 1) - max_line;
|
||||||
while (loop && max_line)
|
while (loop && max_line)
|
||||||
{
|
{
|
||||||
c_printer_line(c, ptr, c->c_pline, 1);
|
c_printer_line(c, ptr, c->c_pline, 1);
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ int exec_leaf(t_btree **ast)
|
||||||
return (1);
|
return (1);
|
||||||
if (!(launch_process(&p)))
|
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);
|
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 (IS_PIPEEND(p))
|
||||||
{
|
{
|
||||||
if (JOB_IS_FG(job->attrs))
|
if (JOB_IS_FG(job->attrs))
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ int launch_file(t_process *p)
|
||||||
{
|
{
|
||||||
/* data_singleton()->opts &= ~SH_INTERACTIVE; */
|
/* data_singleton()->opts &= ~SH_INTERACTIVE; */
|
||||||
/* data_singleton()->opts &= ~SH_OPTS_JOBC; */
|
/* 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_setgroup(p, 0);
|
||||||
process_setsig();
|
process_setsig();
|
||||||
if (process_redirect(p))
|
if (process_redirect(p))
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ int launch_process(t_process *p)
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
DG("launchprocess");
|
|
||||||
if (p->type >= PROCESS_MAX)
|
if (p->type >= PROCESS_MAX)
|
||||||
return (-1);
|
return (-1);
|
||||||
if (!g_launchmap[p->type].f)
|
if (!g_launchmap[p->type].f)
|
||||||
|
|
@ -38,7 +37,6 @@ int launch_process(t_process *p)
|
||||||
p->attrs |= PROCESS_RUNNING;
|
p->attrs |= PROCESS_RUNNING;
|
||||||
if (!(pid = (*g_launchmap[p->type].f)(p)))
|
if (!(pid = (*g_launchmap[p->type].f)(p)))
|
||||||
{
|
{
|
||||||
DG("gonna reset fds");
|
|
||||||
process_resetfds(p);
|
process_resetfds(p);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ static int do_subshell(t_process *p)
|
||||||
ft_exec(&p->data.subshell.content);
|
ft_exec(&p->data.subshell.content);
|
||||||
ret = ft_atoi(ft_getenv(data_singleton()->env, "?"));
|
ret = ft_atoi(ft_getenv(data_singleton()->env, "?"));
|
||||||
DG("CHECK, ret=[%i]", ret);
|
DG("CHECK, ret=[%i]", ret);
|
||||||
|
/* p = ft_lstlast(j->first_process)->content; */
|
||||||
|
/* ret = p->status */
|
||||||
|
/* DG("CHECK, ret=[%i]", ret); */
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ int mark_process_status(pid_t pid, int status)
|
||||||
{
|
{
|
||||||
p = plist->content;
|
p = plist->content;
|
||||||
p->status = status;
|
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))
|
if (WIFSTOPPED(status))
|
||||||
{
|
{
|
||||||
p->attrs &= ~PROCESS_STATE_MASK;
|
p->attrs &= ~PROCESS_STATE_MASK;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ int process_redirect(t_process *p)
|
||||||
{
|
{
|
||||||
redir = redirs->content;
|
redir = redirs->content;
|
||||||
DG("redirs content : %p", 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.word [%s]", redir->word);
|
||||||
DG("redir.n [%i]", redir->n);
|
DG("redir.n [%i]", redir->n);
|
||||||
if (redir->n > 9)
|
if (redir->n > 9)
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,16 @@ int process_setgroup(t_process *p, pid_t pid)
|
||||||
(void)p;
|
(void)p;
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
j = &data->exec.job;
|
j = &data->exec.job;
|
||||||
|
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||||
|
return (0);
|
||||||
DG("setpgid(%i, %i)", pid, j->pgid);
|
DG("setpgid(%i, %i)", pid, j->pgid);
|
||||||
if (setpgid(pid, j->pgid) == -1)
|
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() error{eoc}\n", SHELL_NAME);
|
||||||
if (pid == 0 && JOB_IS_FG(j->attrs))
|
if (pid == 0 && JOB_IS_FG(j->attrs))
|
||||||
{
|
{
|
||||||
DG("I'm taking the terminal !");
|
DG("tcsetpgrp[%i]", j->pgid);
|
||||||
tcsetpgrp(STDIN, j->pgid);
|
tcsetpgrp(STDIN, j->pgid);
|
||||||
|
DG("after tcsetpgrp");
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,5 +19,7 @@ void process_setsig(void)
|
||||||
signal(SIGTSTP, SIG_DFL);
|
signal(SIGTSTP, SIG_DFL);
|
||||||
signal(SIGTTIN, SIG_DFL);
|
signal(SIGTTIN, SIG_DFL);
|
||||||
signal(SIGTTOU, SIG_DFL);
|
signal(SIGTTOU, SIG_DFL);
|
||||||
|
/* signal(SIGTTIN, sigttin_handler); */
|
||||||
|
/* signal(SIGTTOU, sigttou_handler); */
|
||||||
signal(SIGCHLD, SIG_DFL);
|
signal(SIGCHLD, SIG_DFL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 *
|
ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p + gl->cur_dir * 2 *
|
||||||
(p[0] == '.' && p[1] == '/'), "/"));
|
(p[0] == '.' && p[1] == '/'), "/"));
|
||||||
else
|
else
|
||||||
ft_ld_pushfront(&gl->match_tmp, ft_strdup(""));
|
ft_ld_pushfront(&gl->match_tmp, ft_strdup(CH(gl->m_pat)[0]));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p))
|
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p))
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ int job_addprocess(t_process *p)
|
||||||
{
|
{
|
||||||
job_update_id();
|
job_update_id();
|
||||||
job->id = jobc->current_id;
|
job->id = jobc->current_id;
|
||||||
/* job->pgid = SH_HAS_JOBC(data_singleton()->opts) ? p->pid : getpid(); */
|
job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ? p->pid : getpgid(0);
|
||||||
job->pgid = p->pid;
|
/* job->pgid = p->pid; */
|
||||||
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
||||||
}
|
}
|
||||||
DG("adding pid=[%i] to pgid=[%i]", p->pid, job->pgid);
|
DG("adding pid=[%i] to pgid=[%i]", p->pid, job->pgid);
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ void job_remove(int id)
|
||||||
if (job_is_completed(id))
|
if (job_is_completed(id))
|
||||||
{
|
{
|
||||||
p = ft_lstlast(j->first_process)->content;
|
p = ft_lstlast(j->first_process)->content;
|
||||||
|
/* DG("remove, status=%i", p->status); */
|
||||||
set_exitstatus(p->status, 0);
|
set_exitstatus(p->status, 0);
|
||||||
if (id < data_singleton()->jobc.current_id)
|
if (id < data_singleton()->jobc.current_id)
|
||||||
data_singleton()->jobc.current_id = id;
|
data_singleton()->jobc.current_id = id;
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ int put_job_in_foreground(t_job *j, int cont)
|
||||||
t_jobc *jobc;
|
t_jobc *jobc;
|
||||||
|
|
||||||
jobc = &data_singleton()->jobc;
|
jobc = &data_singleton()->jobc;
|
||||||
DG("giving terminal to pgid->[%i]", j->pgid);
|
DG("tcsetpgrp[%i]", j->pgid);
|
||||||
|
if (SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||||
tcsetpgrp(STDIN, j->pgid);
|
tcsetpgrp(STDIN, j->pgid);
|
||||||
|
|
||||||
if (cont)
|
if (cont)
|
||||||
{
|
{
|
||||||
tcsetattr(STDIN, TCSADRAIN, &j->tmodes);
|
tcsetattr(STDIN, TCSADRAIN, &j->tmodes);
|
||||||
|
|
@ -28,8 +28,7 @@ int put_job_in_foreground(t_job *j, int cont)
|
||||||
}
|
}
|
||||||
job_wait(j->id);
|
job_wait(j->id);
|
||||||
job_remove(j->id);
|
job_remove(j->id);
|
||||||
|
if (SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||||
if (SH_HAS_JOBC(data_singleton()->opts))
|
|
||||||
{
|
{
|
||||||
tcsetpgrp(STDIN, jobc->shell_pgid);
|
tcsetpgrp(STDIN, jobc->shell_pgid);
|
||||||
tcgetattr(STDIN, &j->tmodes);
|
tcgetattr(STDIN, &j->tmodes);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 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);
|
DG("JOBC is %s, fd=[%i]", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd);
|
||||||
while (handle_instruction(fd) == 0)
|
while (handle_instruction(fd) == 0)
|
||||||
{
|
{
|
||||||
DG();
|
|
||||||
// lexer_clean;
|
// lexer_clean;
|
||||||
// parser_clean;
|
// parser_clean;
|
||||||
;
|
;
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@
|
||||||
int iscondition(t_btree **ast, t_list **lst)
|
int iscondition(t_btree **ast, t_list **lst)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
t_token *token;
|
// t_token *token;
|
||||||
|
|
||||||
node = NULL;
|
node = NULL;
|
||||||
token = (*lst)->content;
|
// token = (*lst)->content;
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,18 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/11 14:54: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"
|
#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;
|
t_astnode *node;
|
||||||
|
|
||||||
token = (*lst)->content;
|
// token = (*lst)->content;
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
|
|
@ -27,12 +27,12 @@ static int isdir_sep_condition(t_btree **ast, t_list **lst)
|
||||||
return (0);
|
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;
|
t_astnode *node;
|
||||||
|
|
||||||
token = (*lst)->content;
|
// token = (*lst)->content;
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
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)
|
int isdir_condition(t_btree **ast, t_list **lst)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
t_astnode *node;
|
// t_astnode *node;
|
||||||
|
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
// node = (*ast)->item;
|
||||||
if ((token->type == TK_LESS || token->type == TK_GREAT
|
if ((token->type == TK_LESS || token->type == TK_GREAT
|
||||||
|| token->type == TK_GREATAND || token->type == TK_LESSAND
|
|| token->type == TK_GREATAND || token->type == TK_LESSAND
|
||||||
|| token->type == TK_DLESS || token->type == TK_DGREAT)
|
|| token->type == TK_DLESS || token->type == TK_DGREAT)
|
||||||
&& isdir_sep_condition(&(*ast)->left, lst) == 1)
|
&& isdir_sep_condition(&(*ast)->left) == 1)
|
||||||
return (1);
|
return (1);
|
||||||
if (token->type == TK_WORD
|
if (token->type == TK_WORD
|
||||||
&& isdir_word_condition(&(*ast)->left, lst) == 1)
|
&& isdir_word_condition(&(*ast)->left) == 1)
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue