diff --git a/42sh/Makefile b/42sh/Makefile index 6fb08372..7a5d7b54 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -179,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\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index f81bbeef..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/05 15:14:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:19:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ 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/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index efee8bea..4cb2db38 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/04 17:09:11 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:58:16 by jhalford ### ########.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_command.c b/42sh/src/exec/exec_command.c index a0656c3a..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/05 15:14:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:42:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index ab304058..85cade9b 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/05 14:41:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:42:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,9 +18,9 @@ int launch_process(t_process *p) 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)) @@ -28,41 +28,38 @@ int launch_process(t_process *p) set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env), 1); return (1); } - else + p->attributes &= ~PROCESS_STATE_MASK; + p->attributes |= PROCESS_RUNNING; + if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT) + && access(p->path, X_OK) == -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); - /* 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); + 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 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 index 878ce011..88a39993 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:18:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:42:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ 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/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_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 a9d2b823..c5900571 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/04 20:51:21 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:28:15 by jhalford ### ########.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_paren.c b/42sh/src/lexer/lexer_paren.c index d903a645..ee205745 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:46:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:29:28 by jhalford ### ########.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/main/main.c b/42sh/src/main/main.c index 7ebb7a70..639ed5ce 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 15:16:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:30:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ 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 */ /* */ /* ************************************************************************** */