Merge branch 'master' of https://github.com/jzck/42sh
"assignement word as word if in second position"
This commit is contained in:
commit
13ad0dfd34
17 changed files with 74 additions and 21 deletions
|
|
@ -94,6 +94,7 @@ exec/launch_until.c\
|
|||
exec/launch_while.c\
|
||||
exec/mark_process_status.c\
|
||||
exec/node_copy.c\
|
||||
exec/process_empty.c\
|
||||
exec/process_redirect.c\
|
||||
exec/process_reset.c\
|
||||
exec/process_resetfds.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/10 18:09:53 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:40:32 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -93,6 +93,7 @@ enum e_process_type
|
|||
PROCESS_IF,
|
||||
PROCESS_FOR,
|
||||
PROCESS_CASE,
|
||||
PROCESS_EMPTY,
|
||||
PROCESS_MAX
|
||||
};
|
||||
|
||||
|
|
@ -187,6 +188,7 @@ int launch_file(t_process *p);
|
|||
int launch_builtin(t_process *p);
|
||||
int launch_subshell(t_process *p);
|
||||
int launch_function(t_process *p);
|
||||
int launch_empty(t_process *p);
|
||||
|
||||
/*
|
||||
** Mapping pour set les process
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 14:29:46 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:19:36 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/13 14:37:01 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:40:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,7 +22,8 @@ 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("check");
|
||||
DG("forked pid=[%i]", p.pid);
|
||||
job_addprocess(&p);
|
||||
/* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */
|
||||
if (IS_PIPEEND(p))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 13:28:48 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:40:45 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 14:43:26 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:38:30 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,12 +23,14 @@ t_itof g_launchmap[] =
|
|||
{PROCESS_IF, launch_if},
|
||||
{PROCESS_FOR, launch_for},
|
||||
{PROCESS_CASE, launch_case},
|
||||
{PROCESS_EMPTY, launch_empty},
|
||||
};
|
||||
|
||||
int launch_process(t_process *p)
|
||||
{
|
||||
int pid;
|
||||
|
||||
DG("p->type=%i", p->type);
|
||||
if (p->type >= PROCESS_MAX)
|
||||
return (-1);
|
||||
if (!g_launchmap[p->type].f)
|
||||
|
|
@ -41,10 +43,13 @@ int launch_process(t_process *p)
|
|||
return (1);
|
||||
}
|
||||
p->pid = pid;
|
||||
DG("check");
|
||||
process_setgroup(p, pid);
|
||||
DG("check");
|
||||
if (p->fdin != STDIN)
|
||||
close(p->fdin);
|
||||
if (p->fdout != STDOUT)
|
||||
close(p->fdout);
|
||||
DG("check");
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
36
42sh/src/exec/process_empty.c
Normal file
36
42sh/src/exec/process_empty.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* process_empty.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/13 17:26:01 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 17:31:05 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int launch_empty(t_process *p)
|
||||
{
|
||||
int pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
{
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
exec_reset();
|
||||
DG("empty exit");
|
||||
exit(0);
|
||||
}
|
||||
else if (pid > 0)
|
||||
return (pid);
|
||||
else if (pid == -1)
|
||||
ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/06 14:58:57 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:40:54 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,6 @@ int redirect_great(t_redir* redir)
|
|||
int fdnew;
|
||||
|
||||
fdnew = redir->n;
|
||||
DG("redir great");
|
||||
if ((fdold = open(redir->word,
|
||||
O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/06 15:05:40 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:42:53 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,10 +18,9 @@ int redirect_less(t_redir *redir)
|
|||
int fdnew;
|
||||
|
||||
fdnew = redir->n;
|
||||
DG("redirect less");
|
||||
if ((fdold = open(redir->word, O_RDONLY)) < 0)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: no such file or directory: %s{eoc}\n",
|
||||
ft_dprintf(2, "{red}%s: %s: no such file or directory\n",
|
||||
SHELL_NAME, redir->word);
|
||||
exit (1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 14:18:11 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:38:56 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ int set_process(t_process *p, t_btree *ast)
|
|||
if (op == TK_PIPE)
|
||||
{
|
||||
pipe(fds);
|
||||
DG("[%i] -> PIPE -> [%i]", fds[PIPE_WRITE], fds[PIPE_READ]);
|
||||
/* DG("[%i] -> PIPE -> [%i]", fds[PIPE_WRITE], fds[PIPE_READ]); */
|
||||
}
|
||||
p->fdin = exec->fdin;
|
||||
p->to_close = fds[PIPE_READ];
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 15:06:05 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/08 18:49:55 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:40:37 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,7 +17,10 @@ int set_process_cmd(t_process *p, t_btree *ast)
|
|||
t_btree *func;
|
||||
|
||||
if (!(p->data.cmd.av = token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1)))
|
||||
return (1);
|
||||
{
|
||||
p->type = PROCESS_EMPTY;
|
||||
return (0);
|
||||
}
|
||||
p->data.cmd.path = NULL;
|
||||
p->data.cmd.execf = NULL;
|
||||
p->data.cmd.stat = ft_memalloc(sizeof(struct stat));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 15:08:12 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/11 13:27:13 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:39:03 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 15:55:53 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/07 15:56:25 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:23:53 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 15:29:09 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:36:32 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/08 20:13:57 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:33:32 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,6 +23,7 @@ t_itof g_freemap[] =
|
|||
{PROCESS_IF, process_free_cond},
|
||||
{PROCESS_FOR, process_free_list},
|
||||
{PROCESS_CASE, process_free_list},
|
||||
{PROCESS_EMPTY, NULL},
|
||||
};
|
||||
|
||||
void process_free(void *content, size_t content_size)
|
||||
|
|
@ -31,10 +32,13 @@ void process_free(void *content, size_t content_size)
|
|||
|
||||
p = content;
|
||||
(void)content_size;
|
||||
DG("gonna free");
|
||||
if (p->type >= PROCESS_MAX)
|
||||
return ;
|
||||
DG("gonna free");
|
||||
if (g_freemap[p->type].f)
|
||||
(g_freemap[p->type].f)(p);
|
||||
DG("gonna free");
|
||||
ft_lstdel(&p->redirs, redir_free);
|
||||
free(p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 14:03:43 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/13 17:37:04 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,9 +26,11 @@ 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)) */
|
||||
DG("check");
|
||||
job_wait(j->id);
|
||||
DG("check");
|
||||
job_remove(j->id);
|
||||
DG("check");
|
||||
if (SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||
{
|
||||
tcsetpgrp(STDIN, jobc->shell_pgid);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/13 17:51:05 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue