subshell + heredoc correct
This commit is contained in:
commit
923416fdda
24 changed files with 55 additions and 56 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:55:09 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ int join_ast(t_btree **ast, t_btree **new_node);
|
||||||
int gen_node(t_btree **ast);
|
int gen_node(t_btree **ast);
|
||||||
int superflous_token(t_btree **ast, t_list **list);
|
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
|
struct s_distrostree
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:28:41 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 15:47:30 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);
|
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))
|
||||||
put_job_in_foreground(job, 0);
|
put_job_in_foreground(job, 0);
|
||||||
|
DG("job->pgid RESET (end of pipe)");
|
||||||
job->pgid = 0;
|
job->pgid = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:30:32 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 14:53:31 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_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_setsig();
|
|
||||||
if (process_redirect(p))
|
if (process_redirect(p))
|
||||||
exit (1);
|
exit (1);
|
||||||
|
process_setgroup(p, 0);
|
||||||
|
process_setsig();
|
||||||
exec_reset();
|
exec_reset();
|
||||||
if (!p->data.cmd.path)
|
if (!p->data.cmd.path)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 14:20:45 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/08 00:11:44 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_INTERACTIVE;
|
||||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
||||||
process_setgroup(p, 0);
|
|
||||||
process_setsig();
|
|
||||||
if (process_redirect(p))
|
if (process_redirect(p))
|
||||||
exit (1);
|
exit (1);
|
||||||
|
process_setgroup(p, 0);
|
||||||
|
process_setsig();
|
||||||
exec_reset();
|
exec_reset();
|
||||||
exit(do_subshell(p));
|
exit(do_subshell(p));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 17:20:53 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/29 16:04:18 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)
|
while (redirs)
|
||||||
{
|
{
|
||||||
redir = redirs->content;
|
redir = redirs->content;
|
||||||
DG("redirs content : %p", redirs->content);
|
/* DG("redirs content : %p", redirs->content); */
|
||||||
// DG("redir.type [%li]", redir->type);
|
DG("redir @ %p", redir);
|
||||||
|
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)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:48:10 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);
|
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() errno=%i{eoc}\n", SHELL_NAME, errno);
|
||||||
|
perror("");
|
||||||
|
}
|
||||||
if (pid == 0 && JOB_IS_FG(j->attrs))
|
if (pid == 0 && JOB_IS_FG(j->attrs))
|
||||||
{
|
{
|
||||||
DG("tcsetpgrp[%i]", j->pgid);
|
DG("tcsetpgrp[%i]", j->pgid);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/08 00:02:58 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->type = old->type;
|
||||||
new->n = old->n;
|
new->n = old->n;
|
||||||
new->word = ft_strdup(old->word);
|
new->word = ft_strdup(old->word);
|
||||||
|
new->heredoc_data = ft_strdup(old->heredoc_data);
|
||||||
return (new);
|
return (new);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ int redirect_dless(t_redir *redir)
|
||||||
|
|
||||||
pipe(fds);
|
pipe(fds);
|
||||||
str = redir->heredoc_data;
|
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));
|
write(fds[PIPE_WRITE], str, ft_strlen(str));
|
||||||
close(fds[PIPE_WRITE]);
|
close(fds[PIPE_WRITE]);
|
||||||
dup2(fds[PIPE_READ], 0);
|
dup2(fds[PIPE_READ], 0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/05 14:54:45 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/14 11:27:03 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/17 11:37:47 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;
|
t_list_history *prev;
|
||||||
|
|
||||||
free(head->prev);
|
if (!head)
|
||||||
|
return ;
|
||||||
while (head)
|
while (head)
|
||||||
{
|
{
|
||||||
ft_strdel(&head->str);
|
ft_strdel(&head->str);
|
||||||
prev = head;
|
prev = head;
|
||||||
head = head->next;
|
head = head->next;
|
||||||
free(prev);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 11:49:05 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 14:58:36 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)
|
if (kill(-j->pgid, SIGCONT) < 0)
|
||||||
DG("kill(SIGCONT) failed");
|
DG("kill(SIGCONT) failed");
|
||||||
}
|
}
|
||||||
|
/* if (SH_IS_INTERACTIVE(data_singleton()->opts)) */
|
||||||
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_IS_INTERACTIVE(data_singleton()->opts))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 14:19:48 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)
|
int readline(int fd, int prompt, char **input)
|
||||||
{
|
{
|
||||||
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||||
{
|
return (get_next_line(fd, input) == 0);
|
||||||
if (get_next_line(fd, input) == 0)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
readline_init(prompt);
|
readline_init(prompt);
|
||||||
*input = ft_read_stdin();
|
*input = ft_read_stdin();
|
||||||
if (STR)
|
if (STR)
|
||||||
ft_current_str(STR, POS);
|
ft_current_str(STR, POS);
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
if (!prompt)
|
if (!prompt)
|
||||||
*input = ft_history_parsing();
|
*input = ft_history_parsing();
|
||||||
|
|
|
||||||
|
|
@ -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/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) ||
|
if ((ret = readline(fd, get_lexer_stack(lexer) ||
|
||||||
parser.state == UNDEFINED || lexer.state == HEREDOC, &str)))
|
parser.state == UNDEFINED || lexer.state == HEREDOC, &str)))
|
||||||
{
|
{
|
||||||
|
DG("readline trap");
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (parser.state == UNDEFINED ? error_eof(&token,
|
return (parser.state == UNDEFINED ? error_eof(&token,
|
||||||
&parser, &ast) : 1);
|
&parser, &ast) : 1);
|
||||||
}
|
}
|
||||||
|
DG("INPUT STRING IS [%s]", str);
|
||||||
if (lexer.state == HEREDOC)
|
if (lexer.state == HEREDOC)
|
||||||
{
|
{
|
||||||
ft_strappend(&lexer.str, (char[]){'\n', 0});
|
ft_strappend(&lexer.str, (char[]){'\n', 0});
|
||||||
|
|
@ -70,12 +72,12 @@ int handle_instruction(int fd)
|
||||||
return (error_syntax(&token, &parser, &ast));
|
return (error_syntax(&token, &parser, &ast));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ft_show_heredoc_data(&ast);
|
|
||||||
btree_print(STDBUG, ast, &ft_putast);
|
btree_print(STDBUG, ast, &ft_putast);
|
||||||
if (ft_exec(&ast))
|
if (ft_exec(&ast))
|
||||||
return (1);
|
return (1);
|
||||||
instruction_free(&token, &parser, &ast);
|
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);
|
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);
|
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)
|
||||||
{
|
|
||||||
// lexer_clean;
|
|
||||||
// parser_clean;
|
|
||||||
;
|
;
|
||||||
}
|
DG("gonna exit");
|
||||||
builtin_exit(NULL, NULL, NULL);
|
builtin_exit(NULL, NULL, NULL);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/13 14:58:13 by ariard ### ########.fr */
|
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 20:15:35 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
|
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/13 14:58:27 by ariard ### ########.fr */
|
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 15:32:10 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;
|
t_redir *redir;
|
||||||
|
|
||||||
if (*ast)
|
if (node->type != CMD)
|
||||||
if ((*ast)->left)
|
return (1);
|
||||||
{
|
redir = (node->data.cmd.redir)->content;
|
||||||
node = ((*ast)->left)->item;
|
if (redir->type != TK_DLESS)
|
||||||
redir = (node->data.cmd.redir)->content;
|
return (1);
|
||||||
if (redir->type == TK_DLESS)
|
DG("heredoc_data=[%s] @ %p", redir->heredoc_data, redir->heredoc_data);
|
||||||
DG("Show me heredoc data from node :%s", redir->heredoc_data);
|
DG("redir @ %p", redir);
|
||||||
}
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue