quoting FSM repaired

This commit is contained in:
Jack Halford 2016-11-29 15:39:39 +01:00
parent 3c0bd77766
commit 1ac56a21e8
7 changed files with 25 additions and 22 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 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 struct s_data
{ {
char **env; char **env;
t_dlist *history; t_dlist *history;
char *input; char *input;
int input_pos; int input_pos;
t_list *qstack; t_list *qstack;
t_qstate state_now;
t_qstate state_last;
int fdin; int fdin;
int fdout; int fdout;
}; };

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 16:56:11 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) void qstate_update(t_data *data, char c)
{ {
t_qstate *state; t_qstate *state;
t_qstate *new;
t_list **list; t_list **list;
t_list *tmp; t_list *tmp;
list = &data->qstack; list = &data->qstack;
state = (*list)->content; state = (*list)->content;
ft_lstadd(list, ft_lstnew(NULL, sizeof(t_qstate))); /* ft_printf("befor state: %i\n", *state); */
if (c == -1) if (c == -1)
{ {
tmp = ft_lstpop(list); tmp = ft_lstpop(list);
ft_lstdelone(&tmp, &ft_lst_cfree); ft_lstdelone(&tmp, &ft_lst_cfree);
return ; 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 == '\\') if (c == '\\')
*state = Q_BACKSLASH; *new = Q_BACKSLASH;
else if (c == '\"') else if (c == '\"')
*state = Q_DQUOTE; *new = Q_DQUOTE;
else if (c == '\'') else if (c == '\'')
*state = Q_QUOTE; *new = Q_QUOTE;
} }
else if (*state == Q_QUOTE) else if (*state == Q_QUOTE)
{ {
if (c == '\'') if (c == '\'')
*state = Q_NONE; *new = Q_NONE;
} }
else if (*state == Q_DQUOTE) else if (*state == Q_DQUOTE)
{ {
if (c == '\\') if (c == '\\')
*state = Q_BACKSLASH; *new = Q_BACKSLASH;
else if (c == '\"') else if (c == '\"')
*state = Q_NONE; *new = Q_NONE;
} }
else if (*state == Q_BACKSLASH) else if (*state == Q_BACKSLASH)
state = (*list)->next->next->content; *new = *(t_qstate*)(*list)->next->next->content;
*((t_qstate *)(*list)->content) = *state; /* ft_printf("new state: %i\n", *new); */
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:21 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:45:23 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:26 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:30 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) int ft_key_enter(t_data *data, char *buf)
{ {
(void)buf; (void)buf;
if (data->state_now == Q_NONE) if (*(t_qstate*)data->qstack->content == Q_NONE)
{ {
ft_putchar('\n'); ft_putchar('\n');
ft_history_add(data); ft_history_add(data);

View file

@ -20,8 +20,10 @@ int parse_separator(t_btree **ast, t_list **start, t_list **lst)
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
ft_parse(&(*ast)->right, &(*lst)->next); ft_parse(&(*ast)->right, &(*lst)->next);
node->type = token->type; node->type = token->type;
ft_lstdelone(lst, &token_free); ft_lstdelone(lst, &token_free);
ft_parse(&(*ast)->left, start); ft_parse(&(*ast)->left, start);
return (0); return (0);
} }