diff --git a/42sh/Makefile b/42sh/Makefile index e608d9a8..e0bfe3a8 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/03 20:06:37 by ariard ### ########.fr # +#* Updated: 2017/03/05 15:36:45 by wescande ### ########.fr *# # # # **************************************************************************** # @@ -95,6 +95,7 @@ exec/redirect_greatand.c\ exec/redirect_less.c\ exec/redirect_lessand.c\ exec/set_exitstatus.c\ +exec/set_process.c\ glob/command_getoutput.c\ glob/dir_glob.c\ glob/esc_print.c\ @@ -137,11 +138,11 @@ history/history_parsing_toolz.c\ history/history_parsing_toolz_2.c\ history/list_toolz.c\ history/surch_in_history.c\ -job-control/add_new_job.c\ job-control/builtin_bg.c\ job-control/builtin_fg.c\ job-control/builtin_jobs.c\ job-control/do_job_notification.c\ +job-control/job_addprocess.c\ job-control/job_cmp_id.c\ job-control/job_format.c\ job-control/job_format_head.c\ @@ -178,7 +179,7 @@ lexer/lexer_assignement_word.c\ lexer/lexer_backslash.c\ lexer/lexer_bquote.c\ lexer/lexer_comment.c\ -lexer/lexer_curly_brackets.c\ +lexer/lexer_curly_braces.c\ lexer/lexer_default.c\ lexer/lexer_delim.c\ lexer/lexer_dless.c\ @@ -223,12 +224,12 @@ main/data_exit.c\ main/data_init.c\ main/data_singleton.c\ main/ft_putast.c\ +main/instruction_free.c\ main/main.c\ main/shell_exit.c\ main/shell_get_avdata.c\ main/shell_get_opts.c\ main/shell_init.c\ -main/instruction_free.c\ parser/add_case.c\ parser/add_cmd.c\ parser/add_condition.c\ @@ -259,13 +260,13 @@ all : @make -j $(NAME) $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) - @$(CC) $(FLAGS) $(D_FLAGS) \ + @$(CC) $(OBJS) -o $(NAME) \ -I $(INC_DIR) \ -I $(LIBFT_INC) \ $(LIBS) \ - $(LIBFT_LIB) $(OBJS) \ - -o $(NAME) - @printf "\r\e[48;5;15;38;5;25m✅ MAKE $(NAME)\e[0m\e[K\n" + $(LIBFT_LIB) \ + $(FLAGS) $(D_FLAGS) + @printf "\r\033[48;5;15;38;5;25m✅ MAKE $(NAME)\033[0m\033[K\n" $(LIBFT_LIB): @make -C $(LIBFT_DIR) @@ -279,7 +280,7 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR) @$(eval PERCENT=$(shell echo $$(($(INDEX)*100/$(NB))))) @$(eval COLOR=$(shell echo $$(($(PERCENT)%35+196)))) @$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB))))) - @printf "\r\e[38;5;11m⌛ MAKE %10.10s : %2d%% \e[48;5;%dm%*s\e[0m%*s\e[48;5;255m \e[0m \e[38;5;11m %*s\e[0m\e[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) "$@" + @printf "\r\033[38;5;11m⌛ MAKE %10.10s : %2d%% \033[48;5;%dm%*s\033[0m%*s\033[48;5;255m \033[0m \033[38;5;11m %*s\033[0m\033[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) "$@" @$(CC) $(FLAGS) $(D_FLAGS) -MMD -c $< -o $@\ -I $(INC_DIR)\ -I $(LIBFT_INC) @@ -287,14 +288,14 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR) clean: cleanlib @rm -rf $(OBJ_DIR) - @printf "\r\e[38;5;202m✖ clean $(NAME).\e[0m\e[K\n" + @printf "\r\033[38;5;202m✖ clean $(NAME).\033[0m\033[K\n" cleanlib: @make -C $(LIBFT_DIR) clean fclean: clean fcleanlib @rm -f $(NAME) - @printf "\r\e[38;5;196m❌ fclean $(NAME).\e[0m\e[K\n" + @printf "\r\033[38;5;196m❌ fclean $(NAME).\033[0m\033[K\n" fcleanlib: cleanlib @make -C $(LIBFT_DIR) fclean diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index be67f404..15db9b28 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/03 20:28:08 by wescande ### ########.fr */ +/* Updated: 2017/03/05 15:19:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,7 +41,7 @@ # 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_IS_OR_IF(j) (j & EXEC_OR_IF) # define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF) # define EXEC_IS_IF_BRANCH(j) (j & EXEC_IF_BRANCH) @@ -119,6 +119,7 @@ int exec_case(t_btree **ast); int exec_case_branch(t_btree **ast); int launch_process(t_process *p); +int set_process(t_process *p, t_btree *ast); int process_setexec(t_process *p); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index b8f04fa4..62c32983 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:35:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:28:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 12f76e17..89fa6f55 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/03/03 17:58:18 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:28:17 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,8 @@ | TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE) enum e_lexstate { - PAREN, DEFAULT, + PAREN, NEWLINE, DELIM, SEP, @@ -111,7 +111,7 @@ int lexer_dquote(t_list **alst, t_lexer *lexer); int lexer_bquote(t_list **alst, t_lexer *lexer); int lexer_backslash(t_list **alst, t_lexer *lexer); int lexer_paren(t_list **alst, t_lexer *lexer); -int lexer_curly_brackets(t_list **alst, t_lexer *lexer); +int lexer_curly_braces(t_list **alst, t_lexer *lexer); int lexer_assignement_word(t_list **alst, t_lexer *lexer); int lexer_comment(t_list **alst, t_lexer *lexer); int lexer_end(t_list **alst, t_lexer *lexer); diff --git a/42sh/libft b/42sh/libft index 318efc7c..282df927 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit 318efc7cfb7b7cc9d3714fa19fd2be7382b6adec +Subproject commit 282df927230b2c6da253f8fc9d7ca0eedc0fe30c diff --git a/42sh/src/builtin/bt_read_parse.c b/42sh/src/builtin/bt_read_parse.c index b23672f1..15aaff94 100644 --- a/42sh/src/builtin/bt_read_parse.c +++ b/42sh/src/builtin/bt_read_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/27 18:25:22 by jhalford #+# #+# */ -/* Updated: 2017/01/27 19:40:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:28:10 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,11 +30,9 @@ int bt_read_parse(t_read *data, char **av) { int i; int j; - int k; t_readopt *opt; i = 1; - k = 0; while (av[i]) { j = 0; diff --git a/42sh/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index c4b1a6f8..15b0f5b5 100644 --- a/42sh/src/exec/ast_free.c +++ b/42sh/src/exec/ast_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ -/* Updated: 2017/03/05 16:24:52 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:50:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,5 +33,4 @@ void ast_free(void *data, size_t content_size) } // if (node->type == WORDLIST) // do clear - } diff --git a/42sh/src/exec/exec_and_if.c b/42sh/src/exec/exec_and_if.c index 874f8004..42ee38a7 100644 --- a/42sh/src/exec/exec_and_if.c +++ b/42sh/src/exec/exec_and_if.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */ -/* Updated: 2017/03/03 16:05:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:18:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ int exec_and_if(t_btree **ast) exec = &data_singleton()->exec; push(&exec->op_stack, TK_AND_IF); ft_exec(&(*ast)->left); + exec->attrs &= ~EXEC_OR_IF; exec->attrs |= EXEC_AND_IF; ft_exec(&(*ast)->right); diff --git a/42sh/src/exec/exec_case.c b/42sh/src/exec/exec_case.c index 0a0cebaa..b200ab15 100644 --- a/42sh/src/exec/exec_case.c +++ b/42sh/src/exec/exec_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ -/* Updated: 2017/03/04 18:18:29 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:29:22 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,16 +14,17 @@ int exec_case(t_btree **ast) { - t_astnode *node; +// t_astnode *node; /* char **av; */ t_exec *exec; + (void)ast; return (0); exec = &data_singleton()->exec; /* data_singleton()->exec.process.case_branch = 0; */ exec->attrs |= EXEC_CASE_BRANCH; - node = (*ast)->item; +// node = (*ast)->item; /* av = token_to_argv(node); */ /* data_singleton()->exec.process.case_pattern = av[0]; */ /* exec->case_pattern = av[0]; */ diff --git a/42sh/src/exec/exec_case_branch.c b/42sh/src/exec/exec_case_branch.c index 0cef16d4..32652b44 100644 --- a/42sh/src/exec/exec_case_branch.c +++ b/42sh/src/exec/exec_case_branch.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ -/* Updated: 2017/03/04 18:23:29 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:29:46 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,16 +14,17 @@ int exec_case_branch(t_btree **ast) { - t_astnode *node; +// t_astnode *node; /* char **av; */ t_exec *exec; + (void)ast; return (0); exec = &data_singleton()->exec; /* if (data_singleton()->exec.process.case_branch == 1) */ if (EXEC_IS_CASE_BRANCH(exec->attrs)) return (0); - node = (*ast)->item; +// node = (*ast)->item; /* av = token_to_argv(node); */ /* if (ft_strcmp(av[0], data_singleton()->exec.process.case_pattern) == 1) */ /* { */ diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index f2b1394f..ac516c54 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ -/* Updated: 2017/03/04 17:11:10 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:42:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,51 +37,25 @@ char **token_to_argv(t_ld *ld, int do_match) int exec_cmd(t_btree **ast) { - t_cmd *cmd; - t_job *job; - t_exec *exec; t_process p; - int fds[2]; - int op; + t_job *job; - cmd = &((t_astnode *)(*ast)->item)->data.cmd; - exec = &data_singleton()->exec; job = &data_singleton()->exec.job; - process_reset(&p); - op = pop(&exec->op_stack); - 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->first_process = NULL; - job->attrs = EXEC_IS_FG(exec->attrs) ? 0 : JOB_BG; - } - if (!(p.av = token_to_argv(cmd->token, 1))) + if (set_process(&p, *ast)) 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_addprocess(&p); + if (IS_PIPEEND(p)) { - job_notify_new(job); - put_job_in_background(job, 0); + if (JOB_IS_FG(job->attrs)) + put_job_in_foreground(job, 0); + else + put_job_in_background(job, 0); } + job->pgid = 0; } + if (p.fdout != STDOUT) + close(p.fdout); return (0); } diff --git a/42sh/src/exec/exec_if.c b/42sh/src/exec/exec_if.c index 02f972e6..c1a59aef 100644 --- a/42sh/src/exec/exec_if.c +++ b/42sh/src/exec/exec_if.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ -/* Updated: 2017/03/04 17:37:11 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:12:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_or_if.c b/42sh/src/exec/exec_or_if.c index ec6bc226..5cc45a5e 100644 --- a/42sh/src/exec/exec_or_if.c +++ b/42sh/src/exec/exec_or_if.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */ -/* Updated: 2017/03/03 16:07:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:18:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,8 @@ int exec_or_if(t_btree **ast) exec = &data_singleton()->exec; push(&exec->op_stack, TK_OR_IF); ft_exec(&(*ast)->left); - exec->attrs |= EXEC_OR_IF; + exec->attrs &= ~EXEC_AND_IF; + exec->attrs = EXEC_OR_IF; ft_exec(&(*ast)->right); /* data = data_singleton(); */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 52919e69..6aa02d84 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/03 19:53:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:32:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,55 +14,50 @@ int launch_process(t_process *p) { - t_exec *exec; int pid; - exec = &data_singleton()->exec; - DG("gonna launch [%s]", p->av[0]); - DG("fdin=[%i]", p->fdin); - DG("fdout=[%i]", p->fdout); + /* 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 (process_redirect(p)) return (1); set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env), 1); + return (1); + } + p->attributes &= ~PROCESS_STATE_MASK; + p->attributes |= PROCESS_RUNNING; + if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT) + && access(p->path, X_OK) == -1) + { + ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->av[0]); + set_exitstatus(126, 1); + return (1); + } + pid = fork(); + 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); + } + process_setgroup(p, 0); + process_setsig(); + DG("gonna redirect"); + if (process_redirect(p)) + exit (1); + (*p->execf)(p->path, p->av, data_singleton()->env); + ft_dprintf(2, "{red}%s: internal excve error{eoc}\n", SHELL_NAME); + } + else if (pid > 0) + { + p->pid = pid; + process_setgroup(p, pid); return (0); } - else - { - p->attributes &= ~PROCESS_STATE_MASK; - p->attributes |= PROCESS_RUNNING; - if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT) - && access(p->path, X_OK) == -1) - { - ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->av[0]); - set_exitstatus(126, 1); - return (1); - } - pid = fork(); - 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_setsig(); - if (process_redirect(p)) - exit (1); - (*p->execf)(p->path, p->av, data_singleton()->env); - exit(43); - } - else if (pid > 0) - { - p->pid = pid; - process_setgroup(p, pid); - return (0); - } - else if (pid == -1) - ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); - } + else if (pid == -1) + ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); return (1); } diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index c13cf802..39b807b6 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:49:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:59:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redir_free.c b/42sh/src/exec/redir_free.c index 9e0a1b06..41ed42d2 100644 --- a/42sh/src/exec/redir_free.c +++ b/42sh/src/exec/redir_free.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 18:12:57 by ariard #+# #+# */ -/* Updated: 2017/03/03 20:02:24 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:58:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,11 +19,14 @@ void redir_free(void *data, size_t content_size) (void)content_size; redir = data; if (redir->type == TK_GREAT || redir->type == TK_LESS || redir->type == TK_DGREAT) + { + /* DG("word.word: %s", redir->word.word); */ ft_strdel(&redir->word.word); - else - redir->word.fd = 0; - redir->type = 0; - redir->n = 0; - redir->close = 1; + } + /* else */ + /* redir->word.fd = 0; */ + /* redir->type = 0; */ + /* redir->n = 0; */ + /* redir->close = 1; */ free(redir); } diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c new file mode 100644 index 00000000..88a39993 --- /dev/null +++ b/42sh/src/exec/set_process.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* set_process.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ +/* Updated: 2017/03/05 15:42:45 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "exec.h" + +int set_process(t_process *p, t_btree *ast) +{ + t_exec *exec; + t_cmd *cmd; + int op; + int fds[2]; + + cmd = &((t_astnode *)ast->item)->data.cmd; + process_reset(p); + exec = &data_singleton()->exec; + op = pop(&exec->op_stack); + if ((EXEC_IS_AND_IF(exec->attrs) + && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") != 0) + || (EXEC_IS_OR_IF(exec->attrs) + && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)) + return (1); + if (!(p->av = token_to_argv(cmd->token, 1))) + return (1); + fds[PIPE_WRITE] = STDOUT; + fds[PIPE_READ] = STDIN; + if (op == TK_AMP) + exec->attrs |= JOB_BG; + else if (op == TK_PIPE) + pipe(fds); + p->fdin = exec->fdin; + p->to_close = fds[PIPE_READ]; + p->fdout = fds[PIPE_WRITE]; + exec->fdin = fds[PIPE_READ]; + p->redirs = cmd->redir; + process_setexec(p); + return (0); +} diff --git a/42sh/src/job-control/add_new_job.c b/42sh/src/job-control/job_addprocess.c similarity index 56% rename from 42sh/src/job-control/add_new_job.c rename to 42sh/src/job-control/job_addprocess.c index 3e866fac..8afe2cee 100644 --- a/42sh/src/job-control/add_new_job.c +++ b/42sh/src/job-control/job_addprocess.c @@ -1,28 +1,37 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* add_new_job.c :+: :+: :+: */ +/* job_addprocess.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */ -/* Updated: 2017/03/03 19:33:29 by jhalford ### ########.fr */ +/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ +/* Updated: 2017/03/05 15:12:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "job_control.h" -int add_new_job(t_job *job) +int job_addprocess(t_process *p) { t_jobc *jobc; + t_job *job; - DG("adding new job"); - if (!job->first_process) - return (1); 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))); + job = &data_singleton()->exec.job; + if (IS_PIPESTART(*p)) + { + 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->attrs) && IS_PIPEEND(*p)) + job_notify_new(job); return (0); } diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index eb84a650..ea62d4bf 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/02 17:48:50 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:00:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,6 @@ void process_free(void *content, size_t content_size) p = content; ft_strdel(&p->path); ft_sstrfree(p->av); - ft_lstdel(&p->redirs, ft_lst_cfree); + /* ft_lstdel(&p->redirs, ft_lst_cfree); */ free(p); } diff --git a/42sh/src/job-control/sigchld_handler.c b/42sh/src/job-control/sigchld_handler.c index 87f795c7..4fe9724a 100644 --- a/42sh/src/job-control/sigchld_handler.c +++ b/42sh/src/job-control/sigchld_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */ -/* Updated: 2017/01/31 15:09:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:30:35 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,8 @@ void sigchld_handler(int signo) { - t_data *data; +// t_data *data; (void)signo; - data = data_singleton(); +// data = data_singleton(); } diff --git a/42sh/src/job-control/sigtstp_handler.c b/42sh/src/job-control/sigtstp_handler.c index e6c9b923..5244b9c0 100644 --- a/42sh/src/job-control/sigtstp_handler.c +++ b/42sh/src/job-control/sigtstp_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */ -/* Updated: 2017/01/22 19:03:32 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:30:58 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,10 @@ void sigtstp_handler(int signo) { - t_jobc *jobc; +// t_jobc *jobc; (void)signo; - jobc = &data_singleton()->jobc; +// jobc = &data_singleton()->jobc; DG("got SIGTSTP pid=%i, pgrp=%i, shell_pgid=%i", getpid(), getpgrp(), data_singleton()->jobc.shell_pgid); ft_putchar('\x1A'); } diff --git a/42sh/src/lexer/get_lexer_stack.c b/42sh/src/lexer/get_lexer_stack.c index d8c449ec..a574564c 100644 --- a/42sh/src/lexer/get_lexer_stack.c +++ b/42sh/src/lexer/get_lexer_stack.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 17:39:45 by jhalford #+# #+# */ -/* Updated: 2017/03/03 17:40:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:27:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index 550e7b2c..d6af9653 100644 --- a/42sh/src/lexer/get_state_global.c +++ b/42sh/src/lexer/get_state_global.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ -/* Updated: 2017/03/03 17:56:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:28:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ t_lexstate get_state_global(t_lexer *lexer) char c; c = lexer->str[lexer->pos]; + DG("check, c=%c", lexer->str[lexer->pos]); if (ft_is_delim(c)) return (DELIM); else if (c == '#') diff --git a/42sh/src/lexer/lexer_comment.c b/42sh/src/lexer/lexer_comment.c index 1ae43e79..8a302869 100644 --- a/42sh/src/lexer/lexer_comment.c +++ b/42sh/src/lexer/lexer_comment.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/07 12:15:59 by jhalford #+# #+# */ -/* Updated: 2017/02/20 21:03:53 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:31:17 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,9 @@ int lexer_comment(t_list **alst, t_lexer *lexer) { - t_token *token; +// t_token *token; - token = (*alst)->content; +// token = (*alst)->content; if (lexer->str[lexer->pos] == '\n') return (lexer_lex(&(*alst)->next, lexer)); return (lexer_comment(alst, lexer)); diff --git a/42sh/src/lexer/lexer_curly_brackets.c b/42sh/src/lexer/lexer_curly_braces.c similarity index 52% rename from 42sh/src/lexer/lexer_curly_brackets.c rename to 42sh/src/lexer/lexer_curly_braces.c index e63356d1..1674027a 100644 --- a/42sh/src/lexer/lexer_curly_brackets.c +++ b/42sh/src/lexer/lexer_curly_braces.c @@ -1,46 +1,35 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* lexer_curly_brackets.c :+: :+: :+: */ +/* lexer_curly_braces.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/02/24 21:24:50 by ariard #+# #+# */ -/* Updated: 2017/02/24 21:48:52 by ariard ### ########.fr */ +/* Created: 2017/03/05 16:29:35 by jhalford #+# #+# */ +/* Updated: 2017/03/05 16:29:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "parser.h" -int lexer_curly_brackets(t_list **alst, t_lexer *lexer) +int lexer_curly_braces(t_list **alst, t_lexer *lexer) { - t_token *token; - t_list **lst; + t_token *token; - DG("lexer curly brackets"); - lst = alst; - if (*alst) - { - token = (*alst)->content; - if (token->type) - lst = &(*alst)->next; - } - token = token_init(); - *lst = ft_lstnew(token, sizeof(*token)); - token = (*lst)->content; + token = (*alst)->content; + if (token->type) + lexer_lex(&(*alst)->next, lexer); if (lexer->str[lexer->pos] == '{') { - DG("lbrace"); token->type = TK_LBRACE; - push(&lexer->stack, CURLY_BRACKETS); + push(&lexer->stack, PAREN); } - else if (lexer->stack && *(int*)lexer->stack->content == CURLY_BRACKETS) + else if (get_lexer_stack(*lexer)) { - DG("rbrace"); token->type = TK_RBRACE; pop(&lexer->stack); } lexer->pos++; lexer->state = DEFAULT; - return (lexer_lex(&(*lst)->next, lexer)); + return (lexer_lex(&(*alst)->next, lexer)); } diff --git a/42sh/src/lexer/lexer_default.c b/42sh/src/lexer/lexer_default.c index 94bf796c..0fff3b18 100644 --- a/42sh/src/lexer/lexer_default.c +++ b/42sh/src/lexer/lexer_default.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */ -/* Updated: 2017/03/03 17:55:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:20:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index cb734fb5..d0b9f604 100644 --- a/42sh/src/lexer/lexer_lex.c +++ b/42sh/src/lexer/lexer_lex.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ -/* Updated: 2017/03/05 14:52:49 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:49:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,8 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) = { - &lexer_paren, &lexer_default, + &lexer_paren, &lexer_newline, &lexer_delim, &lexer_sep, @@ -31,7 +31,7 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) = &lexer_bquote, &lexer_bquote, &lexer_backslash, - &lexer_curly_brackets, + &lexer_curly_braces, &lexer_assignement_word, &lexer_comment, &lexer_end, diff --git a/42sh/src/lexer/lexer_number.c b/42sh/src/lexer/lexer_number.c index d9eb81e5..0d0b2c3b 100644 --- a/42sh/src/lexer/lexer_number.c +++ b/42sh/src/lexer/lexer_number.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */ -/* Updated: 2017/03/05 16:44:00 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:48:47 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,18 +19,16 @@ int lexer_number(t_list **alst, t_lexer *lexer) token = (*alst)->content; token->type = TK_IO_NUMBER; - if ((state = get_state_global(lexer))) - { - lexer->state = state; - return (lexer_lex(alst, lexer)); - } - else if ((state = get_state_redir(lexer))) + if ((state = get_state_global(lexer)) + || (state = get_state_redir(lexer))) { lexer->state = state; return (lexer_lex(alst, lexer)); } else if (ft_isdigit(lexer->str[lexer->pos]) - && (lexer->str[lexer->pos + 1] == '>' || lexer->str[lexer->pos + 1] == '<')) + && (ft_isdigit(lexer->str[lexer->pos + 1]) + || lexer->str[lexer->pos + 1] == '>' + || lexer->str[lexer->pos + 1] == '<')) { token_append(token, lexer, 0, 0); lexer->pos++; diff --git a/42sh/src/lexer/lexer_paren.c b/42sh/src/lexer/lexer_paren.c index bb517adf..db8b0545 100644 --- a/42sh/src/lexer/lexer_paren.c +++ b/42sh/src/lexer/lexer_paren.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 17:37:15 by jhalford #+# #+# */ -/* Updated: 2017/03/05 14:47:09 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:48:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,29 +15,21 @@ int lexer_paren(t_list **alst, t_lexer *lexer) { t_token *token; - t_list **lst; - lst = alst; - if (*alst) - { - token = (*alst)->content; - if (token->type) - lst = &(*alst)->next; - } - token = token_init(); - *lst = ft_lstnew(token, sizeof(*token)); - token = (*lst)->content; + token = (*alst)->content; + if (token->type) + lexer_lex(&(*alst)->next, lexer); if (lexer->str[lexer->pos] == '(') { token->type = TK_PAREN_OPEN; push(&lexer->stack, PAREN); } - else if (lexer->stack && *(int*)lexer->stack->content == PAREN) + else if (get_lexer_stack(*lexer)) { token->type = TK_PAREN_CLOSE; pop(&lexer->stack); } lexer->pos++; lexer->state = DEFAULT; - return (lexer_lex(&(*lst)->next, lexer)); + return (lexer_lex(&(*alst)->next, lexer)); } diff --git a/42sh/src/lexer/token_print.c b/42sh/src/lexer/token_print.c index 98c29591..4f71879f 100644 --- a/42sh/src/lexer/token_print.c +++ b/42sh/src/lexer/token_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */ -/* Updated: 2017/03/01 16:25:30 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:27:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ void token_print(t_list *lst) while (lst) { - DG("token print"); if (lst->content) token = lst->content; if (token->type) diff --git a/42sh/src/line-editing/lib_line_editing/toolz_parseur.c b/42sh/src/line-editing/lib_line_editing/toolz_parseur.c index a0781e12..7c14dc9b 100644 --- a/42sh/src/line-editing/lib_line_editing/toolz_parseur.c +++ b/42sh/src/line-editing/lib_line_editing/toolz_parseur.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */ -/* Updated: 2017/02/02 14:29:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/05 15:31:42 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,12 @@ char *ft_realloc_imput(char *str, int a, size_t pos) { - int i; +// int i; char tmp[2]; char *str_tmp; char *new_str; - i = 0; +// i = 0; tmp[0] = (char)a; tmp[1] = '\0'; if (!str) diff --git a/42sh/src/line-editing/move_up_and_down.c b/42sh/src/line-editing/move_up_and_down.c index 26eaa8d8..742f232a 100644 --- a/42sh/src/line-editing/move_up_and_down.c +++ b/42sh/src/line-editing/move_up_and_down.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */ -/* Updated: 2017/02/14 11:18:54 by gwojda ### ########.fr */ +/* Updated: 2017/03/05 15:32:18 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,9 +40,9 @@ static void ft_up_2(size_t *pos, char *str) void ft_up(void) { - int i; +// int i; - i = 0; +// i = 0; if (!STR || !POS) return ; if (STR[POS - 1] == '\n') diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 0dbee69a..47fed25d 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/05 16:38:23 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:47:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,7 +83,6 @@ int get_input_fd() return (fd); else if (data->opts & SH_OPTS_LC) { - DG(); pipe(fds); fd = fds[PIPE_READ]; file = shell_get_avdata(); diff --git a/42sh/src/main/shell_get_opts.c b/42sh/src/main/shell_get_opts.c index 98742c4b..6e259f08 100644 --- a/42sh/src/main/shell_get_opts.c +++ b/42sh/src/main/shell_get_opts.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */ -/* Updated: 2017/03/03 19:53:11 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:28:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index 8955d666..6b4661ed 100644 --- a/42sh/src/parser/add_case.c +++ b/42sh/src/parser/add_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 20:42:13 by ariard #+# #+# */ -/* Updated: 2017/03/05 14:47:19 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:47:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,10 +15,11 @@ int iscase(t_btree **ast, t_list **lst) { t_astnode *node; - t_token *token; +// t_token *token; + (void)lst; node = NULL; - token = (*lst)->content; +// token = (*lst)->content; if (*ast) { node = (*ast)->item; diff --git a/42sh/src/parser/add_condition.c b/42sh/src/parser/add_condition.c index d73dc8d1..6dd90ac6 100644 --- a/42sh/src/parser/add_condition.c +++ b/42sh/src/parser/add_condition.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 18:12:52 by ariard #+# #+# */ -/* Updated: 2017/03/04 21:51:34 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:32:49 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,10 +15,10 @@ int iscondition(t_btree **ast, t_list **lst) { t_astnode *node; - t_token *token; +// t_token *token; node = NULL; - token = (*lst)->content; +// token = (*lst)->content; DG("iscondition"); if (*ast) { diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index fc775e97..63481be3 100644 --- a/42sh/src/parser/add_loop.c +++ b/42sh/src/parser/add_loop.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ -/* Updated: 2017/03/05 15:51:04 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:46:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,10 +15,10 @@ int isloop(t_btree **ast, t_list **lst) { t_astnode *node; - t_token *token; +// t_token *token; node = NULL; - token = (*lst)->content; +// token = (*lst)->content; DG("isloop"); if (*ast) { diff --git a/42sh/src/parser/add_subshell.c b/42sh/src/parser/add_subshell.c index 03fc263a..02618324 100644 --- a/42sh/src/parser/add_subshell.c +++ b/42sh/src/parser/add_subshell.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ -/* Updated: 2017/03/03 14:27:44 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:34:12 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,10 +15,11 @@ int issubshell(t_btree **ast, t_list **lst) { t_astnode *node; - t_token *token; +// t_token *token; + (void)lst; node = NULL; - token = (*lst)->content; +// token = (*lst)->content; if (*ast) { node = (*ast)->item;