55 lines
1.9 KiB
C
55 lines
1.9 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* set_process.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
|
|
/* Updated: 2017/03/07 15:09:36 by jhalford ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "exec.h"
|
|
|
|
int set_process(t_process *p, t_btree *ast)
|
|
{
|
|
t_exec *exec;
|
|
t_cmd *cmd;
|
|
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)
|
|
&& ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") != 0)
|
|
|| (EXEC_IS_OR_IF(exec->attrs)
|
|
&& ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0))
|
|
return (1);
|
|
if (!(p->av = token_to_argv(cmd->token, 1)))
|
|
return (1);
|
|
fds[PIPE_WRITE] = STDOUT;
|
|
fds[PIPE_READ] = STDIN;
|
|
if (op == TK_AMP)
|
|
exec->attrs |= JOB_BG;
|
|
else if (op == TK_PIPE)
|
|
pipe(fds);
|
|
p->fdin = exec->fdin;
|
|
p->to_close = fds[PIPE_READ];
|
|
p->fdout = fds[PIPE_WRITE];
|
|
exec->fdin = fds[PIPE_READ];
|
|
p->redirs = ft_lstmap(cmd->redir, ft_id);
|
|
t_list *tmp = p->redirs;
|
|
while (tmp)
|
|
{
|
|
t_redir *toto = tmp->content;
|
|
printf("IIIIIIIIIIIIIIIIIIIIIII%lld |%d| {%s}\n", toto->type, toto->n, toto->word);
|
|
tmp= tmp->next;
|
|
}
|
|
process_setexec(p);
|
|
if (exec->control_count)
|
|
p->attrs |= PROCESS_CONTROL;
|
|
return (0);
|
|
}
|