diff --git a/42sh/Makefile b/42sh/Makefile index fb1e3dc8..6a620772 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/15 18:11:31 by jhalford ### ########.fr # +# Updated: 2017/03/16 23:02:12 by jhalford ### ########.fr # # # # **************************************************************************** # diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 06e5c1a6..d7a15af5 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/15 21:54:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 20:24:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 42a623cf..46c9f14f 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/16 23:36:02 by ariard ### ########.fr */ +/* Updated: 2017/03/17 00:07:51 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,7 +34,6 @@ enum e_lexstate QUOTE, DQUOTE, BQUOTE, - DQUOTE_BQUOTE, BACKSLASH, CURLY_BRACKETS, ASSIGNEMENT_WORD, diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 262ed34e..a144b2e4 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/16 22:18:45 by ariard ### ########.fr */ +/* Updated: 2017/03/16 23:01:59 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,34 +32,35 @@ # include "completion.h" # include "hash.h" +#ifndef DEBUG +# define DEBUG_MODE 0 +#else +# define DEBUG_MODE 1 +#endif + struct s_data { - t_flag opts; - int fd; - char **env; - int argc; - char **argv; - t_line line; - t_list *token; - t_btree *ast; - t_lexer lexer; - t_parser parser; - t_comp *comp; - t_exec exec; - t_jobc jobc; - char **local_var; - t_list *lst_func; + t_flag opts; + char **env; + int argc; + char **argv; + t_line line; + t_comp *comp; + t_exec exec; + t_jobc jobc; + t_list *heredoc_queue; + char **local_var; + t_list *lst_func; }; int shell_init(int ac, char **av); void shell_exit(void); int data_init(int ac, char **av); void data_exit(void); -int error_msg(char *msg); -int instruction_free( - t_list **token, t_btree **ast, t_lexer *lexer, t_parser *parser); -/* void content_free(void *data, size_t content_size); */ +int instruction_free(t_list **token, t_parser *parser, + t_btree **ast); +void content_free(void *data, size_t content_size); char *ft_putast(void *node); void ft_putast2(void *node); diff --git a/42sh/includes/types.h b/42sh/includes/types.h index aad1f77e..a275a8fa 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/16 18:17:16 by ariard ### ########.fr */ +/* Updated: 2017/03/17 00:06:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 55852698..4fdd864f 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/16 18:40:47 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 21:45:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 7341d593..3c2ef390 100644 --- a/42sh/src/exec/mark_process_status.c +++ b/42sh/src/exec/mark_process_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/16 16:50:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 23:00:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ int mark_process_status(pid_t pid, int status) { p->attrs &= ~PROCESS_STATE_MASK; p->attrs |= PROCESS_COMPLETED; - if (WIFSIGNALED(status)) + if (WIFSIGNALED(status) && DEBUG_MODE) ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", (int)pid, WTERMSIG(status)); } diff --git a/42sh/src/exec/plaunch_brace.c b/42sh/src/exec/plaunch_brace.c index 069123e9..f584cb6b 100644 --- a/42sh/src/exec/plaunch_brace.c +++ b/42sh/src/exec/plaunch_brace.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ -/* Updated: 2017/03/16 18:42:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 21:42:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index b1b4ed6a..52036dec 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/16 18:51:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 20:08:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index 7ee3a391..d1f6980d 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/16 18:40:59 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 21:42:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index bac28023..9ad707f9 100644 --- a/42sh/src/job-control/job_addprocess.c +++ b/42sh/src/job-control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2017/03/16 18:24:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 22:23:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_lexer_stack.c b/42sh/src/lexer/get_lexer_stack.c index b37ec859..a3c91de3 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/07 19:33:30 by ariard ### ########.fr */ +/* Updated: 2017/03/16 22:50:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index aca394e5..ba46cae6 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/16 19:00:30 by ariard ### ########.fr */ +/* Updated: 2017/03/17 00:08:12 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/src/lexer/lexer_backslash.c index 3418e2a2..71a24964 100644 --- a/42sh/src/lexer/lexer_backslash.c +++ b/42sh/src/lexer/lexer_backslash.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ -/* Updated: 2017/02/20 22:04:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 22:36:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_bquote.c b/42sh/src/lexer/lexer_bquote.c index aa958410..9d2e631c 100644 --- a/42sh/src/lexer/lexer_bquote.c +++ b/42sh/src/lexer/lexer_bquote.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */ -/* Updated: 2017/03/08 23:32:14 by ariard ### ########.fr */ +/* Updated: 2017/03/16 22:30:59 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,40 +15,25 @@ int lexer_bquote(t_list **alst, t_lexer *lexer) { t_token *token; - int top_state; + int back; token = (*alst)->content; token->type = TK_WORD; - if (lexer->state == DQUOTE_BQUOTE) - token_append(token, lexer, 1, 0); - else - token_append(token, lexer, 0, 0); + back = 0; if (lexer->str[lexer->pos] == '`') { - lexer->pos++; - if (!(lexer->stack && (*(int*)lexer->stack->content == BQUOTE - || *(int*)lexer->stack->content == DQUOTE_BQUOTE))) - { + if (get_lexer_stack(*lexer) != BQUOTE) push(&lexer->stack, lexer->state); - return (lexer_lex(alst, lexer)); - } - top_state = pop(&lexer->stack); - lexer->state = top_state == DQUOTE_BQUOTE ? DQUOTE : DEFAULT; - return (lexer_lex(alst, lexer)); + else + lexer->state = pop(&lexer->stack) == DQUOTE ? DQUOTE : DEFAULT; } - if (lexer->str[lexer->pos] == '\\') + else if (lexer->str[lexer->pos] == '\\' && (back = 1)) { lexer->pos++; if (lexer->str[lexer->pos] == 0) - { - push(&lexer->stack, BACKSLASH); - return (0); - } - else - token_append(token, lexer, 1, 1); - lexer->pos++; - return (lexer_lex(alst,lexer)); + return (push(&lexer->stack, BACKSLASH) ? 0 : 0); } + token_append(token, lexer, back, back); lexer->pos++; return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_default.c b/42sh/src/lexer/lexer_default.c index 2ab8a22d..3589f20c 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/16 19:05:25 by ariard ### ########.fr */ +/* Updated: 2017/03/16 21:42:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,11 +17,15 @@ int lexer_default(t_list **alst, t_lexer *lexer) t_token *token; char c; - c = lexer->str[lexer->pos]; + c = lexer->str[lexer->pos]; if ((lexer->state = get_state_global(lexer))) + { + DG("got state %i",lexer->state); return (lexer_lex(alst, lexer)); + } if ((lexer->state = get_state_redir(lexer))) return (lexer_lex(alst, lexer)); + DG("no special state, %c",lexer->str[lexer->pos]); lexer->state = ft_isdigit(c) ? NUMBER : WORD; token = (*alst)->content; token->type = TK_WORD; diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/src/lexer/lexer_dquote.c index 10455689..903442b0 100644 --- a/42sh/src/lexer/lexer_dquote.c +++ b/42sh/src/lexer/lexer_dquote.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ -/* Updated: 2017/03/05 17:09:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 22:59:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,32 +20,21 @@ int lexer_dquote(t_list **alst, t_lexer *lexer) token->type = TK_WORD; if (lexer->str[lexer->pos] == '"') { - lexer->pos++; - if (!(lexer->stack && *(int*)lexer->stack->content == DQUOTE)) - { - push(&lexer->stack, DQUOTE); - return (lexer_lex(alst, lexer)); - } - lexer->state = WORD; - pop(&lexer->stack); - return (lexer_lex(alst, lexer)); - } - if (lexer->str[lexer->pos] == '\\') - { - lexer->pos++; - if (lexer->str[lexer->pos] == 0) - return (0); + if (get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD)) + pop(&lexer->stack); else - token_append(token, lexer, 1, 1); - lexer->pos++; - return (lexer_lex(alst,lexer)); + push(&lexer->stack, DQUOTE); } - else if (lexer->str[lexer->pos] == '`') + else if (lexer->str[lexer->pos] == '\\') { - lexer->state = DQUOTE_BQUOTE; - return (lexer_bquote(alst, lexer)); + if (lexer->str[lexer->pos + 1] == 0) + return(lexer_backslash(alst, lexer)); + token_append(token, lexer, 1, 1); } - token_append(token, lexer, 1, 0); + else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE)) + return (lexer_lex(alst, lexer)); + else + token_append(token, lexer, 1, 0); lexer->pos++; return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_end.c b/42sh/src/lexer/lexer_end.c index c502b53c..bae21bae 100644 --- a/42sh/src/lexer/lexer_end.c +++ b/42sh/src/lexer/lexer_end.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */ -/* Updated: 2017/03/16 14:44:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 23:17:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,8 @@ int lexer_end(t_list **alst, t_lexer *lexer) t_token *token; if (lexer->str[lexer->pos] == '#') - while (lexer->str[++lexer->pos]); + while (lexer->str[++lexer->pos]) + ; if (*alst && (lexer->state == QUOTE || lexer->state == DQUOTE || lexer->state == BQUOTE)) diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index 505b56a6..8e6a9df3 100644 --- a/42sh/src/lexer/lexer_lex.c +++ b/42sh/src/lexer/lexer_lex.c @@ -6,6 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ +/* Updated: 2017/03/17 00:09:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +27,6 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) = &lexer_quote, &lexer_dquote, &lexer_bquote, - &lexer_bquote, &lexer_backslash, &lexer_curly_braces, &lexer_assignement_word, diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 0508e694..9a3a11f9 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,6 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/16 23:38:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */