This commit is contained in:
Antoine Riard 2017-03-03 20:12:57 +01:00
commit b4fdc05f64
75 changed files with 568 additions and 496 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:20:32 by ariard ### ########.fr # # Updated: 2017/03/03 20:06:37 by ariard ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -14,7 +14,7 @@ NAME = 42sh
CC = gcc CC = gcc
FLAGS = -Wall -Wextra -Werror FLAGS = -Wall -Wextra -Werror
D_FLAGS = -g D_FLAGS = -g
DELTA = $$(echo "$$(tput cols)-47"|bc) DELTA = $$(echo "$$(tput cols)-47"|bc)
@ -72,10 +72,8 @@ exec/exec_else.c\
exec/exec_for.c\ exec/exec_for.c\
exec/exec_func.c\ exec/exec_func.c\
exec/exec_if.c\ exec/exec_if.c\
exec/exec_less.c\
exec/exec_or_if.c\ exec/exec_or_if.c\
exec/exec_pipe.c\ exec/exec_pipe.c\
exec/exec_redir.c\
exec/exec_semi.c\ exec/exec_semi.c\
exec/exec_until.c\ exec/exec_until.c\
exec/exec_var.c\ exec/exec_var.c\
@ -84,9 +82,9 @@ 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_resetfds.c\
exec/process_setexec.c\ exec/process_setexec.c\
exec/process_setgroup.c\ exec/process_setgroup.c\
exec/process_setsig.c\ exec/process_setsig.c\
@ -138,11 +136,11 @@ history/history_parsing_toolz.c\
history/history_parsing_toolz_2.c\ history/history_parsing_toolz_2.c\
history/list_toolz.c\ history/list_toolz.c\
history/surch_in_history.c\ history/surch_in_history.c\
job-control/add_new_job.c\
job-control/builtin_bg.c\ job-control/builtin_bg.c\
job-control/builtin_fg.c\ job-control/builtin_fg.c\
job-control/builtin_jobs.c\ job-control/builtin_jobs.c\
job-control/do_job_notification.c\ job-control/do_job_notification.c\
job-control/job_addprocess.c\
job-control/job_cmp_id.c\ job-control/job_cmp_id.c\
job-control/job_format.c\ job-control/job_format.c\
job-control/job_format_head.c\ job-control/job_format_head.c\
@ -163,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\

View file

@ -0,0 +1 @@
echo 'je suis un test'

View file

@ -0,0 +1 @@
ls

View file

@ -0,0 +1 @@
pwd

View file

View file

14
42sh/TESTSHELL/stdin_ref Normal file
View file

@ -0,0 +1,14 @@
42sh
Makefile
TESTSHELL
donovan_segaults_06-02
file1
file2
includes
libft
objs
pdf
sample
src
test_framework.sh
update_makefile.sh

43
42sh/TESTSHELL/stdin_test Normal file
View file

@ -0,0 +1,43 @@
 main.c 107start of shell JOBC is ON
 token_print.c 21 token print
 token_print.c 25 token : TK_WORD data [ls]

 insert_newline.c 19 insert newline
 ft_parse.c 45 

 build_tree.c 83 func TK : 'TK_WORD' TK : 'TK_WORD'
 add_cmd.c 55 add data
 ft_parse.c 45 

 build_tree.c 83 func TK : 'TK_NEWLINE' TK : 'TK_NEWLINE'
 add_sep.c 21 add sep
 ft_parse.c 45 

 ft_parse.c 58 sucessful parsing
 main.c 64 Before execution:
NEW
+----+
CMD
 ft_exec.c 39 
 ft_exec.c 48 match : TK_NEWLINE and TK_NEWLINE
 exec_semi.c 20 
 exec_semi.c 22 
 ft_exec.c 39 
 ft_exec.c 48 match : NON-DEFINED and NON-DEFINED
 exec_command.c 52 op=2118139328
42sh
Makefile
TESTSHELL
donovan_segaults_06-02
file1
file2
includes
libft
objs
pdf
sample
src
test_framework.sh
update_makefile.sh
 exec_semi.c 24 
 ft_exec.c 39 

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 18:39:32 by ariard ### ########.fr */ /* Updated: 2017/03/03 20:07:01 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,19 +21,31 @@
# define PROCESS_SCRIPT (1 << 2) # define PROCESS_SCRIPT (1 << 2)
# define PROCESS_SUBSHELL (1 << 3) # define PROCESS_SUBSHELL (1 << 3)
# define PROCESS_UNKNOWN (1 << 4) # define PROCESS_UNKNOWN (1 << 4)
# define PROCESS_PIPESTART (1 << 5) # define PROCESS_COMPLETED (1 << 5)
# define PROCESS_PIPEEND (1 << 6) # define PROCESS_SUSPENDED (1 << 6)
# define PROCESS_COMPLETED (1 << 7) # define PROCESS_RUNNING (1 << 7)
# define PROCESS_SUSPENDED (1 << 8) # define PROCESS_CONTINUED (1 << 8)
# define PROCESS_RUNNING (1 << 9)
# define PROCESS_CONTINUED (1 << 10)
# define PROCESS_TYPE_MASK (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4) # define PROCESS_TYPE_MASK (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4)
# define PROCESS_STATE_MASK (1 << 7 | 1 << 8 | 1 << 9 | 1 << 10) # define PROCESS_STATE_MASK (1 << 5 | 1 << 6 | 1 << 7 | 1 << 8)
# define IS_PIPESTART(a) (a & PROCESS_PIPESTART) # define IS_PIPESTART(p) ((p).fdin == STDIN)
# define IS_PIPEEND(a) (a & PROCESS_PIPEEND) # define IS_PIPEEND(p) ((p).fdout == STDOUT)
# define IS_PIPESINGLE(a) ((a & PROCESS_PIPESTART) && (a & PROCESS_PIPEEND)) # define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
# define EXEC_BG (1 << 1)
# define EXEC_AND_IF (1 << 2)
# define EXEC_OR_IF (1 << 3)
# define EXEC_IF_BRANCH (1 << 4)
# define EXEC_CASE_BRANCH (1 << 5)
# define EXEC_IS_BG(j) (j & EXEC_BG)
# define EXEC_IS_FG(j) (!EXEC_IS_BG(j))
# define EXEC_IS_AND_IF(j) (j & EXEC_AND_IF)
# define EXEC_IS_OR_IF(j) (j & EXEC_JOB_OR_IF)
# define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF)
# define EXEC_IS_IF_BRANCH(j) (j & EXEC_IF_BRANCH)
# define EXEC_IS_CASE_BRANCH(j) (j & EXEC_CASE_BRANCH)
# include "libft.h" # include "libft.h"
# include "types.h" # include "types.h"
@ -47,24 +59,23 @@ struct s_process
pid_t pid; pid_t pid;
int fdin; int fdin;
int fdout; int fdout;
int to_close;
t_list *redirs; t_list *redirs;
int toclose;
int status; int status;
t_flag attributes; t_flag attributes;
t_condition if_branch;
t_condition case_branch;
char *case_pattern;
}; };
struct s_exec struct s_exec
{ {
char *aol_status; /* char *aol_status; */
int aol_search; /* int aol_search; */
t_job job; t_job job;
t_process process; /* t_process process; */
int fd0save; int fd_save[3];
int fd1save; t_flag attrs;
int fd2save; int fdin;
t_list *op_stack;
char *case_pattern;
}; };
struct s_execmap struct s_execmap
@ -93,10 +104,10 @@ int exec_ampersand(t_btree **ast);
int exec_or_if(t_btree **ast); int exec_or_if(t_btree **ast);
int exec_and_if(t_btree **ast); int exec_and_if(t_btree **ast);
int exec_pipe(t_btree **ast); int exec_pipe(t_btree **ast);
int exec_redir(t_btree **ast); /* int exec_redir(t_btree **ast); */
int exec_command(t_btree **ast); int exec_cmd(t_btree **ast);
int exec_while(t_btree **ast); int exec_while(t_btree **ast);
int exec_if(t_btree **ast); int exec_if(t_btree **ast);
int exec_elif(t_btree **ast); int exec_elif(t_btree **ast);
int exec_else(t_btree **ast); int exec_else(t_btree **ast);
@ -108,7 +119,7 @@ int exec_case(t_btree **ast);
int exec_case_branch(t_btree **ast); int exec_case_branch(t_btree **ast);
int launch_process(t_process *p); int launch_process(t_process *p);
int process_setexec(t_type type, t_process *p); int process_setexec(t_process *p);
int process_setgroup(t_process *p, pid_t pid); int process_setgroup(t_process *p, pid_t pid);
void process_setsig(void); void process_setsig(void);
void process_free(void *content, size_t content_size); void process_free(void *content, size_t content_size);
@ -132,6 +143,8 @@ 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); void redir_free(void *data, size_t content_size);
char **token_to_argv(t_astnode *node); char **token_to_argv(t_ld *ld);
int add_new_job(t_job *job);
#endif #endif

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/02/03 14:43:34 by ariard ### ########.fr */ /* Updated: 2017/03/03 18:35:49 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,15 +22,15 @@
# define JOB_NOTIFIED (1 << 0) # define JOB_NOTIFIED (1 << 0)
# define JOB_BG (1 << 1) # define JOB_BG (1 << 1)
# define JOB_IS_BG(j) (j & JOB_BG) # define JOB_IS_BG(j) (j & JOB_BG)
# define JOB_IS_FG(j) !(j & JOB_BG) # define JOB_IS_FG(j) (!JOB_IS_BG(j))
#define JOBS_OPTS_L (1 << 0) # define JOBS_OPTS_L (1 << 0)
struct s_job struct s_job
{ {
int id; int id;
pid_t pgid; pid_t pgid;
t_flag attributes; t_flag attrs;
t_list *first_process; t_list *first_process;
struct termios tmodes; struct termios tmodes;
}; };
@ -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

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/02/24 21:46:08 by ariard ### ########.fr */ /* Updated: 2017/03/03 17:58:18 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,6 +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
{ {
PAREN,
DEFAULT, DEFAULT,
NEWLINE, NEWLINE,
DELIM, DELIM,
@ -39,11 +40,8 @@ enum e_lexstate
BQUOTE, BQUOTE,
DQUOTE_BQUOTE, DQUOTE_BQUOTE,
BACKSLASH, BACKSLASH,
PAREN,
CURLY_BRACKETS, CURLY_BRACKETS,
ASSIGNEMENT_WORD, ASSIGNEMENT_WORD,
// VAR,
// SPECIAL,
COMMENT, COMMENT,
END, END,
}; };

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/02/21 18:51:18 by jhalford ### ########.fr */ /* Updated: 2017/03/02 17:15:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,6 +1,5 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */ /* ::: :::::::: */
/* ::: :::::::: */
/* parser.h :+: :+: :+: */ /* parser.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
@ -141,11 +140,6 @@ int isvar(t_btree **ast, t_list **list);
int join_ast(t_btree **ast, t_btree **new_node); int join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast); int gen_node(t_btree **ast);
/*
* Build AST
*
*/
union u_word union u_word
{ {
char *word; char *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 14:33:49 by ariard ### ########.fr */ /* Updated: 2017/03/03 20:07:30 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

@ -1 +1 @@
Subproject commit 8f6e64fa9b4ac1dd3e3d5200fb93471ddfeedd40 Subproject commit 318efc7cfb7b7cc9d3714fa19fd2be7382b6adec

1
42sh/sample/ls Normal file
View file

@ -0,0 +1 @@
ls

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */ /* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */
/* Updated: 2017/02/17 15:56:55 by gwojda ### ########.fr */ /* Updated: 2017/03/03 16:07:30 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
/* Updated: 2017/02/20 20:30:54 by ariard ### ########.fr */ /* Updated: 2017/03/02 21:00:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,7 +36,9 @@ t_execf *is_builtin(t_process *p)
i = -1; i = -1;
while (g_builtin[++i].name) while (g_builtin[++i].name)
{
if (ft_strcmp(g_builtin[i].name, p->av[0]) == 0) if (ft_strcmp(g_builtin[i].name, p->av[0]) == 0)
return (g_builtin[i].f); return (g_builtin[i].f);
}
return (NULL); return (NULL);
} }

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/02/05 22:10:08 by ariard ### ########.fr */ /* Updated: 2017/03/03 19:35:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,12 +14,21 @@
int exec_ampersand(t_btree **ast) int exec_ampersand(t_btree **ast)
{ {
if (SH_HAS_JOBC(data_singleton()->opts)) t_exec *exec;
data_singleton()->exec.job.attributes |= JOB_BG;
if (!SH_HAS_JOBC(data_singleton()->opts))
return (exec_semi(ast));
exec = &data_singleton()->exec;
push(&exec->op_stack, TK_AMP);
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
if (SH_HAS_JOBC(data_singleton()->opts)) exec->attrs &= ~EXEC_BG;
data_singleton()->exec.job.attributes &= ~JOB_BG;
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
/* if (SH_HAS_JOBC(data_singleton()->opts)) */
/* data_singleton()->exec.job.attributes |= JOB_BG; */
/* ft_exec(&(*ast)->left); */
/* if (SH_HAS_JOBC(data_singleton()->opts)) */
/* data_singleton()->exec.job.attributes &= ~JOB_BG; */
/* ft_exec(&(*ast)->right); */
// btree_delone(ast, &ast_free); // btree_delone(ast, &ast_free);
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:28 by jhalford #+# #+# */ /* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */
/* Updated: 2017/02/05 22:10:38 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:05:42 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,24 +14,31 @@
int exec_and_if(t_btree **ast) int exec_and_if(t_btree **ast)
{ {
t_data *data; /* t_data *data; */
t_exec *exec;
data = data_singleton(); exec = &data_singleton()->exec;
if (data->exec.aol_status == NULL push(&exec->op_stack, TK_AND_IF);
|| (data->exec.aol_search == TK_AND_IF ft_exec(&(*ast)->left);
&& *data->exec.aol_status == '0') exec->attrs |= EXEC_AND_IF;
|| (data->exec.aol_search == TK_OR_IF ft_exec(&(*ast)->right);
&& *data->exec.aol_status != '0'))
{ /* data = data_singleton(); */
ft_exec(&(*ast)->left); /* if (data->exec.aol_status == NULL */
data->exec.aol_status = ft_getenv(data->env, "?"); /* || (data->exec.aol_search == TK_AND_IF */
} /* && *data->exec.aol_status == '0') */
data->exec.aol_search = TK_AND_IF; /* || (data->exec.aol_search == TK_OR_IF */
if (*data->exec.aol_status == '0' /* && *data->exec.aol_status != '0')) */
|| ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) /* { */
ft_exec(&(*ast)->right); /* ft_exec(&(*ast)->left); */
data->exec.aol_status = NULL; /* data->exec.aol_status = ft_getenv(data->env, "?"); */
data->exec.aol_search = 0; /* } */
/* data->exec.aol_search = TK_AND_IF; */
/* if (*data->exec.aol_status == '0' */
/* || ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) */
/* ft_exec(&(*ast)->right); */
/* data->exec.aol_status = NULL; */
/* data->exec.aol_search = 0; */
// btree_delone(ast, &ast_free); // btree_delone(ast, &ast_free);
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/06 18:07:31 by ariard #+# #+# */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
/* Updated: 2017/03/01 16:29:20 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:29:52 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,11 +15,16 @@
int exec_case(t_btree **ast) int exec_case(t_btree **ast)
{ {
t_astnode *node; t_astnode *node;
char **av; /* char **av; */
t_exec *exec;
exec = &data_singleton()->exec;
/* data_singleton()->exec.process.case_branch = 0; */
exec->attrs |= EXEC_CASE_BRANCH;
data_singleton()->exec.process.case_branch = 0;
node = (*ast)->item; node = (*ast)->item;
av = token_to_argv(node); /* av = token_to_argv(node); */
data_singleton()->exec.process.case_pattern = av[0]; /* data_singleton()->exec.process.case_pattern = av[0]; */
/* exec->case_pattern = av[0]; */
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/06 18:07:31 by ariard #+# #+# */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
/* Updated: 2017/02/20 22:31:46 by jhalford ### ########.fr */ /* Updated: 2017/03/03 16:28:15 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,16 +15,19 @@
int exec_case_branch(t_btree **ast) int exec_case_branch(t_btree **ast)
{ {
t_astnode *node; t_astnode *node;
char **av; /* char **av; */
t_exec *exec;
if (data_singleton()->exec.process.case_branch == 1) exec = &data_singleton()->exec;
/* if (data_singleton()->exec.process.case_branch == 1) */
if (EXEC_IS_CASE_BRANCH(exec->attrs))
return (0); return (0);
node = (*ast)->item; node = (*ast)->item;
av = token_to_argv(node); /* av = token_to_argv(node); */
if (ft_strcmp(av[0], data_singleton()->exec.process.case_pattern) == 1) /* if (ft_strcmp(av[0], data_singleton()->exec.process.case_pattern) == 1) */
{ /* { */
data_singleton()->exec.process.case_branch = 1; /* data_singleton()->exec.process.case_branch = 1; */
ft_exec(&(*ast)->right); /* ft_exec(&(*ast)->right); */
} /* } */
return (0); return (0);
} }

View file

@ -6,67 +6,82 @@
/* 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/01 16:32:26 by ariard ### ########.fr */ /* Updated: 2017/03/03 19:46:11 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "exec.h" #include "exec.h"
char **token_to_argv(t_astnode *node) char **token_to_argv(t_ld *ld)
{ {
char **my_tab; char **my_tab;
int index; int index;
char **expand; char **expand;
char **content; char **content;
t_ld *ld;
if (node->type == TK_WORD || node->type == TK_ASSIGNEMENT_WORD) my_tab = NULL;
while (ld)
{ {
ld = NULL; content = ld->content;
// ld = node->data.cmd.token; if ((expand = glob(content[0], (unsigned char *)content[1], (unsigned char *)content[2])))
my_tab = NULL;
while (ld)
{ {
content = ld->content; index = -1;
if ((expand = glob(content[0], (unsigned char *)content[1], (unsigned char *)content[2]))) while (expand[++index])
{ my_tab = ft_sstradd(my_tab, expand[index]);
index = -1; ft_tabdel(&expand);
while (expand[++index])
my_tab = ft_sstradd(my_tab, expand[index]);
ft_tabdel(&expand);
}
ld = ld->next;
} }
return (my_tab); ld = ld->next;
} }
else if (node->type == TK_SUBSHELL) return (my_tab);
return (ft_sstrdup(node->data.sstr));
return (NULL);
} }
int exec_command(t_btree **ast) int exec_cmd(t_btree **ast)
{ {
t_astnode *node; t_cmd *cmd;
t_process *p;
t_job *job; t_job *job;
t_exec *exec;
t_process p;
int fds[2];
int op;
node = (*ast)->item; cmd = &((t_astnode *)(*ast)->item)->data.cmd;
p = &data_singleton()->exec.process; exec = &data_singleton()->exec;
job = &data_singleton()->exec.job; job = &data_singleton()->exec.job;
p->av = token_to_argv(node); process_reset(&p);
process_setexec(node->type, p); op = pop(&exec->op_stack);
if (!(launch_process(p))) 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];
p.redirs = cmd->redir;
exec->fdin = fds[PIPE_READ];
if (IS_PIPESTART(p))
{ {
job_addprocess(p); job->first_process = NULL;
if (IS_PIPEEND(p->attributes)) job->attrs = EXEC_IS_FG(exec->attrs) ? 0 : JOB_BG;
}
if (!(p.av = token_to_argv(cmd->token)))
return (1);
process_setexec(&p);
if (!(launch_process(&p)))
ft_lstadd(&job->first_process, ft_lstnew(&p, sizeof(p)));
if (fds[PIPE_WRITE] != STDOUT)
close(fds[PIPE_WRITE]);
if (IS_PIPEEND(p))
{
add_new_job(job);
if (JOB_IS_FG(job->attrs))
put_job_in_foreground(job, 0);
else
{ {
JOB_IS_FG(job->attributes) ? job_notify_new(job);
put_job_in_foreground(job, 0): put_job_in_background(job, 0);
put_job_in_background(job, 0);
job->pgid = 0;
} }
} }
process_reset(p);
// btree_delone(ast, &ast_free);
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/06 18:08:53 by ariard #+# #+# */ /* Created: 2017/02/06 18:08:53 by ariard #+# #+# */
/* Updated: 2017/02/20 22:35:47 by jhalford ### ########.fr */ /* Updated: 2017/03/03 16:14:25 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,12 +14,18 @@
int exec_elif(t_btree **ast) int exec_elif(t_btree **ast)
{ {
if (data_singleton()->exec.process.if_branch == 1) t_exec *exec;
exec = &data_singleton()->exec;
/* if (data_singleton()->exec.process.if_branch == 1) */
if (EXEC_IS_IF_BRANCH(exec->attrs))
return (0); return (0);
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
if (data_singleton()->exec.process.status == 1) if (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))
/* if (data_singleton()->exec.process.status == 1) */
{ {
data_singleton()->exec.process.if_branch = 1; /* data_singleton()->exec.process.if_branch = 1; */
exec->attrs |= EXEC_IF_BRANCH;
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
} }
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/06 18:55:07 by ariard #+# #+# */ /* Created: 2017/02/06 18:55:07 by ariard #+# #+# */
/* Updated: 2017/02/06 19:13:05 by ariard ### ########.fr */ /* Updated: 2017/03/03 15:56:25 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,9 +14,14 @@
int exec_else(t_btree **ast) int exec_else(t_btree **ast)
{ {
if (data_singleton()->exec.process.if_branch == 0) t_exec *exec;
exec = &data_singleton()->exec;
if (EXEC_IS_IF_BRANCH(exec->attrs))
/* if (data_singleton()->exec.process.if_branch == 0) */
{ {
data_singleton()->exec.process.if_branch = 1; exec->attrs |= EXEC_IF_BRANCH;
/* data_singleton()->exec.process.if_branch = 1; */
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
} }
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/06 20:42:20 by ariard #+# #+# */ /* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
/* Updated: 2017/02/06 20:42:21 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:26:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
/* Updated: 2017/02/20 22:31:46 by jhalford ### ########.fr */ /* Updated: 2017/03/03 16:30:46 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,11 +14,18 @@
int exec_if(t_btree **ast) int exec_if(t_btree **ast)
{ {
data_singleton()->exec.process.if_branch = 0; t_exec *exec;
exec = &data_singleton()->exec;
/* data_singleton()->exec.process.if_branch = 0; */
exec->attrs &= ~EXEC_IF_BRANCH;
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
if (data_singleton()->exec.process.status == 1) /* if (data_singleton()->exec.process.status == 1) */
if (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)
{ {
data_singleton()->exec.process.if_branch = 1; /* data_singleton()->exec.process.if_branch = 1; */
exec->attrs |= EXEC_IF_BRANCH;
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
} }
return (0); return (0);

View file

@ -1,32 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_less.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:27:08 by jhalford #+# #+# */
/* Updated: 2017/03/01 16:37:28 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
int exec_less(t_btree **ast)
{
t_astnode *node;
int fd;
fd = 0;
node = (*ast)->item;
// fd = open(node->data.redir.word.word, O_RDONLY);
data_singleton()->exec.process.fdin = fd;
/* ft_strappend(&data->exec.process.command, "<"); */
/* ft_strappend(&data->exec.process.command, node->data.redir.word.word); */
ft_exec(&(*ast)->left);
data_singleton()->exec.process.fdin = STDIN;
/* data->exec.process.command = NULL; */
// btree_delone(ast, &ast_free);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */ /* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */
/* Updated: 2017/02/05 22:12:08 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:07:35 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,24 +14,31 @@
int exec_or_if(t_btree **ast) int exec_or_if(t_btree **ast)
{ {
t_data *data; /* t_data *data; */
t_exec *exec;
data = data_singleton(); exec = &data_singleton()->exec;
if (data->exec.aol_status == NULL push(&exec->op_stack, TK_OR_IF);
|| (data->exec.aol_search == TK_AND_IF ft_exec(&(*ast)->left);
&& *data->exec.aol_status == '0') exec->attrs |= EXEC_OR_IF;
|| (data->exec.aol_search == TK_OR_IF ft_exec(&(*ast)->right);
&& *data->exec.aol_status != '0'))
{ /* data = data_singleton(); */
ft_exec(&(*ast)->left); /* if (data->exec.aol_status == NULL */
data->exec.aol_status = ft_getenv(data->env, "?"); /* || (data->exec.aol_search == TK_AND_IF */
} /* && *data->exec.aol_status == '0') */
data->exec.aol_search = TK_OR_IF; /* || (data->exec.aol_search == TK_OR_IF */
if (*data->exec.aol_status != '0' /* && *data->exec.aol_status != '0')) */
|| ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) /* { */
ft_exec(&(*ast)->right); /* ft_exec(&(*ast)->left); */
data->exec.aol_status = NULL; /* data->exec.aol_status = ft_getenv(data->env, "?"); */
data->exec.aol_search = 0; /* } */
/* data->exec.aol_search = TK_OR_IF; */
/* if (*data->exec.aol_status != '0' */
/* || ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) */
/* ft_exec(&(*ast)->right); */
/* data->exec.aol_status = NULL; */
/* data->exec.aol_search = 0; */
// btree_delone(ast, &ast_free); // btree_delone(ast, &ast_free);
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */ /* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */
/* Updated: 2017/02/20 20:32:52 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:27:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,36 +14,12 @@
int exec_pipe(t_btree **ast) int exec_pipe(t_btree **ast)
{ {
int fds[2]; t_exec *exec;
int start;
t_data *data;
t_process *p;
data = data_singleton(); exec = &data_singleton()->exec;
p = &data_singleton()->exec.process; push(&exec->op_stack, TK_PIPE);
pipe(fds);
/* DG("pipe %i->%i", fds[PIPE_WRITE], fds[PIPE_READ]); */
p->fdout = fds[PIPE_WRITE];
start = IS_PIPESTART(p->attributes);
p->toclose = fds[PIPE_READ];
p->attributes &= ~PROCESS_PIPEEND;
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
p->attributes &= ~PROCESS_PIPESTART;
p->toclose = STDIN;
close(fds[PIPE_WRITE]);
p->fdout = STDOUT;
p->fdin = fds[PIPE_READ];
p->attributes |= PROCESS_PIPEEND;
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
if (start) /* btree_delone(ast, &ast_free); */
p->attributes |= PROCESS_PIPESTART;
close(fds[PIPE_READ]);
p->fdin = STDIN;
btree_delone(ast, &ast_free);
return (0); return (0);
} }

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_redir.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */
/* Updated: 2017/03/01 16:38:01 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
int exec_redir(t_btree **ast)
{
t_astnode *node;
t_process *p;
p = &data_singleton()->exec.process;
node = (*ast)->item;
// node->data.redir.type = node->type;
// ft_lsteadd(&p->redirs, ft_lstnew(&node->data.redir,sizeof(node->data.redir)));
ft_exec(&(*ast)->left);
// btree_delone(ast, &ast_free);
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/02/06 18:34:38 by ariard ### ########.fr */ /* Updated: 2017/03/03 18:10:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,9 +14,13 @@
int exec_semi(t_btree **ast) int exec_semi(t_btree **ast)
{ {
ft_exec(&(*ast)->left); t_exec *exec;
ft_exec(&(*ast)->right);
exec = &data_singleton()->exec;
push(&exec->op_stack, TK_SEMI);
ft_exec(&(*ast)->left);
exec->attrs &= ~EXEC_AOL_MASK;
ft_exec(&(*ast)->right);
// btree_delone(ast, &ast_free); // btree_delone(ast, &ast_free);
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/06 20:42:20 by ariard #+# #+# */ /* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
/* Updated: 2017/02/06 20:42:21 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:30:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,7 @@
int exec_until(t_btree **ast) int exec_until(t_btree **ast)
{ {
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
while (data_singleton()->exec.process.status == 0) while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)
{ {
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */ /* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
/* Updated: 2017/02/06 22:05:35 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:28:41 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@ int exec_var(t_btree **ast)
char **av; char **av;
node = (*ast)->item; node = (*ast)->item;
av = token_to_argv(node); /* av = token_to_argv(node); */
builtin_setenv("setenv", av, data_singleton()->local_var); builtin_setenv("setenv", av, data_singleton()->local_var);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */ /* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
/* Updated: 2017/02/06 22:05:35 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:05:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,7 @@
int exec_while(t_btree **ast) int exec_while(t_btree **ast)
{ {
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
while (data_singleton()->exec.process.status == 1) while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))
{ {
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);

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/02/21 18:50:05 by ariard ### ########.fr */ /* Updated: 2017/03/03 19:03:46 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,24 +15,18 @@
t_execmap g_execmap[] = t_execmap g_execmap[] =
{ {
{TK_NEWLINE, &exec_semi}, {TK_NEWLINE, &exec_semi},
{TK_AND_IF, &exec_and_if},
{TK_OR_IF, &exec_or_if},
{TK_SEMI, &exec_semi}, {TK_SEMI, &exec_semi},
{TK_AMP, &exec_ampersand}, {TK_AMP, &exec_ampersand},
{TK_AND_IF, &exec_and_if},
{TK_OR_IF, &exec_or_if},
{TK_PIPE, &exec_pipe}, {TK_PIPE, &exec_pipe},
{TK_LESS, &exec_redir},
{TK_GREAT, &exec_redir},
{TK_DLESS, &exec_redir},
{TK_DGREAT, &exec_redir},
{TK_LESSAND, &exec_redir},
{TK_GREATAND, &exec_redir},
{TK_WHILE, &exec_while}, {TK_WHILE, &exec_while},
{TK_IF, &exec_if}, {TK_IF, &exec_if},
{TK_ELIF, &exec_elif}, {TK_ELIF, &exec_elif},
{TK_ELSE, &exec_else}, {TK_ELSE, &exec_else},
{TK_UNTIL, &exec_until}, {TK_UNTIL, &exec_until},
{TK_SUBSHELL, &exec_command}, /* {TK_SUBSHELL, &exec_}, */
{TK_WORD, &exec_command}, {CMD, &exec_cmd},
{0, 0}, {0, 0},
}; };
@ -51,8 +45,7 @@ int ft_exec(t_btree **ast)
{ {
DG("match : %s and %s", DG("match : %s and %s",
read_state(item->type), read_state(g_execmap[i].type)); read_state(item->type), read_state(g_execmap[i].type));
/* return ((*g_execmap[i].f)(ast)); */ return ((*g_execmap[i].f)(ast));
(*g_execmap[i].f)(ast);
} }
i++; i++;
} }

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/02/21 20:09:54 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:53:26 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,16 +18,15 @@ int launch_process(t_process *p)
int pid; int pid;
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
if (p->attributes & PROCESS_UNKNOWN) DG("gonna launch [%s]", p->av[0]);
{ DG("fdin=[%i]", p->fdin);
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]); DG("fdout=[%i]", p->fdout);
set_exitstatus(127, 1); if (p->attributes & PROCESS_BUILTIN && IS_PIPESINGLE(*p))
}
else if (p->attributes & PROCESS_BUILTIN && IS_PIPESINGLE(p->attributes))
{ {
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
{ {
@ -43,6 +42,12 @@ int launch_process(t_process *p)
pid = fork(); pid = fork();
if (pid == 0) if (pid == 0)
{ {
if (p->attributes & PROCESS_UNKNOWN)
{
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]);
exit(127);
/* set_exitstatus(127, 1); */
}
process_setgroup(p, 0); process_setgroup(p, 0);
process_setsig(); process_setsig();
if (process_redirect(p)) if (process_redirect(p))

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/02/07 17:36:46 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:49:27 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -48,12 +48,11 @@ int process_redirect(t_process *p)
} }
redirs = redirs->next; redirs = redirs->next;
} }
if (p->toclose != STDIN) if (p->to_close != STDIN)
close(p->toclose); close(p->to_close);
if (p->fdin != STDIN) if (p->fdin != STDIN)
dup2_close(p->fdin, STDIN); dup2_close(p->fdin, STDIN);
if (p->fdout != STDOUT) if (p->fdout != STDOUT)
dup2_close(p->fdout, STDOUT); dup2_close(p->fdout, STDOUT);
ft_lstdel(&p->redirs, ft_lst_cfree);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/07 17:44:22 by jhalford #+# #+# */ /* Created: 2017/02/07 17:44:22 by jhalford #+# #+# */
/* Updated: 2017/02/07 17:48:22 by jhalford ### ########.fr */ /* Updated: 2017/03/03 16:36:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,9 +14,14 @@
void process_reset(t_process *p) void process_reset(t_process *p)
{ {
process_resetfds();
p->av = NULL; p->av = NULL;
p->path = NULL;
p->execf = NULL;
p->pid = 0; p->pid = 0;
/* p->fdin = STDIN; */
/* p->fdout = STDOUT; */
p->to_close = 0;
p->redirs = NULL; p->redirs = NULL;
p->attributes &= ~(PROCESS_STATE_MASK | PROCESS_TYPE_MASK); p->status = -1;
p->attributes = 0;
} }

View file

@ -6,25 +6,17 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
/* Updated: 2017/02/20 20:42:02 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:32:15 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int process_setexec(t_type type, t_process *p) int process_setexec(t_process *p)
{ {
p->path = NULL; p->path = NULL;
if (type == TK_SUBSHELL) if ((p->execf = is_builtin(p)))
{
p->execf = &execve;
p->attributes |= PROCESS_SUBSHELL;
p->path = ft_strdup(p->av[0]);
}
else if ((p->execf = is_builtin(p)))
{
p->attributes |= PROCESS_BUILTIN; p->attributes |= PROCESS_BUILTIN;
}
else if (ft_strchr(p->av[0], '/')) else if (ft_strchr(p->av[0], '/'))
{ {
p->execf = &execve; p->execf = &execve;

View file

@ -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/01/11 14:45:36 by jhalford ### ########.fr */ /* Updated: 2017/03/03 16:34:02 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,7 +26,7 @@ int process_setgroup(t_process *p, pid_t pid)
if (!j->pgid) if (!j->pgid)
j->pgid = pid ? pid : getpid(); j->pgid = pid ? pid : getpid();
setpgid(pid, j->pgid); setpgid(pid, j->pgid);
if (pid == 0 && JOB_IS_FG(j->attributes)) if (pid == 0 && JOB_IS_FG(j->attrs))
tcsetpgrp(STDIN, j->pgid); tcsetpgrp(STDIN, j->pgid);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */ /* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
/* Updated: 2017/02/24 22:04:43 by ariard ### ########.fr */ /* Updated: 2017/03/03 16:45:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,33 +15,34 @@
char *command_getoutput(char *command) char *command_getoutput(char *command)
{ {
int fds[2]; return (command);
t_btree *ast; /* int fds[2]; */
t_astnode item; /* t_btree *ast; */
char *output; /* t_astnode item; */
char buf[BUF_SIZE + 1]; /* char *output; */
int ret; /* char buf[BUF_SIZE + 1]; */
t_exec *exec; /* int ret; */
/* t_exec *exec; */
output = NULL; /* output = NULL; */
exec = &data_singleton()->exec; /* exec = &data_singleton()->exec; */
item.type = TK_SUBSHELL; /* item.type = TK_SUBSHELL; */
item.data.sstr = malloc(4 * sizeof(char *)); /* item.data.sstr = malloc(4 * sizeof(char *)); */
item.data.sstr[0] = ft_strdup(data_singleton()->argv[0]); /* item.data.sstr[0] = ft_strdup(data_singleton()->argv[0]); */
item.data.sstr[1] = ft_strdup("-c"); /* item.data.sstr[1] = ft_strdup("-c"); */
item.data.sstr[2] = ft_strdup(command); /* item.data.sstr[2] = ft_strdup(command); */
item.data.sstr[3] = NULL; /* item.data.sstr[3] = NULL; */
ast = btree_create_node(&item, sizeof(item)); /* ast = btree_create_node(&item, sizeof(item)); */
pipe(fds); /* pipe(fds); */
exec->process.fdout = fds[PIPE_WRITE]; /* exec->process.fdout = fds[PIPE_WRITE]; */
exec_command(&ast); /* exec_command(&ast); */
exec->process.fdout = STDOUT; /* exec->process.fdout = STDOUT; */
close(fds[PIPE_WRITE]); /* close(fds[PIPE_WRITE]); */
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE))) /* while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE))) */
{ /* { */
buf[ret] = 0; /* buf[ret] = 0; */
ft_strappend(&output, buf); /* ft_strappend(&output, buf); */
} /* } */
close(fds[PIPE_READ]); /* close(fds[PIPE_READ]); */
return (output); /* return (output); */
} }

View file

@ -1,23 +1,28 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* process_resetfds.c :+: :+: :+: */ /* add_new_job.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/07 17:39:14 by jhalford #+# #+# */ /* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */
/* Updated: 2017/02/07 17:50:52 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:33:29 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "job_control.h"
void process_resetfds(void) int add_new_job(t_job *job)
{ {
t_exec *exec; t_jobc *jobc;
exec = &data_singleton()->exec; DG("adding new job");
dup2(exec->fd0save, 0); if (!job->first_process)
dup2(exec->fd1save, 1); return (1);
dup2(exec->fd2save, 2); jobc = &data_singleton()->jobc;
job_update_id();
job->id = jobc->current_id;
job->pgid = ((t_process*)job->first_process->content)->pid;
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
/* Updated: 2017/02/03 15:47:44 by jhalford ### ########.fr */ /* Updated: 2017/03/03 16:46:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,14 +27,14 @@ int do_job_notification(void)
{ {
j = jlist->content; j = jlist->content;
if (job_is_completed(j->id) if (job_is_completed(j->id)
|| (job_is_stopped(j->id) && !(j->attributes & JOB_NOTIFIED))) || (job_is_stopped(j->id) && !(j->attrs & JOB_NOTIFIED)))
{ {
ret = 1; ret = 1;
job_notify_change(j->id); job_notify_change(j->id);
if (job_is_completed(j->id)) if (job_is_completed(j->id))
job_remove(j->id); job_remove(j->id);
else else
j->attributes |= JOB_NOTIFIED; j->attrs |= JOB_NOTIFIED;
} }
jlist = jlist->next; jlist = jlist->next;
} }

View file

@ -1,37 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* job_addprocess.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
/* Updated: 2017/01/31 15:07:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "job_control.h"
int job_addprocess(t_process *p)
{
t_jobc *jobc;
t_job *job;
jobc = &data_singleton()->jobc;
job = &data_singleton()->exec.job;
if (IS_PIPESTART(p->attributes))
{
job_update_id();
job->id = jobc->current_id;
job->pgid = p->pid;
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
}
job = jobc->first_job->content;
if (p->pid > 0)
{
ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
}
if (JOB_IS_BG(job->attributes) && IS_PIPEEND(p->attributes))
job_notify_new(job);
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/01/10 13:22:11 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);
while (!process_mark_status(pid, status)
&& !job_is_completed(id)
&& !job_is_stopped(id))
{
pid = waitpid(WAIT_ANY, &status, WUNTRACED); pid = waitpid(WAIT_ANY, &status, WUNTRACED);
} while (!mark_process_status(pid, status)
&& !job_is_stopped(id)
&& !job_is_completed(id));
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */ /* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */
/* Updated: 2017/01/31 15:08:11 by jhalford ### ########.fr */ /* Updated: 2017/03/03 16:47:28 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,5 +28,5 @@ void mark_job_as_running(t_job *j)
} }
plist = plist->next; plist = plist->next;
} }
j->attributes &= ~JOB_NOTIFIED; j->attrs &= ~JOB_NOTIFIED;
} }

View file

@ -6,7 +6,7 @@
/* 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 13:59:25 by jhalford ### ########.fr */ /* Updated: 2017/03/02 17:48:50 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */ /* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */
/* Updated: 2017/02/20 21:52:28 by jhalford ### ########.fr */ /* Updated: 2017/03/02 20:57:36 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

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/01/31 15:10:45 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:46:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,21 +17,27 @@ int put_job_in_foreground(t_job *j, int cont)
t_jobc *jobc; t_jobc *jobc;
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
tcsetpgrp(STDIN, j->pgid); if (SH_HAS_JOBC(data_singleton()->opts))
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
if (cont)
{ {
tcsetattr(STDIN, TCSADRAIN, &j->tmodes); tcsetpgrp(STDIN, j->pgid);
if (kill(-j->pgid, SIGCONT) < 0) if (cont)
DG("kill(SIGCONT) failed"); {
tcsetattr(STDIN, TCSADRAIN, &j->tmodes);
if (kill(-j->pgid, SIGCONT) < 0)
DG("kill(SIGCONT) failed");
}
job_wait(j->id);
job_remove(j->id);
tcsetpgrp(STDIN, jobc->shell_pgid);
tcgetattr(STDIN, &j->tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
}
else
{
job_wait(j->id);
job_remove(j->id);
} }
job_wait(j->id);
job_remove(j->id);
tcsetpgrp(STDIN, jobc->shell_pgid);
tcgetattr(STDIN, &j->tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
return (0); return (0);
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_lexer_stack.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 17:39:45 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:40:24 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int get_lexer_stack(t_lexer lexer) int get_lexer_stack(t_lexer lexer)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ /* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
/* Updated: 2017/03/03 15:06:07 by wescande ### ########.fr */ /* Updated: 2017/03/03 17:56:09 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -35,9 +35,7 @@ t_lexstate get_state_global(t_lexer *lexer)
return (PAREN); return (PAREN);
else if (c == '{' || c == '}') else if (c == '{' || c == '}')
return (CURLY_BRACKETS); return (CURLY_BRACKETS);
/* else if (c == '=') else if (c == 0)
return (ASSIGNEMENT_WORD);
*/ else if (c == 0)
return (END); return (END);
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/24 20:28:13 by ariard #+# #+# */ /* Created: 2017/02/24 20:28:13 by ariard #+# #+# */
/* Updated: 2017/02/24 21:00:13 by ariard ### ########.fr */ /* Updated: 2017/03/02 19:11:25 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */ /* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */
/* Updated: 2017/02/17 15:36:49 by jhalford ### ########.fr */ /* Updated: 2017/03/03 17:45:53 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,7 +32,7 @@ int lexer_bquote(t_list **alst, t_lexer *lexer)
push(&lexer->stack, lexer->state); push(&lexer->stack, lexer->state);
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
} }
top_state = *(int*)pop(&lexer->stack)->content; top_state = pop(&lexer->stack);
lexer->state = top_state == DQUOTE_BQUOTE ? DQUOTE : DEFAULT; lexer->state = top_state == DQUOTE_BQUOTE ? DQUOTE : DEFAULT;
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */ /* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */
/* Updated: 2017/03/01 23:40:16 by ariard ### ########.fr */ /* Updated: 2017/03/03 17:55:57 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
/* Updated: 2017/02/24 21:38:42 by ariard ### ########.fr */ /* Updated: 2017/03/03 17:55:55 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,6 +14,7 @@
int (*g_lexer[])(t_list **alst, t_lexer *lexer) = int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
{ {
&lexer_paren,
&lexer_default, &lexer_default,
&lexer_newline, &lexer_newline,
&lexer_delim, &lexer_delim,
@ -30,7 +31,6 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
&lexer_bquote, &lexer_bquote,
&lexer_bquote, &lexer_bquote,
&lexer_backslash, &lexer_backslash,
&lexer_paren,
&lexer_curly_brackets, &lexer_curly_brackets,
&lexer_assignement_word, &lexer_assignement_word,
&lexer_comment, &lexer_comment,

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 23:19:46 by ariard #+# #+# */ /* Created: 2017/01/23 23:19:46 by ariard #+# #+# */
/* Updated: 2017/02/09 19:55:04 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:00:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */ /* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */
/* Updated: 2017/03/01 23:39:37 by ariard ### ########.fr */ /* Updated: 2017/03/03 17:35:30 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_paren.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 17:37:15 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:48:28 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_paren(t_list **alst, t_lexer *lexer) int lexer_paren(t_list **alst, t_lexer *lexer)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2017/03/03 16:00:13 by wescande ### ########.fr */ /* Updated: 2017/03/03 17:56:07 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -51,27 +51,3 @@ int lexer_word(t_list **alst, t_lexer *lexer)
lexer->pos++; lexer->pos++;
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
} }
/*
int lexer_word(t_list **alst, t_lexer *lexer)
{
t_token *token;
t_lexstate state;
token = (*alst)->content;
token->type = TK_WORD;
if ((state = get_state_global(lexer)))
{
lexer->state = state;
return (lexer_lex(alst, lexer));
}
if ((state = get_state_redir(lexer)))
{
lexer->state = state;
return (lexer_lex(alst, lexer));
}
token_append(token, lexer, 0, 0);
lexer->pos++;
return (lexer_lex(alst, lexer));
}
*/

View file

@ -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/01 17:19:21 by ariard ### ########.fr */ /* Updated: 2017/03/03 18:29:03 by wescande ### ########.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/02/20 20:57:14 by ariard ### ########.fr */ /* Updated: 2017/03/03 19:45:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,25 +22,28 @@ 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.toclose = STDIN; /* data->exec.process.to_close = 0; */
data->exec.process.fdin = STDIN; /* data->exec.process.fdin = STDIN; */
data->exec.process.fdout = STDOUT; /* data->exec.process.fdout = STDOUT; */
data->exec.process.pid = 0; /* data->exec.process.pid = 0; */
data->exec.process.attributes = PROCESS_PIPESTART | PROCESS_PIPEEND; /* data->exec.process.attributes = 0; */
data->exec.process.redirs = NULL; /* data->exec.process.redirs = NULL; */
data->exec.fd0save = fcntl(0, F_DUPFD_CLOEXEC); data->exec.fd_save[0] = fcntl(0, F_DUPFD_CLOEXEC);
data->exec.fd1save = fcntl(1, F_DUPFD_CLOEXEC); data->exec.fd_save[1] = fcntl(1, F_DUPFD_CLOEXEC);
data->exec.fd2save = fcntl(2, F_DUPFD_CLOEXEC); data->exec.fd_save[2] = fcntl(2, F_DUPFD_CLOEXEC);
data->exec.op_stack = NULL;
data->exec.fdin = STDIN;
data->exec.attrs = 0;
data->exec.aol_status = NULL; /* data->exec.aol_status = NULL; */
data->exec.aol_search = 0; /* data->exec.aol_search = 0; */
data->exec.job.id = 0; /* data->exec.job.id = 0; */
data->exec.job.pgid = 0; /* data->exec.job.pgid = 0; */
data->exec.job.attributes = 0; /* data->exec.job.attributes = 0; */
data->exec.job.first_process = 0; /* data->exec.job.first_process = 0; */
data->jobc.first_job = NULL; data->jobc.first_job = NULL;
data->jobc.current_id = 1; data->jobc.current_id = 1;

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 14:56:11 by ariard ### ########.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 19:30:48 by ariard ### ########.fr */ /* Updated: 2017/03/03 20:05:06 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,14 +26,11 @@ int handle_instruction(int fd)
parser_init(&parser); parser_init(&parser);
token = NULL; token = NULL;
ast = NULL; ast = NULL;
/* str = NULL; */
DG("START: state=%i", parser.state);
while (1) while (1)
{ {
if ((ret = readline(fd, get_lexer_stack(lexer) || if ((ret = readline(fd, get_lexer_stack(lexer) ||
parser.state == UNDEFINED, &str))) parser.state == UNDEFINED, &str)))
{ {
ft_putstr("bonjour");
if (ret == -1) if (ret == -1)
return (-1); return (-1);
return (parser.state == UNDEFINED ? error_EOF() : 1); return (parser.state == UNDEFINED ? error_EOF() : 1);
@ -46,7 +43,7 @@ int handle_instruction(int fd)
ltoken = ft_lstlast(token); ltoken = ft_lstlast(token);
if (lexer_lex(token ? &ltoken : &token, &lexer)) if (lexer_lex(token ? &ltoken : &token, &lexer))
return (1); return (1);
if (get_lexer_stack(lexer)) if (get_lexer_stack(lexer) > 1)
continue ; continue ;
lexer.state = DEFAULT; lexer.state = DEFAULT;
token_print(token); token_print(token);
@ -61,13 +58,13 @@ int handle_instruction(int fd)
else if (parser.state == ERROR && !SH_IS_INTERACTIVE(data_singleton()->opts)) else if (parser.state == ERROR && !SH_IS_INTERACTIVE(data_singleton()->opts))
return (error_syntax(&token)); return (error_syntax(&token));
else if (parser.state == ERROR) else if (parser.state == ERROR)
error_syntax(&token); error_syntax(&token);
token = NULL; token = NULL;
} }
DG("succesful parsing:"); DG("Before execution:");
btree_print(STDBUG, ast, &ft_putast); btree_print(STDBUG, ast, &ft_putast);
/* if (ft_exec(&ast)) */ if (ft_exec(&ast))
/* return (1); */ return (1);
btree_del(&ast, &ast_free); btree_del(&ast, &ast_free);
ft_add_str_in_history(lexer.str); ft_add_str_in_history(lexer.str);
return (0); return (0);
@ -86,6 +83,7 @@ int get_input_fd()
return (fd); return (fd);
else if (data->opts & SH_OPTS_LC) else if (data->opts & SH_OPTS_LC)
{ {
DG();
pipe(fds); pipe(fds);
fd = fds[PIPE_READ]; fd = fds[PIPE_READ];
file = shell_get_avdata(); file = shell_get_avdata();
@ -95,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);
} }
@ -106,9 +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", if ((fd = get_input_fd()) < 0)
SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF"); {
fd = get_input_fd(); ft_printf("{red}%s: %s: No such file or directory\n{eoc}", SHELL_NAME, shell_get_avdata());
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 17:14:52 by jhalford #+# #+# */ /* Created: 2017/01/11 17:14:52 by jhalford #+# #+# */
/* Updated: 2017/01/19 20:56:05 by ariard ### ########.fr */ /* Updated: 2017/03/03 17:33:33 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,7 +21,7 @@ char *shell_get_avdata()
data = data_singleton(); data = data_singleton();
av = data->argv; av = data->argv;
i = 1; i = 1;
while (av[i][0] == '-') while (av[i] && 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: 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/02/21 20:14:44 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 19:43:22 by ariard ### ########.fr */ /* Updated: 2017/03/03 20:04:08 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -50,16 +50,19 @@ int add_cmd(t_btree **ast, t_list **lst)
&& node->type != TK_PAREN_CLOSE && node->type != CMD && node->type != TK_PAREN_CLOSE && node->type != CMD
&& node->type != REDIR) && node->type != REDIR)
return (add_cmd(&(*ast)->right, lst)); return (add_cmd(&(*ast)->right, lst));
my_tab = NULL;
node = (*ast)->item; node = (*ast)->item;
node->type = CMD; node->type = CMD;
if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD) if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD)
{ {
DG("add data"); DG("add data");
my_tab = ft_sstradd(my_tab, token->data); if ((my_tab = (char **)malloc(sizeof(char *) * 4)))
my_tab = ft_sstradd(my_tab, (char *)token->esc); {
my_tab = ft_sstradd(my_tab, (char *)token->esc2); my_tab[0] = ft_strdup(token->data);
ft_ld_pushback(&node->data.cmd.token, my_tab); my_tab[1] = (char *)dup_char_esc(token->esc, token->size >> 3);
my_tab[2] = (char *)dup_char_esc(token->esc2, token->size >> 3);
my_tab[3] = NULL;
}
ft_ld_pushback(&node->data.cmd.token, my_tab);
} }
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/09 15:32:10 by ariard #+# #+# */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
/* Updated: 2017/03/03 18:44:44 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)

41
42sh/test_framework.sh Executable file
View file

@ -0,0 +1,41 @@
SHELL=$1
TOTAL_TEST=0
NBR_TEST_SUCCESS=0
unset LIST_TEST
LIST_TEST='./TESTSHELL/*'/'*'.test
DIR_TEST=./TESTSHELL
do_test() {
for TEST in $LIST_TEST
do
($SHELL < $TEST 1> ${DIR_TEST}/stdin_test 2> ${DIR_TEST}/stderr_test)
(bash < $TEST 1> ${DIR_TEST}/stdin_ref 2> ${DIR_TEST}/stderr_ref)
if ! diff ${DIR_TEST}/stdin_test ${DIR_TEST}/stdin_ref > /dev/null ||
! diff ${DIR_TEST}/stderr_test ${DIR_TEST}/stderr_test > /dev/null
then
echo "\033[0;31mFAILURE $TEST" >> ${DIR_TEST}/resultat
else
((NBR_TEST_SUCCESS++))
fi
((TOTAL_TEST++))
done
}
do_test
if [ -e ${DIR_TEST}/resultat ]
then
cat ${DIR_TEST}/resultat
fi
echo "\033[0;32mYou succeed $NBR_TEST_SUCCESS tests on $TOTAL_TEST"
rm -f $DIR_TEST/resultat
#add random input sed -n $RANDOM "p" /usr/share/dict/words
#add timeout
#charging phase of test
#real verification of references
#to add extranous comportement