Merge branch 'pda' of github.com:jzck/42sh into pda

This commit is contained in:
wescande 2017-03-03 20:14:01 +01:00
commit ec945bb5a5
42 changed files with 220 additions and 141 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ # # By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# # # Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/03 18:05:32 by jhalford ### ########.fr # # Updated: 2017/03/03 20:06:37 by ariard ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -59,6 +59,7 @@ completion/c_sizing.c\
completion/c_terminal.c\ completion/c_terminal.c\
completion/completion.c\ completion/completion.c\
exec/ast_free.c\ exec/ast_free.c\
exec/redir_free.c\
exec/bad_fd.c\ exec/bad_fd.c\
exec/exec_ampersand.c\ exec/exec_ampersand.c\
exec/exec_and_if.c\ exec/exec_and_if.c\
@ -81,6 +82,7 @@ exec/fd_is_valid.c\
exec/ft_exec.c\ exec/ft_exec.c\
exec/ft_findexec.c\ exec/ft_findexec.c\
exec/launch_process.c\ exec/launch_process.c\
exec/mark_process_status.c\
exec/process_redirect.c\ exec/process_redirect.c\
exec/process_reset.c\ exec/process_reset.c\
exec/process_setexec.c\ exec/process_setexec.c\
@ -159,7 +161,6 @@ job-control/mark_job_as_running.c\
job-control/process_cmp_pid.c\ job-control/process_cmp_pid.c\
job-control/process_format.c\ job-control/process_format.c\
job-control/process_free.c\ job-control/process_free.c\
job-control/process_mark_status.c\
job-control/put_job_in_background.c\ job-control/put_job_in_background.c\
job-control/put_job_in_foreground.c\ job-control/put_job_in_foreground.c\
job-control/sigchld_handler.c\ job-control/sigchld_handler.c\
@ -234,6 +235,7 @@ parser/add_loop.c\
parser/add_redir.c\ parser/add_redir.c\
parser/add_sep.c\ parser/add_sep.c\
parser/add_subshell.c\ parser/add_subshell.c\
parser/add_var.c\
parser/aggregate_sym.c\ parser/aggregate_sym.c\
parser/build_tree.c\ parser/build_tree.c\
parser/error_syntax.c\ parser/error_syntax.c\

View file

View file

@ -1,14 +0,0 @@
total 576
-rwxr-xr-x 1 ariard 2016_paris 690 Feb 21 15:30 update_makefile.sh
drwxr-xr-x 13 ariard 2016_paris 442 Feb 21 15:30 src
drwxr-xr-x 28 ariard 2016_paris 952 Feb 25 18:21 sample
drwxr-xr-x 6 ariard 2016_paris 204 Feb 21 15:30 pdf
drwxr-xr-x 13 ariard 2016_paris 442 Mar 2 20:15 objs
drwxr-xr-x 12 ariard 2016_paris 408 Mar 2 20:15 libft
drwxr-xr-x 19 ariard 2016_paris 646 Mar 2 20:36 includes
-rw-r--r-- 1 ariard 2016_paris 0 Mar 2 20:40 file2
-rw-r--r-- 1 ariard 2016_paris 0 Mar 2 20:40 file1
-rw-r--r-- 1 ariard 2016_paris 4396 Feb 21 15:40 donovan_segaults_06-02
-rw-r--r-- 1 ariard 2016_paris 21985 Mar 2 20:39 STDBUG
-rw-r--r-- 1 ariard 2016_paris 8051 Mar 1 16:42 Makefile
-rwxr-xr-x 1 ariard 2016_paris 246884 Mar 2 20:38 42sh

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/03 16:39:06 by jhalford ### ########.fr */ /* Updated: 2017/03/03 20:07:01 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -141,6 +141,7 @@ char *ft_findexec(char *path, char *file);
void set_exitstatus(int status, int override); void set_exitstatus(int status, int override);
void ast_free(void *data, size_t content_size); void ast_free(void *data, size_t content_size);
void redir_free(void *data, size_t content_size);
char **token_to_argv(t_ld *ld); char **token_to_argv(t_ld *ld);

View file

@ -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/03 16:38:51 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:35:49 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -58,7 +58,7 @@ void job_format_head(t_job *j);
void job_update_status(void); void job_update_status(void);
void mark_job_as_running (t_job *j); void mark_job_as_running (t_job *j);
int process_mark_status(pid_t pid, int status); int mark_process_status(pid_t pid, int status);
int job_is_stopped(int id); int job_is_stopped(int id);
int job_is_completed(int id); int job_is_completed(int id);

View file

@ -5,7 +5,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */ /* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
/* Updated: 2017/03/02 17:10:21 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:18:14 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -124,22 +124,21 @@ int add_func_cmd(t_btree **ast, t_list **lst);
int add_func_sep(t_btree **ast, t_list **lst); int add_func_sep(t_btree **ast, t_list **lst);
int add_one_func(t_btree **ast, t_list **lst); int add_one_func(t_btree **ast, t_list **lst);
int add_pipe(t_btree **ast, t_list **lst); int add_pipe(t_btree **ast, t_list **lst);
int add_var(t_btree **ast, t_list **lst);
int isloop(t_btree **ast, t_list **lst); int isloop(t_btree **ast, t_list **lst);
int iscase(t_btree **ast, t_list **lst); int iscase(t_btree **ast, t_list **lst);
int iscondition(t_btree **ast, t_list **lst); int iscondition(t_btree **ast, t_list **lst);
int issubshell(t_btree **ast, t_list **lst); int issubshell(t_btree **ast, t_list **lst);
int isfunc(t_btree **ast, t_list **lst); int isfunc(t_btree **ast, t_list **lst);
int join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast);
int isdir(t_btree **ast); int isdir(t_btree **ast);
int iscondition(t_btree **ast, t_list **list); int iscondition(t_btree **ast, t_list **list);
int isdir_sep(t_btree **ast, t_list **list); int isdir_sep(t_btree **ast, t_list **list);
int isdir_word(t_btree **ast, t_list **list); int isdir_word(t_btree **ast, t_list **list);
int isvar(t_btree **ast, t_list **list);
/* int join_ast(t_btree **ast, t_btree **new_node);
* Build AST int gen_node(t_btree **ast);
*
*/
union u_word union u_word
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:30:47 by jhalford ### ########.fr */ /* Updated: 2017/03/03 20:07:30 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

1
42sh/sample/ls Normal file
View file

@ -0,0 +1 @@
ls

1
42sh/src/addls Normal file
View file

@ -0,0 +1 @@

View file

@ -6,34 +6,32 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
/* Updated: 2017/03/02 21:40:54 by ariard ### ########.fr */ /* Updated: 2017/03/03 19:59:33 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "exec.h" #include "exec.h"
void read_redir(void *data)
{
t_redir *redir;
redir = data;
DG("file : [%s]", redir->word.word);
}
void ast_free(void *data, size_t content_size) void ast_free(void *data, size_t content_size)
{ {
t_astnode *node; t_astnode *node;
(void)node;
(void)data;
(void)content_size;
return ;
/*
(void)content_size; (void)content_size;
node = data; node = data;
if (node->type == TK_COMMAND) if (node->type == CMD)
{
ft_ld_clear(&node->data.cmd.token, &ft_tabdel); ft_ld_clear(&node->data.cmd.token, &ft_tabdel);
else if (node->type == TK_SUBSHELL) ft_lstdel(&node->data.cmd.redir, &redir_free);
{
ft_sstrfree(node->data.sstr);
node->data.sstr = NULL;
} }
else if (node->type == TK_LESS || node->type == TK_GREAT || node->type == TK_DGREAT) // if (node->type == WORDLIST)
{ // do clear
ft_strdel(&node->data.cmd.redir.word.word);
}
*/
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */ /* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
/* Updated: 2017/03/03 16:05:30 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:35:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,12 +16,13 @@ int exec_ampersand(t_btree **ast)
{ {
t_exec *exec; t_exec *exec;
if (!SH_HAS_JOBC(data_singleton()->opts))
return (exec_semi(ast));
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
push(&exec->op_stack, TK_AMP); push(&exec->op_stack, TK_AMP);
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
exec->attrs &= ~EXEC_BG; exec->attrs &= ~EXEC_BG;
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
/* if (SH_HAS_JOBC(data_singleton()->opts)) */ /* if (SH_HAS_JOBC(data_singleton()->opts)) */
/* data_singleton()->exec.job.attributes |= JOB_BG; */ /* data_singleton()->exec.job.attributes |= JOB_BG; */
/* ft_exec(&(*ast)->left); */ /* ft_exec(&(*ast)->left); */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:44:43 by wescande ### ########.fr */ /* Updated: 2017/03/03 19:46:11 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -49,7 +49,6 @@ int exec_cmd(t_btree **ast)
job = &data_singleton()->exec.job; job = &data_singleton()->exec.job;
process_reset(&p); process_reset(&p);
op = pop(&exec->op_stack); op = pop(&exec->op_stack);
DG("op=%i", op);
fds[PIPE_WRITE] = STDOUT; fds[PIPE_WRITE] = STDOUT;
fds[PIPE_READ] = STDIN; fds[PIPE_READ] = STDIN;
if (op == TK_AMP) if (op == TK_AMP)
@ -57,7 +56,9 @@ int exec_cmd(t_btree **ast)
else if (op == TK_PIPE) else if (op == TK_PIPE)
pipe(fds); pipe(fds);
p.fdin = exec->fdin; p.fdin = exec->fdin;
p.to_close = fds[PIPE_READ];
p.fdout = fds[PIPE_WRITE]; p.fdout = fds[PIPE_WRITE];
p.redirs = cmd->redir;
exec->fdin = fds[PIPE_READ]; exec->fdin = fds[PIPE_READ];
if (IS_PIPESTART(p)) if (IS_PIPESTART(p))
{ {
@ -69,7 +70,18 @@ int exec_cmd(t_btree **ast)
process_setexec(&p); process_setexec(&p);
if (!(launch_process(&p))) if (!(launch_process(&p)))
ft_lstadd(&job->first_process, ft_lstnew(&p, sizeof(p))); ft_lstadd(&job->first_process, ft_lstnew(&p, sizeof(p)));
if (fds[PIPE_WRITE] != STDOUT)
close(fds[PIPE_WRITE]);
if (IS_PIPEEND(p)) if (IS_PIPEEND(p))
{
add_new_job(job); add_new_job(job);
if (JOB_IS_FG(job->attrs))
put_job_in_foreground(job, 0);
else
{
job_notify_new(job);
put_job_in_background(job, 0);
}
}
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */ /* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:01:38 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:10:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,11 +17,8 @@ int exec_semi(t_btree **ast)
t_exec *exec; t_exec *exec;
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
DG();
push(&exec->op_stack, TK_SEMI); push(&exec->op_stack, TK_SEMI);
DG();
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
DG();
exec->attrs &= ~EXEC_AOL_MASK; exec->attrs &= ~EXEC_AOL_MASK;
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
// btree_delone(ast, &ast_free); // btree_delone(ast, &ast_free);

View file

@ -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/03 18:02:55 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:03:46 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,7 @@ t_execmap g_execmap[] =
{TK_AMP, &exec_ampersand}, {TK_AMP, &exec_ampersand},
{TK_AND_IF, &exec_and_if}, {TK_AND_IF, &exec_and_if},
{TK_OR_IF, &exec_or_if}, {TK_OR_IF, &exec_or_if},
/* {TK_PIPE, &exec_pipe}, */ {TK_PIPE, &exec_pipe},
{TK_WHILE, &exec_while}, {TK_WHILE, &exec_while},
{TK_IF, &exec_if}, {TK_IF, &exec_if},
{TK_ELIF, &exec_elif}, {TK_ELIF, &exec_elif},
@ -36,7 +36,6 @@ int ft_exec(t_btree **ast)
int i; int i;
i = 0; i = 0;
DG();
if (!*ast) if (!*ast)
return (0); return (0);
item = (*ast)->item; item = (*ast)->item;

View file

@ -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/03 16:29:12 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:53:26 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,11 +18,15 @@ int launch_process(t_process *p)
int pid; int pid;
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
DG("gonna launch [%s]", p->av[0]);
DG("fdin=[%i]", p->fdin);
DG("fdout=[%i]", p->fdout);
if (p->attributes & PROCESS_BUILTIN && IS_PIPESINGLE(*p)) if (p->attributes & PROCESS_BUILTIN && IS_PIPESINGLE(*p))
{ {
if (process_redirect(p)) if (process_redirect(p))
return (1); return (1);
set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env), 1); set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env), 1);
return (0);
} }
else else
{ {

View file

@ -6,19 +6,20 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/02/03 15:50:29 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:02:54 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "job_control.h" #include "job_control.h"
int process_mark_status(pid_t pid, int status) int mark_process_status(pid_t pid, int status)
{ {
t_list *plist; t_list *plist;
t_process *p; t_process *p;
if (pid > 1) if (pid > 1)
{ {
DG("MPS pid=%i,s=%i", pid, status);
if ((plist = job_getprocess(pid))) if ((plist = job_getprocess(pid)))
{ {
p = plist->content; p = plist->content;

View file

@ -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/02 19:44:42 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:49:27 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -48,10 +48,10 @@ int process_redirect(t_process *p)
} }
redirs = redirs->next; redirs = redirs->next;
} }
if (p->to_close != 0) if (p->to_close != STDIN)
close(p->to_close); close(p->to_close);
if (p->fdin != STDIN) if (p->fdin != STDIN)
dup2_close(p->fdout, STDOUT); dup2_close(p->fdin, STDIN);
if (p->fdout != STDOUT) if (p->fdout != STDOUT)
dup2_close(p->fdout, STDOUT); dup2_close(p->fdout, STDOUT);
return (0); return (0);

View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redir_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 18:12:57 by ariard #+# #+# */
/* Updated: 2017/03/03 20:02:24 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
void redir_free(void *data, size_t content_size)
{
t_redir *redir;
(void)content_size;
redir = data;
if (redir->type == TK_GREAT || redir->type == TK_LESS || redir->type == TK_DGREAT)
ft_strdel(&redir->word.word);
else
redir->word.fd = 0;
redir->type = 0;
redir->n = 0;
redir->close = 1;
free(redir);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */ /* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:44:42 by wescande ### ########.fr */ /* Updated: 2017/03/03 19:33:29 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,6 +16,7 @@ int add_new_job(t_job *job)
{ {
t_jobc *jobc; t_jobc *jobc;
DG("adding new job");
if (!job->first_process) if (!job->first_process)
return (1); return (1);
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
@ -23,12 +24,5 @@ int add_new_job(t_job *job)
job->id = jobc->current_id; job->id = jobc->current_id;
job->pgid = ((t_process*)job->first_process->content)->pid; job->pgid = ((t_process*)job->first_process->content)->pid;
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
if (JOB_IS_FG(job->attrs))
put_job_in_foreground(job, 0);
else
{
job_notify_new(job);
put_job_in_background(job, 0);
}
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/31 15:07:30 by jhalford #+# #+# */ /* Created: 2017/01/31 15:07:30 by jhalford #+# #+# */
/* Updated: 2017/01/31 15:07:41 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:42:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
/* Updated: 2017/01/31 13:44:26 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:53:32 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 13:33:08 by jhalford #+# #+# */ /* Created: 2016/12/12 13:33:08 by jhalford #+# #+# */
/* Updated: 2017/03/02 20:59:46 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:18:29 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
/* Updated: 2017/02/03 15:50:30 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:56:57 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ void job_update_status(void)
int status; int status;
pid_t pid; pid_t pid;
pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG); do
while (!process_mark_status(pid, status)) pid = waitpid (WAIT_ANY, &status, WUNTRACED|WNOHANG);
pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG); while (!mark_process_status (pid, status));
} }

View file

@ -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/01/31 13:44:17 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:42:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,15 +17,11 @@ int job_wait(int id)
pid_t pid; pid_t pid;
int status; int status;
if (job_is_stopped(id)) DG("job wait [%i]", id);
return (0); do
job_update_status();
pid = waitpid(WAIT_ANY, &status, WUNTRACED); pid = waitpid(WAIT_ANY, &status, WUNTRACED);
while (!process_mark_status(pid, status) while (!mark_process_status(pid, status)
&& !job_is_completed(id) && !job_is_stopped(id)
&& !job_is_stopped(id)) && !job_is_completed(id));
{
pid = waitpid(WAIT_ANY, &status, WUNTRACED);
}
return (0); return (0);
} }

View file

@ -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/03 18:44:44 by wescande ### ########.fr */ /* Updated: 2017/03/03 19:46:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,8 +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;
if (SH_HAS_JOBC(data_singleton()->opts))
{
tcsetpgrp(STDIN, j->pgid); tcsetpgrp(STDIN, j->pgid);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
if (cont) if (cont)
{ {
tcsetattr(STDIN, TCSADRAIN, &j->tmodes); tcsetattr(STDIN, TCSADRAIN, &j->tmodes);
@ -32,5 +33,11 @@ int put_job_in_foreground(t_job *j, int cont)
tcgetattr(STDIN, &j->tmodes); tcgetattr(STDIN, &j->tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
}
else
{
job_wait(j->id);
job_remove(j->id);
}
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */ /* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */
/* Updated: 2017/02/20 20:55:25 by ariard ### ########.fr */ /* Updated: 2017/03/03 18:57:46 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:39:30 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:45:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,7 @@ int data_init(void)
data = data_singleton(); data = data_singleton();
data->env = ft_sstrdup(environ); data->env = ft_sstrdup(environ);
data->comp = NULL; data->comp = NULL;
data->opts = SH_OPTS_JOBC; data->opts = 0;
/* data->exec.process.path = NULL; */ /* data->exec.process.path = NULL; */
/* data->exec.process.av = NULL; */ /* data->exec.process.av = NULL; */
/* data->exec.process.to_close = 0; */ /* data->exec.process.to_close = 0; */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:32:06 by jhalford ### ########.fr */ /* Updated: 2017/03/03 20:05:54 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -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/03 18:33:40 by wescande ### ########.fr */ /* Updated: 2017/03/03 20:05:06 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -63,14 +63,10 @@ int handle_instruction(int fd)
} }
DG("Before execution:"); DG("Before execution:");
btree_print(STDBUG, ast, &ft_putast); btree_print(STDBUG, ast, &ft_putast);
DG();
if (ft_exec(&ast)) if (ft_exec(&ast))
return (1); return (1);
DG();
btree_del(&ast, &ast_free); btree_del(&ast, &ast_free);
DG();
ft_add_str_in_history(lexer.str); ft_add_str_in_history(lexer.str);
DG();
return (0); return (0);
} }
@ -97,7 +93,11 @@ int get_input_fd()
return (fd); return (fd);
} }
else if ((file = shell_get_avdata())) else if ((file = shell_get_avdata()))
return (open(file, O_RDONLY)); {
if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0)
return (-1);
return (fd);
}
else else
return (STDIN); return (STDIN);
} }
@ -108,13 +108,13 @@ int main(int ac, char **av)
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
shell_init(ac, av); shell_init(ac, av);
DG("{inv}{bol}{gre}start of shell{eoc} JOBC is %s",
SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF");
if ((fd = get_input_fd()) < 0) if ((fd = get_input_fd()) < 0)
{ {
ft_printf("{red}%s: No such file or directory\n{eoc}", SHELL_NAME); ft_printf("{red}%s: %s: No such file or directory\n{eoc}", SHELL_NAME, shell_get_avdata());
return (1); return (1);
} }
DG("{inv}{bol}{gre}start of shell{eoc} 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; // lexer_clean;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */ /* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */
/* Updated: 2017/02/21 15:37:22 by ariard ### ########.fr */ /* Updated: 2017/03/03 19:53:11 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,7 +41,10 @@ void shell_get_opts(int ac, char **av)
i = 1; i = 1;
if (isatty(STDIN) && !av[1]) if (isatty(STDIN) && !av[1])
{
data_singleton()->opts |= SH_INTERACTIVE; data_singleton()->opts |= SH_INTERACTIVE;
data_singleton()->opts |= SH_OPTS_JOBC;
}
while (i < ac && av[i][0] == '-') while (i < ac && av[i][0] == '-')
{ {
if (ft_strcmp(av[i], "--") == 0) if (ft_strcmp(av[i], "--") == 0)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2017/03/02 20:38:23 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:45:52 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/03/03 17:33:28 by jhalford ### ########.fr */ /* Updated: 2017/03/03 20:04:08 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,6 +26,8 @@ int add_cmd(t_btree **ast, t_list **lst)
gen_node(ast); gen_node(ast);
else if (isdir_word(ast, lst)) else if (isdir_word(ast, lst))
return (add_redir_word(ast, lst)); return (add_redir_word(ast, lst));
else if (isvar(ast, lst))
return (add_var(ast, lst));
else if (isloop(ast, lst) == 3) else if (isloop(ast, lst) == 3)
return (add_loop_condition(ast, lst)); return (add_loop_condition(ast, lst));
else if (isloop(ast, lst)) else if (isloop(ast, lst))

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
/* Updated: 2017/03/03 14:27:27 by ariard ### ########.fr */ /* Updated: 2017/03/03 18:01:55 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* 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/03 14:35:14 by ariard ### ########.fr */ /* Updated: 2017/03/03 20:02:22 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -69,7 +69,7 @@ int add_redir_word(t_btree **ast, t_list **lst)
else if (ft_stris((char *)token->data, &ft_isdigit)) else if (ft_stris((char *)token->data, &ft_isdigit))
redir->word.fd = ft_atoi(token->data); redir->word.fd = ft_atoi(token->data);
else else
redir->word.word = token->data; redir->word.word = ft_strdup(token->data);
} }
return (0); return (0);
} }
@ -78,7 +78,7 @@ int add_redir_type(t_btree **ast, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *token; t_token *token;
t_redir *redir; t_redir redir;
DG("add redir"); DG("add redir");
if (!*ast) if (!*ast)
@ -86,8 +86,7 @@ int add_redir_type(t_btree **ast, t_list **lst)
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
node->type = REDIR; node->type = REDIR;
redir = ft_memalloc(sizeof(redir)); redir.type = token->type;
redir->type = token->type; ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(redir, sizeof(redir)));
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */
/* Updated: 2017/03/03 14:27:40 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:05:24 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

45
42sh/src/parser/add_var.c Normal file
View file

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_var.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 15:08:16 by ariard #+# #+# */
/* Updated: 2017/03/03 16:17:27 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int isvar(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
node = NULL;
token = (*lst)->content;
if (*ast)
{
node = (*ast)->item;
if (node->type != TK_ASSIGNEMENT_WORD && token->type == TK_ASSIGNEMENT_WORD)
return (1);
}
return (0);
}
int add_var(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_btree *new_node;
if (!*ast)
return (0);
new_node = NULL;
gen_node(&new_node);
join_ast(ast, &new_node);
node = (new_node)->item;
node->type = TK_SEMI;
add_cmd(&new_node, lst);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */ /* Created: 2017/02/09 17:39:18 by ariard #+# #+# */
/* Updated: 2017/03/03 14:27:46 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:35:04 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,6 +25,7 @@ t_aggrematch g_aggrematch[] =
{TK_PAREN_OPEN, CMD_SUPERIOR, FUNC_NAME, CMD_SUPERIOR}, {TK_PAREN_OPEN, CMD_SUPERIOR, FUNC_NAME, CMD_SUPERIOR},
{TK_ASSIGNEMENT_WORD, CMD_PREFIX,CMD_PREFIX, 0}, {TK_ASSIGNEMENT_WORD, CMD_PREFIX,CMD_PREFIX, 0},
{TK_PIPE, CMD_SUPERIOR, SIMPLE_COMMAND, CMD_SUPERIOR}, {TK_PIPE, CMD_SUPERIOR, SIMPLE_COMMAND, CMD_SUPERIOR},
{TK_PIPE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE},
{TK_FI, ELSE_PART, IF_CLAUSE, TK_IF}, {TK_FI, ELSE_PART, IF_CLAUSE, TK_IF},
{TK_FI, COMPOUND_LIST, IF_CLAUSE, COMPLETE_CONDITION}, {TK_FI, COMPOUND_LIST, IF_CLAUSE, COMPLETE_CONDITION},
{TK_FI, COMPLETE_CONDITION, IF_CLAUSE, COMPLETE_CONDITION}, {TK_FI, COMPLETE_CONDITION, IF_CLAUSE, COMPLETE_CONDITION},
@ -306,20 +307,20 @@ int aggregate_sym(t_sym **stack, t_sym *new_sym, t_parstate *state)
int i; int i;
i = 0; i = 0;
// DG("aggregate head %s && sym %s", DG("aggregate head %s && sym %s",
// read_state(**stack), read_state(*new_sym)); read_state(**stack), read_state(*new_sym));
while (g_aggrematch[i].top) while (g_aggrematch[i].top)
{ {
if (*new_sym == g_aggrematch[i].top if (*new_sym == g_aggrematch[i].top
&& MATCH_STACK(**stack, g_aggrematch[i].under)) && MATCH_STACK(**stack, g_aggrematch[i].under))
{ {
// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); DG("MATCH : %s", read_state(g_aggrematch[i].new_sym));
*new_sym = g_aggrematch[i].new_sym; *new_sym = g_aggrematch[i].new_sym;
if (g_aggrematch[i].erase_sym) if (g_aggrematch[i].erase_sym)
{ {
pop_stack(stack, g_aggrematch[i].erase_sym); pop_stack(stack, g_aggrematch[i].erase_sym);
// DG("stack after pop: %s", read_state(**stack)); DG("stack after pop: %s", read_state(**stack));
} }
if (eval_sym(**stack, *new_sym)) if (eval_sym(**stack, *new_sym))
return ((*state = ERROR)); return ((*state = ERROR));

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/03/03 14:35:40 by ariard ### ########.fr */ /* Updated: 2017/03/03 15:08:55 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -393,6 +393,7 @@ t_stackmatch g_stackmatch[] =
{TK_AMP, TERM}, {TK_AMP, TERM},
{TK_PIPE, PATTERN}, {TK_PIPE, PATTERN},
{TK_PIPE, CMD_SUPERIOR}, {TK_PIPE, CMD_SUPERIOR},
{TK_PIPE, PIPE_SEMI_SEQUENCE},
{PATTERN_CASE, TK_IN}, {PATTERN_CASE, TK_IN},
{PATTERN_CASE, CASE_LIST_NS}, {PATTERN_CASE, CASE_LIST_NS},
{TK_PAREN_OPEN, COMPLETE_COMMANDS}, {TK_PAREN_OPEN, COMPLETE_COMMANDS},
@ -1009,7 +1010,7 @@ int eval_sym(t_sym stack, t_sym new_sym)
{ {
int i; int i;
// DG("eval head %s && sym %s", read_state(stack), read_state(new_sym)); DG("eval head %s && sym %s", read_state(stack), read_state(new_sym));
i = 0; i = 0;
while (g_stackmatch[i].top) while (g_stackmatch[i].top)
{ {

View file

@ -32,8 +32,8 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
while (*token) while (*token)
{ {
produce_sym(*parser->stack, parser->new_sym, token); produce_sym(*parser->stack, parser->new_sym, token);
//DG("new sym %s", read_state(*parser->new_sym)); DG("new sym %s", read_state(*parser->new_sym));
DG("number of token to treat: %d", ft_lstsize(*token));
if (eval_sym(*parser->stack, *parser->new_sym)) if (eval_sym(*parser->stack, *parser->new_sym))
return ((parser->state = ERROR)); return ((parser->state = ERROR));
else else

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
/* Updated: 2017/03/03 14:28:05 by ariard ### ########.fr */ /* Updated: 2017/03/03 18:43:13 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -88,13 +88,11 @@ t_prodmatch g_prodmatch[] =
{TK_NEWLINE, FOR_WORDLIST, NEWLINE_LIST}, {TK_NEWLINE, FOR_WORDLIST, NEWLINE_LIST},
{TK_NEWLINE, SEQUENTIAL_SEP, NEWLINE_LIST}, {TK_NEWLINE, SEQUENTIAL_SEP, NEWLINE_LIST},
{TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP}, {TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP},
{TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP},
{TK_SEMI, TERM, SEPARATOR_OP},
{TK_SEMI, LIST, SEPARATOR_OP}, {TK_SEMI, LIST, SEPARATOR_OP},
{TK_SEMI, PIPE_SEMI_SEQUENCE, SEPARATOR_OP}, {TK_SEMI, PIPE_SEMI_SEQUENCE, SEPARATOR_OP},
{TK_AMP, CMD_SUPERIOR, SEPARATOR_OP}, {TK_AMP, CMD_SUPERIOR, SEPARATOR_OP},
{TK_AMP, TERM, SEPARATOR_OP},
{TK_AMP, LIST, SEPARATOR_OP}, {TK_AMP, LIST, SEPARATOR_OP},
{TK_AMP, PIPE_SEMI_SEQUENCE, SEPARATOR_OP},
{0, 0, 0}, {0, 0, 0},
}; };
@ -105,8 +103,8 @@ int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst)
int i; int i;
token = (*lst)->content; token = (*lst)->content;
// DG("produce stack : %s && token : %s", read_state(stack), DG("produce stack : %s && token : %s", read_state(stack),
// read_state(token->type)); read_state(token->type));
i = 0; i = 0;
*new_sym = 0; *new_sym = 0;
while (g_prodmatch[i].new_sym) while (g_prodmatch[i].new_sym)
@ -114,7 +112,7 @@ int produce_sym(t_sym stack, t_sym *new_sym, t_list **lst)
if (token->type == g_prodmatch[i].token if (token->type == g_prodmatch[i].token
&& stack == g_prodmatch[i].stack) && stack == g_prodmatch[i].stack)
{ {
// DG("MATCH : %s", read_state(g_prodmatch[i].new_sym)); DG("MATCH : %s", read_state(g_prodmatch[i].new_sym));
*new_sym = g_prodmatch[i].new_sym; *new_sym = g_prodmatch[i].new_sym;
} }
i++; i++;

View file

@ -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/03 14:28:12 by ariard ### ########.fr */ /* Updated: 2017/03/03 20:03:24 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -194,6 +194,8 @@ char *read_state(t_sym current)
return ("ALL"); return ("ALL");
if (current == NEWLINE_LIST) if (current == NEWLINE_LIST)
return ("NEWLINE_LIST"); return ("NEWLINE_LIST");
if (current == CMD)
return ("CMD");
if (current != 0) if (current != 0)
return ("NON-DEFINED"); return ("NON-DEFINED");
if (current == 0) if (current == 0)