From f7d0f0408a6444bb36be18b10b66148472430b99 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 17 Mar 2017 19:27:22 +0100 Subject: [PATCH 1/6] petite lecon des familles --- 42sh/src/lexer/get_reserved_words.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index 7e95db6f..c4a7deab 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/03/17 17:21:23 by ariard ### ########.fr */ +/* Updated: 2017/03/17 19:27:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,7 @@ t_rvwords g_rvwords[] = static int recognization_rvwords(t_token *pv_tk, t_token *at_tk) { - if (!pv_tk || (pv_tk->type == TK_NEWLINE || pv_tk->type == TK_AMP + return (!pv_tk || (pv_tk->type == TK_NEWLINE || pv_tk->type == TK_AMP || pv_tk->type == TK_SEMI || pv_tk->type == TK_PIPE || pv_tk->type == TK_WHILE || pv_tk->type == TK_DONE || pv_tk->type == TK_DO || pv_tk->type == TK_IF @@ -39,8 +39,6 @@ static int recognization_rvwords(t_token *pv_tk, t_token *at_tk) || pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE || pv_tk->type == TK_DSEMI) || (pv_tk->type == TK_PAREN_CLOSE && at_tk->type == TK_PAREN_OPEN)) - return (1); - return (0); } static int match_words(t_token *token) @@ -60,14 +58,12 @@ static int match_words(t_token *token) return (0); } -int get_reserved_words(t_list **alst) +int get_reserved_words(t_list *temp) { t_token *token; t_token *pv_tk; t_token *ante_token; - t_list *temp; - temp = *alst; pv_tk = NULL; ante_token = NULL; while (temp) From 9bda99e13935cb1a94aa52b4d07a68f9411ea06e Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 17 Mar 2017 19:46:11 +0100 Subject: [PATCH 2/6] ca compile deso deso --- 42sh/includes/lexer.h | 4 ++-- 42sh/src/lexer/get_reserved_words.c | 4 ++-- 42sh/src/lexer/lexer_assignement_word.c | 14 +++++++------- 42sh/src/lexer/lexer_default.c | 6 +----- 42sh/src/lexer/lexer_dquote.c | 4 ++-- 42sh/src/lexer/lexer_word.c | 5 ++++- 42sh/src/main/main.c | 2 +- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 46c9f14f..de3f86ab 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/17 00:07:51 by ariard ### ########.fr */ +/* Updated: 2017/03/17 19:34:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,7 +92,7 @@ char *stack_to_prompt(t_list *stack); t_lexstate get_state_global(t_lexer *lexer); t_lexstate get_state_redir(t_lexer *lexer); int get_lexer_stack(t_lexer lexer); -int get_reserved_words(t_list **alst); +int get_reserved_words(t_list *temp); int insert_newline(t_list **alst); void lexer_init(t_lexer *lexer); diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index c4a7deab..930d8ea4 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/03/17 19:27:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 19:33:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,7 +38,7 @@ static int recognization_rvwords(t_token *pv_tk, t_token *at_tk) || pv_tk->type == TK_FI || pv_tk->type == TK_THEN || pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE || pv_tk->type == TK_DSEMI) || (pv_tk->type == TK_PAREN_CLOSE - && at_tk->type == TK_PAREN_OPEN)) + && at_tk->type == TK_PAREN_OPEN)); } static int match_words(t_token *token) diff --git a/42sh/src/lexer/lexer_assignement_word.c b/42sh/src/lexer/lexer_assignement_word.c index 28453bce..06d12691 100644 --- a/42sh/src/lexer/lexer_assignement_word.c +++ b/42sh/src/lexer/lexer_assignement_word.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 20:28:13 by ariard #+# #+# */ -/* Updated: 2017/03/14 00:50:34 by ariard ### ########.fr */ +/* Updated: 2017/03/17 19:33:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,12 +18,12 @@ int lexer_assignement_word(t_list **alst, t_lexer *lexer) char c; token = (*alst)->content; - if (token->type != TK_WORD && token->type != TK_ASSIGNMENT_WORD) - { - token_append(token, lexer, 0, 0); - lexer->pos++; - return (lexer_lex(alst, lexer)); - } + /* if (token->type != TK_WORD && token->type != TK_ASSIGNMENT_WORD) */ + /* { */ + /* token_append(token, lexer, 0, 0); */ + /* lexer->pos++; */ + /* return (lexer_lex(alst, lexer)); */ + /* } */ token->type = TK_ASSIGNMENT_WORD; token_append(token, lexer, 0, 0); lexer->pos++; diff --git a/42sh/src/lexer/lexer_default.c b/42sh/src/lexer/lexer_default.c index 3589f20c..7e6c2184 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 21:42:47 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 19:28:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,13 +19,9 @@ int lexer_default(t_list **alst, t_lexer *lexer) 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 903442b0..4e2f1760 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/16 22:59:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 19:27:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ int lexer_dquote(t_list **alst, t_lexer *lexer) else if (lexer->str[lexer->pos] == '\\') { if (lexer->str[lexer->pos + 1] == 0) - return(lexer_backslash(alst, lexer)); + return (lexer_backslash(alst, lexer)); token_append(token, lexer, 1, 1); } else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE)) diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 8fc1ac99..584eec42 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ -/* Updated: 2017/03/16 14:44:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 19:33:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,10 @@ int lexer_word(t_list **alst, t_lexer *lexer) lexer->state = ASSIGNEMENT_WORD; return (lexer_lex(alst, lexer)); } + else + { token_append(token, lexer, 0, 0); lexer->pos++; + } return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 647f30ea..517989d3 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -56,7 +56,7 @@ static int do_parser_routine(void) t_data *data; data = data_singleton(); - if (get_reserved_words(&data->token)) + if (get_reserved_words(data->token)) return (1); if (insert_newline(&data->token)) return (1); From 8427ab28bfd1b6c7adc5558ddac14d6e906a9066 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 17 Mar 2017 20:22:09 +0100 Subject: [PATCH 3/6] lexer_assignment_word factorizating: it doesnt exist anymore... --- 42sh/includes/lexer.h | 3 +- 42sh/src/builtin/is_builtin.c | 2 +- 42sh/src/lexer/get_reserved_words.c | 2 +- 42sh/src/lexer/get_state_global.c | 2 +- 42sh/src/lexer/lexer_assignement_word.c | 37 ------------------------- 42sh/src/lexer/lexer_backslash.c | 4 +-- 42sh/src/lexer/lexer_bquote.c | 4 +-- 42sh/src/lexer/lexer_dquote.c | 4 +-- 42sh/src/lexer/lexer_lex.c | 3 +- 42sh/src/lexer/lexer_quote.c | 4 +-- 42sh/src/lexer/lexer_word.c | 18 ++++++------ 11 files changed, 21 insertions(+), 62 deletions(-) delete mode 100644 42sh/src/lexer/lexer_assignement_word.c diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index de3f86ab..77fabbf9 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/17 19:34:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:19:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,6 @@ enum e_lexstate BQUOTE, BACKSLASH, CURLY_BRACKETS, - ASSIGNEMENT_WORD, END, }; diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 876727c7..270c70ef 100644 --- a/42sh/src/builtin/is_builtin.c +++ b/42sh/src/builtin/is_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ -/* Updated: 2017/03/16 15:54:15 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 19:51:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index 930d8ea4..42702849 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/03/17 19:33:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:19:59 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index ba46cae6..3b7fe898 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/17 00:08:12 by ariard ### ########.fr */ +/* Updated: 2017/03/17 20:02:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_assignement_word.c b/42sh/src/lexer/lexer_assignement_word.c deleted file mode 100644 index 06d12691..00000000 --- a/42sh/src/lexer/lexer_assignement_word.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* lexer_assignement_word.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/02/24 20:28:13 by ariard #+# #+# */ -/* Updated: 2017/03/17 19:33:12 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int lexer_assignement_word(t_list **alst, t_lexer *lexer) -{ - t_token *token; - char c; - - token = (*alst)->content; - /* if (token->type != TK_WORD && token->type != TK_ASSIGNMENT_WORD) */ - /* { */ - /* token_append(token, lexer, 0, 0); */ - /* lexer->pos++; */ - /* return (lexer_lex(alst, lexer)); */ - /* } */ - token->type = TK_ASSIGNMENT_WORD; - token_append(token, lexer, 0, 0); - lexer->pos++; - c = lexer->str[lexer->pos]; - if ((lexer->state = get_state_global(lexer))) - return (lexer_lex(alst, lexer)); - if ((lexer->state = get_state_redir(lexer))) - return (lexer_lex(alst, lexer)); - lexer->state = ASSIGNEMENT_WORD; - return(lexer_lex(alst, lexer)); -} diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/src/lexer/lexer_backslash.c index 71a24964..e998f5a0 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/03/16 22:36:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:17:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ int lexer_backslash(t_list **alst, t_lexer *lexer) t_token *token; token = (*alst)->content; - token->type = TK_WORD; + token->type = token->type ? token->type : TK_WORD; lexer->pos++; lexer->state = WORD; if (lexer->str[lexer->pos] == 0) diff --git a/42sh/src/lexer/lexer_bquote.c b/42sh/src/lexer/lexer_bquote.c index 9d2e631c..b7236305 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/16 22:30:59 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:07:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int lexer_bquote(t_list **alst, t_lexer *lexer) int back; token = (*alst)->content; - token->type = TK_WORD; + token->type = token->type ? token->type : TK_WORD; back = 0; if (lexer->str[lexer->pos] == '`') { diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/src/lexer/lexer_dquote.c index 4e2f1760..f4df5b90 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/17 19:27:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:08:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ int lexer_dquote(t_list **alst, t_lexer *lexer) t_token *token; token = (*alst)->content; - token->type = TK_WORD; + token->type = token->type ? token->type : TK_WORD; if (lexer->str[lexer->pos] == '"') { if (get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD)) diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index 8e6a9df3..80f590da 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/17 00:09:05 by ariard ### ########.fr */ +/* Updated: 2017/03/17 20:21:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,6 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) = &lexer_bquote, &lexer_backslash, &lexer_curly_braces, - &lexer_assignement_word, &lexer_end, }; diff --git a/42sh/src/lexer/lexer_quote.c b/42sh/src/lexer/lexer_quote.c index 67cbc4c7..f758416f 100644 --- a/42sh/src/lexer/lexer_quote.c +++ b/42sh/src/lexer/lexer_quote.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:08 by jhalford #+# #+# */ -/* Updated: 2017/02/17 15:28:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:16:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ int lexer_quote(t_list **alst, t_lexer *lexer) t_token *token; token = (*alst)->content; - token->type = TK_WORD; + token->type = token->type ? token->type : TK_WORD; if (lexer->str[lexer->pos] == '\'') { lexer->pos++; diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 584eec42..665c0a0a 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ -/* Updated: 2017/03/17 19:33:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:17:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,23 +18,21 @@ int lexer_word(t_list **alst, t_lexer *lexer) t_lexstate state; token = (*alst)->content; - token->type = TK_WORD; + token->type = token->type ? token->type : TK_WORD; if ((state = get_state_global(lexer)) || (state = get_state_redir(lexer))) - { lexer->state = state; - return (lexer_lex(alst, lexer)); - } - if (lexer->str[lexer->pos] == '=' + else if (lexer->str[lexer->pos] == '=' && word_is_assignment((char *[]){token->data, (char *)token->esc})) { - lexer->state = ASSIGNEMENT_WORD; - return (lexer_lex(alst, lexer)); + token->type = TK_ASSIGNMENT_WORD; + token_append(token, lexer, 0, 0); + lexer->pos++; } else { - token_append(token, lexer, 0, 0); - lexer->pos++; + token_append(token, lexer, 0, 0); + lexer->pos++; } return (lexer_lex(alst, lexer)); } From 043b0247b8cec1aa13129c34dd0457fb88e4f634 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 17 Mar 2017 21:02:13 +0100 Subject: [PATCH 4/6] token and ast not in data_singleton() --- 42sh/Makefile | 1 - 42sh/includes/minishell.h | 4 +--- 42sh/src/lexer/lexer_backslash.c | 2 +- 42sh/src/lexer/lexer_bquote.c | 2 +- 42sh/src/main/data_init.c | 4 +--- 42sh/src/main/main.c | 36 ++++++++++++++++++-------------- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 98dd358c..0e4a1bed 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -214,7 +214,6 @@ lexer/get_reserved_words.c\ lexer/get_state_global.c\ lexer/get_state_redir.c\ lexer/insert_newline.c\ -lexer/lexer_assignement_word.c\ lexer/lexer_backslash.c\ lexer/lexer_bquote.c\ lexer/lexer_curly_braces.c\ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index eaeb4c37..7c408f3a 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/17 00:20:53 by ariard ### ########.fr */ +/* Updated: 2017/03/17 20:52:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,8 +45,6 @@ struct s_data int argc; char **argv; t_line line; - t_list *token; - t_btree *ast; t_lexer lexer; t_parser parser; t_comp *comp; diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/src/lexer/lexer_backslash.c index e998f5a0..36af22c4 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/03/17 20:17:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:01:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_bquote.c b/42sh/src/lexer/lexer_bquote.c index b7236305..084db882 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/17 20:07:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:01:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index cae2ce88..77ac8219 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/17 17:41:33 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 20:51:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,8 +38,6 @@ int data_init(int ac, char **av) data->opts = 0; exec_reset(); data->lst_func = NULL; - data->token = NULL; - data->ast = NULL; lexer_init(&data->lexer); parser_init(&data->parser); if ((term_name = ft_getenv(data->env, "TERM")) == NULL) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 517989d3..7327654b 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -28,7 +28,7 @@ static int do_readline_routine(char **stream) return (ret); } -static int do_lexer_routine(char *stream) +static int do_lexer_routine(t_list **token, char *stream) { t_list *ltoken; t_data *data; @@ -42,8 +42,8 @@ static int do_lexer_routine(char *stream) ft_strappend(&data->lexer.str, stream); if (get_lexer_stack(data->lexer) == BACKSLASH) pop(&data->lexer.stack); - ltoken = ft_lstlast(data->token); - if (lexer_lex(data->token ? <oken : &data->token, &data->lexer) < 0) + ltoken = ft_lstlast(*token); + if (lexer_lex(*token ? <oken : token, &data->lexer) < 0) exit(1); if (get_lexer_stack(data->lexer) > 2) return (1); @@ -51,24 +51,24 @@ static int do_lexer_routine(char *stream) return (0); } -static int do_parser_routine(void) +static int do_parser_routine(t_list **token, t_btree **ast) { t_data *data; data = data_singleton(); - if (get_reserved_words(data->token)) + if (get_reserved_words(*token)) return (1); - if (insert_newline(&data->token)) + if (insert_newline(token)) return (1); if (data->parser.state == SUCCESS && stack_init(&data->parser)) exit(1); - if (ft_parse(&data->ast, &data->token, &data->parser)) + if (ft_parse(ast, token, &data->parser)) exit(1); if ((data->lexer.state = data->parser.heredoc_queue ? HEREDOC : DEFAULT)) return (0); if (data->parser.state == ERROR) { - error_syntax(&data->token); + error_syntax(token); return (1); } else if (data->parser.state == SUCCESS) @@ -76,7 +76,7 @@ static int do_parser_routine(void) return (0); } -static int handle_instruction() +static int handle_instruction(t_list **token, t_btree **ast) { int ret; char *stream; @@ -88,14 +88,14 @@ static int handle_instruction() { if ((ret = do_readline_routine(&stream)) > 0) return (ret); - if (do_lexer_routine(stream) > 0) + if (do_lexer_routine(token, stream) > 0) continue ; - token_print(data->token); - if (do_parser_routine() > 0) + token_print(*token); + if (do_parser_routine(token, ast) > 0) break ; } /* btree_print(STDBUG, ast, &ft_putast); */ - if (data->parser.state == SUCCESS && ft_exec(&data->ast) < 0) + if (data->parser.state == SUCCESS && ft_exec(ast) < 0) exit(1); if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str) ft_add_str_in_history(data->lexer.str); @@ -106,6 +106,8 @@ int main(int ac, char **av) { int ret; t_data *data; + t_list *token; + t_btree *ast; g_argv = av; setlocale(LC_ALL, ""); @@ -113,14 +115,16 @@ int main(int ac, char **av) if (shell_init(ac, av)) return (1); DG("JOBC is %s", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF"); + token = NULL; + ast = NULL; data = data_singleton(); while (1) { - ret = handle_instruction(); + ret = handle_instruction(&token, &ast); lexer_destroy(&data->lexer); parser_destroy(&data->parser); - ft_lstdel(&data->token, &ft_lst_cfree); - btree_del(&data->ast, &ft_lst_cfree); + ft_lstdel(&token, &token_free); + btree_del(&ast, &ast_free); if (ret == 1) break ; } From 6f4ecd2960c1b0e30bbcc2ec53b29d56293dad11 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 17 Mar 2017 21:16:54 +0100 Subject: [PATCH 5/6] bquotes and '-c' work again --- 42sh/includes/minishell.h | 5 +++-- 42sh/src/line-editing/readline.c | 4 ++-- 42sh/src/main/data_init.c | 4 ++-- 42sh/src/main/shell_init.c | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 7c408f3a..70d0c6d0 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/17 20:52:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:13:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,12 +41,13 @@ struct s_data { t_flag opts; + int fd; char **env; int argc; char **argv; t_line line; t_lexer lexer; - t_parser parser; + t_parser parser; t_comp *comp; t_exec exec; t_jobc jobc; diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 0b84ab3d..8cf2a404 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/17 16:10:40 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 21:14:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ int readline(int has_prompt, char **input) if (!has_prompt) data_singleton()->line.prompt_size = 1; if (!SH_IS_INTERACTIVE(data_singleton()->opts)) - return ((ret = get_next_line(STDIN, input)) >= 0 ? !ret : ret); + return ((ret = get_next_line(data_singleton()->fd, input)) >= 0 ? !ret : ret); readline_init(has_prompt); ret = ft_read_stdin(input); if (ret < 0) diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 77ac8219..71d87f6b 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:51:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:16:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int data_init(int ac, char **av) { t_data *data; char *term_name; - char* shlvl; + char *shlvl; data = data_singleton(); data->argc = ac; diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index fbbf106b..28ee9e8d 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/16 23:25:29 by ariard ### ########.fr */ +/* Updated: 2017/03/17 21:16:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,11 +33,10 @@ int get_input_fd(char **av) else if (data->opts & SH_OPTS_LC) { pipe(fds); - dup2_close(fds[PIPE_READ], 10); - fd = 10; file = *cliopts_getdata(av); write(fds[PIPE_WRITE], file, ft_strlen(file)); close(fds[PIPE_WRITE]); + dup2_close(fds[PIPE_READ], (fd = 10)); fcntl(fd, F_SETFD, FD_CLOEXEC); return (fd); } @@ -93,6 +92,7 @@ int shell_init(int ac, char **av) } if (cliopts_get(av, g_opts, data)) return (ft_perror()); + data->fd = get_input_fd(av); if (SH_IS_INTERACTIVE(data->opts)) interactive_settings(); return (0); From 4524fac2c8d71448655d2d822efa21ca5ba567bd Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 17 Mar 2017 22:59:56 +0100 Subject: [PATCH 6/6] plein de headers mis a jour avec mon nom --- 42sh/libft/includes/libft.h | 2 +- 42sh/libft/src/ft_printf/ft_printf.c | 2 +- 42sh/src/exec/mark_process_status.c | 9 +++++---- 42sh/src/job-control/process_format.c | 23 ++++++++++++++--------- 42sh/src/main/data_init.c | 2 +- 42sh/src/main/shell_init.c | 2 +- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/42sh/libft/includes/libft.h b/42sh/libft/includes/libft.h index 56cdf59b..986cda46 100644 --- a/42sh/libft/includes/libft.h +++ b/42sh/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2017/03/15 20:51:55 by ariard ### ########.fr */ +/* Updated: 2017/03/17 21:30:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/ft_printf/ft_printf.c b/42sh/libft/src/ft_printf/ft_printf.c index fb813acd..f392b79e 100644 --- a/42sh/libft/src/ft_printf/ft_printf.c +++ b/42sh/libft/src/ft_printf/ft_printf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2017/03/14 20:24:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:33:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 3c2ef390..dbde6d7d 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 23:00:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:38:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,9 +30,10 @@ int mark_process_status(pid_t pid, int status) { p->attrs &= ~PROCESS_STATE_MASK; p->attrs |= PROCESS_COMPLETED; - if (WIFSIGNALED(status) && DEBUG_MODE) - ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", - (int)pid, WTERMSIG(status)); + if (WIFSIGNALED(status)) + psignal(WTERMSIG(status), NULL); + /* ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", */ + /* (int)pid, WTERMSIG(status)); */ } return (0); } diff --git a/42sh/src/job-control/process_format.c b/42sh/src/job-control/process_format.c index facaad6f..783fea8c 100644 --- a/42sh/src/job-control/process_format.c +++ b/42sh/src/job-control/process_format.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */ -/* Updated: 2017/03/16 16:41:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:35:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,27 +34,32 @@ static int redirection_print(t_redir *redir) static void process_format_state(t_process *p) { - int state; + int state; + char *statestr; state = p->attrs & PROCESS_STATE_MASK; + statestr = NULL; if (state == PROCESS_RUNNING) - ft_putstr("running "); + ft_asprintf(&statestr, "running"); else if (state == PROCESS_SUSPENDED) - ft_putstr("suspended"); + ft_asprintf(&statestr, "suspended"); else if (state == PROCESS_CONTINUED) { - ft_putstr("continued"); + ft_asprintf(&statestr, "continued"); p->attrs &= ~PROCESS_STATE_MASK; p->attrs |= PROCESS_RUNNING; } else if (state == PROCESS_COMPLETED) { - if (p->status == 0) - ft_putstr("done "); + if (WIFSIGNALED(p->status)) + ft_asprintf(&statestr, strsignal(WTERMSIG(p->status))); + else if (p->status == 0) + ft_asprintf(&statestr, "done"); else - ft_printf("exit %i ", p->status); + ft_asprintf(&statestr, "%s %i", "exit", WEXITSTATUS(p->status)); } - ft_putchar('\t'); + ft_printf("%-*s\t", 12, statestr); + ft_strdel(&statestr); } static void process_format_com_long(t_list **plist) diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 71d87f6b..7c901196 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/17 21:16:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:18:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 28ee9e8d..a8441c2e 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/17 21:16:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:18:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */