From 1ac56a21e8f8b2df9cd6654176ec608ff80ab28e Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Tue, 29 Nov 2016 15:39:39 +0100 Subject: [PATCH] quoting FSM repaired --- 42sh/includes/minishell.h | 9 +++----- 42sh/src/lexer/qstate_update.c | 26 +++++++++++++---------- 42sh/src/line-editing/ft_interactive_sh.c | 2 +- 42sh/src/line-editing/ft_key_default.c | 2 +- 42sh/src/line-editing/ft_key_del.c | 2 +- 42sh/src/line-editing/ft_key_enter.c | 4 ++-- 42sh/src/parser/parse_separator.c | 2 ++ 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 027851f9..ec2e308b 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: 2016/11/28 18:53:42 by jhalford ### ########.fr */ +/* Updated: 2016/11/29 15:32:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,14 +41,11 @@ enum e_qstate struct s_data { - char **env; - t_dlist *history; - + char **env; + t_dlist *history; char *input; int input_pos; t_list *qstack; - t_qstate state_now; - t_qstate state_last; int fdin; int fdout; }; diff --git a/42sh/src/lexer/qstate_update.c b/42sh/src/lexer/qstate_update.c index 04a94439..a415553b 100644 --- a/42sh/src/lexer/qstate_update.c +++ b/42sh/src/lexer/qstate_update.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 16:56:11 by jhalford #+# #+# */ -/* Updated: 2016/11/28 19:27:44 by jhalford ### ########.fr */ +/* Updated: 2016/11/29 15:38:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,40 +15,44 @@ void qstate_update(t_data *data, char c) { t_qstate *state; + t_qstate *new; t_list **list; t_list *tmp; list = &data->qstack; state = (*list)->content; - ft_lstadd(list, ft_lstnew(NULL, sizeof(t_qstate))); + /* ft_printf("befor state: %i\n", *state); */ if (c == -1) { tmp = ft_lstpop(list); ft_lstdelone(&tmp, &ft_lst_cfree); return ; } - else if (*state == Q_NONE) + ft_lstadd(list, ft_lstnew(NULL, sizeof(t_qstate))); + new = (*list)->content; + *new = *state; + if (*state == Q_NONE) { if (c == '\\') - *state = Q_BACKSLASH; + *new = Q_BACKSLASH; else if (c == '\"') - *state = Q_DQUOTE; + *new = Q_DQUOTE; else if (c == '\'') - *state = Q_QUOTE; + *new = Q_QUOTE; } else if (*state == Q_QUOTE) { if (c == '\'') - *state = Q_NONE; + *new = Q_NONE; } else if (*state == Q_DQUOTE) { if (c == '\\') - *state = Q_BACKSLASH; + *new = Q_BACKSLASH; else if (c == '\"') - *state = Q_NONE; + *new = Q_NONE; } else if (*state == Q_BACKSLASH) - state = (*list)->next->next->content; - *((t_qstate *)(*list)->content) = *state; + *new = *(t_qstate*)(*list)->next->next->content; + /* ft_printf("new state: %i\n", *new); */ } diff --git a/42sh/src/line-editing/ft_interactive_sh.c b/42sh/src/line-editing/ft_interactive_sh.c index d4506c24..d3c456d6 100644 --- a/42sh/src/line-editing/ft_interactive_sh.c +++ b/42sh/src/line-editing/ft_interactive_sh.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:44:21 by jhalford #+# #+# */ -/* Updated: 2016/11/28 19:28:23 by jhalford ### ########.fr */ +/* Updated: 2016/11/29 15:32:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_key_default.c b/42sh/src/line-editing/ft_key_default.c index 85603e0c..540be2c5 100644 --- a/42sh/src/line-editing/ft_key_default.c +++ b/42sh/src/line-editing/ft_key_default.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:45:23 by jhalford #+# #+# */ -/* Updated: 2016/11/28 19:27:47 by jhalford ### ########.fr */ +/* Updated: 2016/11/29 13:49:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_key_del.c b/42sh/src/line-editing/ft_key_del.c index 435d8f3c..d8f4df97 100644 --- a/42sh/src/line-editing/ft_key_del.c +++ b/42sh/src/line-editing/ft_key_del.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:44:26 by jhalford #+# #+# */ -/* Updated: 2016/11/28 18:54:02 by jhalford ### ########.fr */ +/* Updated: 2016/11/29 13:46:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_key_enter.c b/42sh/src/line-editing/ft_key_enter.c index 9707d654..e8739a4e 100644 --- a/42sh/src/line-editing/ft_key_enter.c +++ b/42sh/src/line-editing/ft_key_enter.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:44:30 by jhalford #+# #+# */ -/* Updated: 2016/11/28 19:02:05 by jhalford ### ########.fr */ +/* Updated: 2016/11/29 13:50:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ int ft_key_enter(t_data *data, char *buf) { (void)buf; - if (data->state_now == Q_NONE) + if (*(t_qstate*)data->qstack->content == Q_NONE) { ft_putchar('\n'); ft_history_add(data); diff --git a/42sh/src/parser/parse_separator.c b/42sh/src/parser/parse_separator.c index c16b4b4b..2b926da6 100644 --- a/42sh/src/parser/parse_separator.c +++ b/42sh/src/parser/parse_separator.c @@ -20,8 +20,10 @@ int parse_separator(t_btree **ast, t_list **start, t_list **lst) token = (*lst)->content; node = (*ast)->item; ft_parse(&(*ast)->right, &(*lst)->next); + node->type = token->type; ft_lstdelone(lst, &token_free); + ft_parse(&(*ast)->left, start); return (0); }