Merge branch 'master' into change_launch

This commit is contained in:
wescande 2017-03-17 20:45:56 +01:00
commit bb6436c67d
46 changed files with 331 additions and 307 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/16 23:02:12 by jhalford ### ########.fr #
# Updated: 2017/03/17 15:13:37 by gwojda ### ########.fr #
# #
# **************************************************************************** #
@ -291,6 +291,7 @@ parser/pop_stack.c\
parser/produce_sym.c\
parser/push_stack.c\
parser/read_stack.c\
parser/redir_init.c\
parser/stack_init.c\
parser/tree_wrapper.c

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
/* Updated: 2017/03/16 09:14:30 by alao ### ########.fr */
/* Updated: 2017/03/17 17:23:34 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
/* Updated: 2017/03/17 12:17:52 by gwojda ### ########.fr */
/* Updated: 2017/03/17 17:24:03 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -106,7 +106,7 @@ void ft_putall_current_str(char *str, size_t *pos);
void ft_current_str(char *str, size_t pos);
int ft_strlen_next(char *str, size_t pos);
void ft_push_back_history(
t_list_history **head, t_list_history *new);
t_list_history **head, t_list_history *new);
void ft_prompt(void);
char *ft_remove_imput(char *str, size_t pos);
char *ft_realloc_imput(char *str, int a, size_t pos);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/03/17 00:07:51 by ariard ### ########.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,
};
@ -92,7 +91,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);

View file

@ -60,14 +60,10 @@ struct s_errormatch
char *error;
};
/* extern t_aggrematch g_aggrematch[]; */
/* extern t_prodmatch g_prodmatch[]; */
/* extern t_stackmatch g_stackmatch[]; */
void parser_init(t_parser *parser);
void parser_destroy(t_parser *parser);
int stack_init(t_parser *parser);
int redir_init(t_type type, t_redir *redir);
int ft_parse(t_btree **ast, t_list **token, t_parser *parser);
int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/10 09:04:42 by alao #+# #+# */
/* Updated: 2017/03/16 10:19:54 by gwojda ### ########.fr */
/* Updated: 2017/03/17 18:12:31 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/10 11:37:43 by alao #+# #+# */
/* Updated: 2017/03/16 08:27:50 by alao ### ########.fr */
/* Updated: 2017/03/17 16:46:20 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 11:21:16 by alao #+# #+# */
/* Updated: 2017/03/16 08:30:52 by alao ### ########.fr */
/* Updated: 2017/03/17 16:51:46 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/16 22:17:10 by alao #+# #+# */
/* Updated: 2017/03/16 08:08:19 by alao ### ########.fr */
/* Updated: 2017/03/17 16:51:53 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 13:10:38 by alao #+# #+# */
/* Updated: 2017/03/16 08:48:05 by alao ### ########.fr */
/* Updated: 2017/03/17 16:48:49 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/11 10:44:40 by alao #+# #+# */
/* Updated: 2017/03/16 09:02:14 by alao ### ########.fr */
/* Updated: 2017/03/17 17:07:20 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,6 +34,22 @@ void c_term_clear(t_comp *c)
}
}
static size_t c_virtual_position(t_comp *c)
{
char *str;
size_t pos;
size_t virtual_pos;
pos = c->ircmd;
virtual_pos = pos;
str = data_singleton()->line.input;
while (pos && str[pos] != '\n')
--pos;
if (str[pos] == '\n')
++pos;
return (virtual_pos - pos);
}
/*
** Move the terminal up by the number of line needed and move it back up to
** the original position.
@ -58,7 +74,7 @@ void c_term_mv_back(t_comp *c)
ft_putstr(tgetstr("cr", NULL));
i = 0;
lcmd = 0;
c->rcmd ? lcmd += c->ircmd + c->prompt + 1 : 0;
c->rcmd ? lcmd += c_virtual_position(c) + c->prompt + 1 : 0;
while (i < lcmd)
{
ft_putstr(tgetstr("nd", NULL));

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */
/* Updated: 2017/03/17 12:09:42 by gwojda ### ########.fr */
/* Updated: 2017/03/17 16:05:47 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,9 +39,8 @@ int ft_history_down(char **str, size_t *pos)
head = head->next;
if (!head->str)
*str = NULL;
else
if (!(*str = ft_strdup(head->str)))
return (-1);
else if (!(*str = ft_strdup(head->str)))
return (-1);
if (*str)
ft_current_str(*str, *pos);
if (*str)
@ -64,9 +63,8 @@ int ft_history_up(char **str, size_t *pos)
head = head->prev;
if (!head->str)
*str = NULL;
else
if (!(*str = ft_strdup(head->str)))
return (-1);
else if (!(*str = ft_strdup(head->str)))
return (-1);
if (*str)
ft_current_str(*str, *pos);
if (*str)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
/* Updated: 2017/03/17 12:12:19 by gwojda ### ########.fr */
/* Updated: 2017/03/17 16:06:09 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -52,7 +52,7 @@ static void ft_give_new_prompt(char *str_srch, size_t srch_pos)
}
static void ft_modify_str(char *str_srch, size_t srch_pos, char **str,
size_t *pos)
size_t *pos)
{
ft_clear_prompt(pos, srch_pos);
data_singleton()->line.is_prompt ? ft_prompt() : ft_putstr("> ");

View file

@ -6,13 +6,12 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
/* Updated: 2017/03/16 14:41:00 by jhalford ### ########.fr */
/* Updated: 2017/03/17 20:19:59 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_rvwords g_rvwords[] =
{
{"while", TK_WHILE},
@ -30,54 +29,55 @@ t_rvwords g_rvwords[] =
{"null", 0},
};
static int recognization_rvwords(t_token *pv_tk)
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
|| 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))
return (1);
|| pv_tk->type == TK_DSEMI) || (pv_tk->type == TK_PAREN_CLOSE
&& at_tk->type == TK_PAREN_OPEN));
}
static int match_words(t_token *token)
{
int i;
if (token->type == TK_WORD)
{
i = 0;
while (g_rvwords[i].type)
{
if (ft_strcmp(token->data, g_rvwords[i].word) == 0)
token->type = g_rvwords[i].type;
i++;
}
}
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;
int i;
temp = *alst;
pv_tk = NULL;
ante_token = NULL;
while (temp)
{
token = temp->content;
//no more comp &
if (recognization_rvwords(pv_tk))
{
if (token->type == TK_WORD)
{
i = 0;
while (g_rvwords[i].type)
{
if (ft_strcmp(token->data, g_rvwords[i].word) == 0)
token->type = g_rvwords[i].type;
i++;
}
}
}
if (ante_token && (ante_token->type == TK_CASE || ante_token->type == TK_FOR)
if (recognization_rvwords(pv_tk, ante_token))
match_words(token);
if (ante_token && (ante_token->type == TK_CASE
|| ante_token->type == TK_FOR)
&& ft_strncmp(token->data, "in", 2) == 0)
token->type = TK_IN;
if (pv_tk && pv_tk->type == TK_FOR && token->type == TK_WORD)
token->type = TK_NAME;
ante_token = pv_tk;
ante_token = pv_tk;
pv_tk = token;
temp = temp->next;
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -1,37 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_assignement_word.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 20:28:13 by ariard #+# #+# */
/* Updated: 2017/03/14 00:50:34 by ariard ### ########.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));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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] == '`')
{

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */
/* Updated: 2017/03/16 22:59:52 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))
@ -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))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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,
};

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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++;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2017/03/16 14:44:46 by jhalford ### ########.fr */
/* Updated: 2017/03/17 20:17:23 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,20 +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));
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */
/* Updated: 2017/03/17 12:13:41 by gwojda ### ########.fr */
/* Updated: 2017/03/17 17:22:02 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -51,7 +51,7 @@ int ft_completion(int ret, char **str, size_t *pos)
ft_current_str(*str, tmp);
ft_get_next_str(*str, &tmp);
ft_putnc('\b', right);
*pos = ft_strleni_w(*str, pos_tmp, '\n') - right;
*pos = pos_tmp + ft_strleni_w(*str, pos_tmp, '\n') - right;
}
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */
/* Updated: 2017/03/17 12:20:31 by gwojda ### ########.fr */
/* Updated: 2017/03/17 12:32:16 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -41,6 +41,7 @@ int ft_control_d(char **str, size_t *pos)
int ft_control_c(char **str, size_t *pos)
{
set_exitstatus(1, 1);
if (*str)
ft_current_str(*str, *pos);
ft_strdel(str);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
/* Updated: 2017/03/17 12:15:58 by gwojda ### ########.fr */
/* Updated: 2017/03/17 15:54:45 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,52 +38,61 @@ t_key g_key[] =
{0 , 0 },
};
static void init_read_stdin(char **str, size_t *pos)
static void init_read_stdin(char ***str, size_t **pos)
{
if (*str)
*pos = &data_singleton()->line.pos;
*str = &data_singleton()->line.input;
if (**str)
{
ft_current_str(*str, *pos);
ft_get_next_str(*str, pos);
if ((*str)[*pos])
++(*pos);
ft_current_str(**str, **pos);
ft_get_next_str(**str, *pos);
if ((**str)[**pos])
++(**pos);
}
if (data_singleton()->comp)
c_clear(data_singleton());
signal(SIGWINCH, sigwinch_resize);
}
static int read_stdin(int *ret, int *j)
{
*j = 0;
*ret = 0;
if (read(0, ret, sizeof(int)) < 0)
return (-1);
return (1);
}
static int press_enter(char **input, char **str)
{
*input = *str;
return (0);
}
int ft_read_stdin(char **input)
{
int ret;
int j;
int ret;
int j;
char **str;
size_t *pos;
init_read_stdin(&data_singleton()->line.input, &data_singleton()->line.pos);
init_read_stdin(&str, &pos);
while (42)
{
ret = 0;
j = 0;
read(0, &ret, sizeof(int));
if (ft_completion(ret, &data_singleton()->line.input,
&data_singleton()->line.pos))
if (read_stdin(&ret, &j) < 0)
return (-1);
DG("key value hex = %x", ret);
if (ft_completion(ret, str, pos))
continue ;
while (g_key[j].value && g_key[j].value != ret)
++j;
if (g_key[j].value)
{
if ((ret = g_key[j].f(&data_singleton()->line.input,
&data_singleton()->line.pos)))
return (ret);
}
else if (ft_isprint(ret))
ft_print(ret, &data_singleton()->line.input,
&data_singleton()->line.pos);
else if (ret == 10)
{
*input = data_singleton()->line.input;
return (0);
}
else if (ft_isascii(ret) == 0)
ft_read_it(ret, &data_singleton()->line.pos,
&data_singleton()->line.input);
if (g_key[j].value && (ret = g_key[j].f(str, pos)))
return (ret);
else if (!g_key[j].value && ft_isprint(ret))
ft_print(ret, str, pos);
else if (!g_key[j].value && ret == 10)
return (press_enter(input, str));
else if (!g_key[j].value && ft_isascii(ret) == 0)
ft_read_it(ret, pos, str);
}
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */
/* Updated: 2017/03/17 13:52:05 by gwojda ### ########.fr */
/* Updated: 2017/03/17 16:01:44 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,6 +26,12 @@ static int ft_str_is_print(char *str)
return (1);
}
static void corrupt_history(int corrupt, char *home)
{
if (corrupt)
ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history\n", home);
}
void ft_init_history(void)
{
int fd;
@ -39,10 +45,7 @@ void ft_init_history(void)
return ;
path = ft_str3join(home, "/", ".42sh_history");
if ((fd = open(path, O_RDONLY)) < 0)
{
free(path);
return ;
}
return (free(path));
while (get_next_line(fd, &str) > 0)
{
if (ft_str_is_print(str) && *str)
@ -52,8 +55,7 @@ void ft_init_history(void)
corrupt = CORRUPT;
free(str);
}
if (corrupt)
ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history", home);
corrupt_history(corrupt, home);
free(path);
free(str);
close(fd);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/14 11:12:09 by gwojda #+# #+# */
/* Updated: 2017/03/17 11:49:18 by gwojda ### ########.fr */
/* Updated: 2017/03/17 12:33:43 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -74,8 +74,7 @@ int ft_found_prev_word(char **str, size_t *pos)
ft_puttermcaps("cd");
*pos -= 2;
ft_get_beggin(*str, pos);
if (!*pos && (*str)[*pos] == '\n')
++(*pos);
(!*pos && (*str)[*pos] == '\n') ? ++(*pos) : 0;
ft_current_str(*str, *pos);
ft_get_next_str(*str, pos);
++(*pos);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */
/* Updated: 2017/03/17 12:19:23 by gwojda ### ########.fr */
/* Updated: 2017/03/17 12:32:51 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -54,7 +54,7 @@ static void ft_suppr_2(char **str, size_t *i, size_t tmp)
ft_strdel(str);
}
int ft_suppr(char **str, size_t *pos)
int ft_suppr(char **str, size_t *pos)
{
size_t tmp;
char boolean;
@ -82,7 +82,7 @@ int ft_suppr(char **str, size_t *pos)
return (0);
}
int ft_del(char **str, size_t *pos)
int ft_del(char **str, size_t *pos)
{
size_t tmp;

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/17 12:20:12 by gwojda ### ########.fr */
/* Updated: 2017/03/17 16:10:40 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,8 @@ int readline(int has_prompt, char **input)
{
int ret;
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);
readline_init(has_prompt);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/16 23:25:46 by ariard ### ########.fr */
/* Updated: 2017/03/17 17:41:33 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,9 +27,13 @@ int data_init(int ac, char **av)
data->local_var = NULL;
builtin_setenv(NULL, (char *[]){"local", "IFS", "\n ", 0}, NULL);
set_exitstatus(0, 1);
shlvl = ft_itoa(ft_atoi(ft_getenv(data->env, "SHLVL")) + 1);
builtin_setenv(NULL, (char *[]){"setenv", "SHLVL", shlvl, 0}, NULL);
ft_strdel(&shlvl);
shlvl = ft_getenv(data->env, "SHLVL");
if (shlvl)
{
shlvl = ft_itoa(ft_atoi(shlvl) + 1);
builtin_setenv(NULL, (char *[]){"setenv", "SHLVL", shlvl, 0}, NULL);
ft_strdel(&shlvl);
}
data->comp = NULL;
data->opts = 0;
exec_reset();

View file

@ -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);
@ -90,6 +90,7 @@ static int handle_instruction()
return (ret);
if (do_lexer_routine(stream) > 0)
continue ;
token_print(data->token);
if (do_parser_routine() > 0)
break ;
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/03/15 16:46:16 by ariard ### ########.fr */
/* Updated: 2017/03/17 17:29:43 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -44,7 +44,7 @@ int superflous_token(t_btree **ast, t_list **lst)
return (0);
}
static int no_del_token(t_btree **ast, t_list **lst)
static int emblematic_token(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
@ -65,42 +65,43 @@ static int no_del_token(t_btree **ast, t_list **lst)
return (0);
}
int add_cmd(t_btree **ast, t_list **lst)
static int add_data_node(t_btree **ast, t_list **lst)
{
t_token *token;
t_astnode *node;
int i;
i = -1;
while (++i < 14)
{
if (g_distrostree[i].test(ast, lst) == 1)
{
DG("add to %d", i);
return (g_distrostree[i].add(ast, lst));
}
}
if (!*ast)
gen_node(ast);
else if (no_del_token(ast, lst))
return (add_cmd(&(*ast)->right, lst));
token = (*lst)->content;
node = (*ast)->item;
if (token->type == TK_IF)
add_if(ast, lst);
else if (token->type != TK_WORD && token->type != TK_NAME)
node->type = token->type;
else if (node->type != TK_CASE && node->type != TK_PAREN_OPEN && node->type != TK_FOR)
else if (node->type != TK_CASE && node->type != TK_PAREN_OPEN
&& node->type != TK_FOR)
node->type = CMD;
if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD || token->type == TK_NAME)
{
DG("type is %s", read_state(node->type));
DG("data is %s", token->data);
if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD
|| token->type == TK_NAME)
ft_ld_pushback(&node->data.cmd.token,
gen_tab(token->data, token->esc, token->esc2, 1));
}
if ((token->type == TK_WORD || token->type == TK_NAME)
if ((token->type == TK_WORD || token->type == TK_NAME)
&& (node->type == TK_CASE || node->type == TK_PAREN_OPEN))
node->pattern = 1;
return (0);
}
int add_cmd(t_btree **ast, t_list **lst)
{
int i;
i = -1;
while (++i < 14)
{
if (g_distrostree[i].test(ast, lst) == 1)
return (g_distrostree[i].add(ast, lst));
}
if (!*ast)
gen_node(ast);
else if (emblematic_token(ast, lst))
return (add_cmd(&(*ast)->right, lst));
return (add_data_node(ast, lst));
}

View file

@ -6,13 +6,13 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
/* Updated: 2017/03/15 20:07:38 by ariard ### ########.fr */
/* Updated: 2017/03/17 17:42:22 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int isfunc_name(t_btree **ast, t_list **lst)
int isfunc_name(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
@ -33,7 +33,7 @@ int isfunc_name(t_btree **ast, t_list **lst)
return (0);
}
int isfunc(t_btree **ast, t_list **lst)
int isfunc(t_btree **ast, t_list **lst)
{
t_astnode *node;
@ -52,7 +52,7 @@ int isfunc(t_btree **ast, t_list **lst)
return (0);
}
int add_func_cmd(t_btree **ast, t_list **lst)
int add_func_cmd(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
@ -86,7 +86,7 @@ t_list *is_already_func(t_btree **new)
t_btree **ast;
char **new_name;
char **old_name;
tmp = data_singleton()->lst_func;
new_name = token_to_argv(((t_astnode *)(*new)->item)->data.cmd.token, 1);
while (tmp)
@ -94,7 +94,8 @@ t_list *is_already_func(t_btree **new)
ast = tmp->content;
if (!*ast)
return (NULL);
old_name = token_to_argv(((t_astnode *)(*ast)->item)->data.cmd.token, 1);
old_name = token_to_argv(((t_astnode *)
(*ast)->item)->data.cmd.token, 1);
if (!new_name || !new_name[0] || !old_name || !old_name[0])
return (NULL);
if (!ft_strcmp(new_name[0], old_name[0]))
@ -104,7 +105,7 @@ t_list *is_already_func(t_btree **new)
return (NULL);
}
int add_one_func(t_btree **ast, t_list **lst)
int add_one_func(t_btree **ast, t_list **lst)
{
t_btree *func_ast;
t_list *old_func;
@ -112,7 +113,8 @@ int add_one_func(t_btree **ast, t_list **lst)
(void)lst;
func_ast = btree_map(*ast, node_copy);
if ((old_func = is_already_func(&func_ast)))
ft_lst_delif(&data_singleton()->lst_func, old_func->content, &ft_addrcmp, &ast_free);
ft_lst_delif(&data_singleton()->lst_func,
old_func->content, &ft_addrcmp, &ast_free);
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast)));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
/* Updated: 2017/03/15 01:59:52 by ariard ### ########.fr */
/* Updated: 2017/03/17 17:45:41 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,7 +27,7 @@ int isloop(t_btree **ast, t_list **lst)
return (1);
if (node->type == TK_FOR && (token->type == TK_WORD
|| token->type == TK_NAME) && node->pattern == 0)
return (0);
return (0);
if ((node->type == TK_NEWLINE || node->type == TK_SEMI
|| node->type == TK_AMP || node->type == TK_PIPE)
&& isloop(&(*ast)->right, lst) == 1)

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
/* Updated: 2017/03/16 18:34:10 by ariard ### ########.fr */
/* Updated: 2017/03/17 17:54:49 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -98,16 +98,6 @@ static int add_redir_type_number(t_btree **ast, t_list **lst)
return (0);
}
int redir_init(t_type type, t_redir *redir)
{
redir->n = (type == TK_LESS || type == TK_DLESS
|| type == TK_LESSAND) ? STDIN : STDOUT;
redir->type = type;
redir->heredoc_data = NULL;
redir->word = NULL;
return (0);
}
int add_redir_type(t_btree **ast, t_list **lst)
{
t_astnode *node;

View file

@ -6,16 +6,12 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 15:58:38 by ariard #+# #+# */
/* Updated: 2017/03/14 22:02:07 by ariard ### ########.fr */
/* Updated: 2017/03/17 18:23:50 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/*
* In case of grammar error, manange it
*/
t_aggrematch g_aggrematch[] =
{
{TK_WORD, CMD_SUFFIX, CMD_SUFFIX, 0},
@ -23,9 +19,9 @@ t_aggrematch g_aggrematch[] =
{TK_WORD, TK_IN, FOR_WORDLIST, TK_IN},
{TK_WORD, FOR_WORDLIST, FOR_WORDLIST, FOR_WORDLIST},
{TK_SEMI, FOR_WORDLIST, SEQUENTIAL_SEP, 0},
{TK_DSEMI, CMD_SUPERIOR, PIPE_SEQUENCE, CMD_SUPERIOR},
{TK_DSEMI, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE},
{TK_DSEMI, PIPE_CLOSE_SEQUENCE, PIPE_SEQUENCE, PIPE_CLOSE_SEQUENCE},
{TK_DSEMI, CMD_SUPERIOR, CLOSE_LIST, TK_PAREN_CLOSE},
{TK_DSEMI, PIPE_SEMI_SEQUENCE, CLOSE_LIST, TK_PAREN_CLOSE},
{TK_DSEMI, PIPE_CLOSE_SEQUENCE, CLOSE_LIST, TK_PAREN_CLOSE},
{TK_PAREN_OPEN, TK_IN, PATTERN_CASE, 0},
{TK_PAREN_OPEN, CASE_LIST_NS, PATTERN_CASE, 0},
{TK_PAREN_OPEN, CMD_SUPERIOR, OPEN_FUNC, 0},
@ -42,7 +38,6 @@ t_aggrematch g_aggrematch[] =
{TK_DONE, COMPOUND_LIST, DO_GROUP, TK_DO},
{TK_ESAC, TK_IN, CASE_CLAUSE, TK_CASE},
{TK_ESAC, CASE_LIST_NS, CASE_CLAUSE, TK_CASE},
{TK_RBRACE, COMPOUND_LIST, BRACE_GROUP, TK_LBRACE},
{TK_PAREN_CLOSE, COMPOUND_LIST, SUBSHELL, TK_PAREN_OPEN},
{TK_PAREN_CLOSE, CMD_SUPERIOR, SUBSHELL, TK_PAREN_OPEN},
{TK_PAREN_CLOSE, PIPE_SEMI_SEQUENCE, SUBSHELL, TK_PAREN_OPEN},
@ -56,11 +51,11 @@ t_aggrematch g_aggrematch[] =
{TK_RBRACE, COMPOUND_LIST, BRACE_CLAUSE, TK_LBRACE},
{TK_RBRACE, CMD_SUPERIOR, BRACE_CLAUSE, TK_LBRACE},
{TK_AND_IF, CMD_SUPERIOR, AND_OR_MINOR, CMD_SUPERIOR},
{TK_AND_IF, PIPE_CLOSE_SEQUENCE, AND_OR_MINOR, PIPE_CLOSE_SEQUENCE},
{TK_AND_IF, PIPE_CLOSE_SEQUENCE, AND_OR_MINOR, PIPE_CLOSE_SEQUENCE},
{TK_AND_IF, PIPE_SEMI_SEQUENCE, AND_OR_MINOR, PIPE_SEMI_SEQUENCE},
{TK_OR_IF, PIPE_SEMI_SEQUENCE, AND_OR_MINOR, PIPE_SEMI_SEQUENCE},
{TK_OR_IF, CMD_SUPERIOR, AND_OR_MINOR, CMD_SUPERIOR},
{TK_OR_IF, PIPE_CLOSE_SEQUENCE, AND_OR_MINOR, PIPE_CLOSE_SEQUENCE},
{TK_OR_IF, PIPE_CLOSE_SEQUENCE, AND_OR_MINOR, PIPE_CLOSE_SEQUENCE},
{SEPARATOR_OP, CMD_SUPERIOR, SEPARATOR, 0},
{SEPARATOR_OP, COMPOUND_LIST, SEPARATOR, 0},
{SEPARATOR_OP, CASE_LIST_NS, SEPARATOR, 0},
@ -100,7 +95,9 @@ t_aggrematch g_aggrematch[] =
{NEWLINE_LIST, NAME, SEQUENTIAL_SEP, 0},
{NEWLINE_LIST, IN, SEQUENTIAL_SEP, 0},
{NEWLINE_LIST, TERM, SEPARATOR, 0},
{NEWLINE_LIST, SEQUENCE, SEQUENCE, SEQUENCE},
{NEWLINE_LIST, COMPOUND_LIST, SEPARATOR, 0},
{NEWLINE_LIST, FUNC_NAME, FUNC_NAME, FUNC_NAME},
{NEWLINE_LIST, CASE_LIST_NS, SEPARATOR, 0},
{NEWLINE_LIST, COMPLETE_CONDITION, COMPLETE_CONDITION, COMPLETE_CONDITION},
{NEWLINE_LIST, CONDITION, CONDITION, CONDITION},
@ -226,7 +223,6 @@ t_aggrematch g_aggrematch[] =
{SUBSHELL, ALL, COMPOUND_COMMAND, 0},
{BRACE_CLAUSE, ALL, COMPOUND_COMMAND, 0},
{COMPOUND_COMMAND, FUNC_NAME, COMMAND, FUNC_NAME},
// {COMPOUND_COMMAND, ALL, COMMAND, 0},
{AND_OR_MINOR, PIPE_SEMI_SEQUENCE, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE},
{AND_OR_MINOR, PIPE_CLOSE_SEQUENCE, AND_OR_MAJOR, PIPE_CLOSE_SEQUENCE},
{AND_OR_MINOR, LINEBREAK, AND_OR_MAJOR, 0},
@ -381,32 +377,35 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state)
if (!*stack || !*new_sym || !*state)
return (1);
i = 0;
i = -1;
head = (*stack)->content;
// DG("aggregate head %s && sym %s",
// read_state(*head), read_state(*new_sym));
while (g_aggrematch[i].top)
{
while (g_aggrematch[++i].top)
if (*new_sym == g_aggrematch[i].top
&& MATCH_STACK(*head, g_aggrematch[i].under))
{
// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym));
*new_sym = g_aggrematch[i].new_sym;
if (g_aggrematch[i].erase_sym)
{
pop_stack(stack, g_aggrematch[i].erase_sym);
head = (*stack)->content;
// DG("stack after pop: %s", read_state(*head));
}
if (eval_sym(stack, *new_sym))
{
*state = ERROR;
if (eval_sym(stack, *new_sym) && !(*state = ERROR))
return (1);
}
aggregate_sym(stack, new_sym, state);
return (0);
}
i++;
}
return (0);
}
/*
** DG("aggregate head %s && sym %s",
** read_state(*head), read_state(*new_sym));
*/
/*
** DG("MATCH : %s", read_state(g_aggrematch[i].new_sym));
*/
/*
** DG("stack after pop: %s", read_state(*head));
*/

View file

@ -6,12 +6,15 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:15:35 by ariard #+# #+# */
/* Updated: 2017/03/16 23:24:01 by ariard ### ########.fr */
/* Updated: 2017/03/17 18:08:11 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#define SYNTERR_0 "{red}syntax error near unexpected token `%s'{eoc}\n"
#define SYNTERR_1 "{red}syntax error near unexpected EOF{eoc}"
static t_errormatch g_errormatch[] =
{
{TK_NEWLINE, "newline"},
@ -64,18 +67,18 @@ int error_syntax(t_list **lst)
{
if (g_errormatch[i].token == token->type)
{
ft_dprintf(2, "{red}syntax error near unexpected token « %s »{eoc}\n",
g_errormatch[i].error);
ft_dprintf(2, SYNTERR_0, g_errormatch[i].error);
return (0);
}
i++;
}
ft_dprintf(2, "{red}syntax error near unexpected token « %s »\n{eoc}", token->data);
ft_dprintf(2, SYNTERR_0,
token->data);
return (0);
}
int error_eof(void)
{
ft_dprintf(2, "{red}syntax error near unexpected EOF{eoc}");
ft_dprintf(2, SYNTERR_1);
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:11:21 by ariard #+# #+# */
/* Updated: 2017/03/16 21:24:10 by ariard ### ########.fr */
/* Updated: 2017/03/17 18:12:41 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -255,6 +255,7 @@ t_stackmatch g_stackmatch[] =
{TK_IF, TK_BANG},
{TK_IF, TK_PAREN_OPEN},
{TK_IF, TK_LBRACE},
{TK_IF, FUNC_NAME},
{TK_IF, COMPLETE_COMMANDS},
{TK_IF, SEPARATOR_OP},
{TK_IF, NEWLINE_LIST},
@ -297,6 +298,7 @@ t_stackmatch g_stackmatch[] =
{TK_CASE, TK_BANG},
{TK_CASE, TK_PAREN_OPEN},
{TK_CASE, TK_LBRACE},
{TK_CASE, FUNC_NAME},
{TK_CASE, COMPLETE_COMMANDS},
{TK_CASE, TK_DO},
{TK_CASE, TK_THEN},
@ -322,6 +324,7 @@ t_stackmatch g_stackmatch[] =
{TK_WHILE, LINEBREAK},
{TK_WHILE, TK_PAREN_OPEN},
{TK_WHILE, TK_LBRACE},
{TK_WHILE, FUNC_NAME},
{TK_WHILE, COMPLETE_COMMANDS},
{TK_WHILE, TK_BANG},
{TK_WHILE, SEPARATOR_OP},
@ -343,6 +346,7 @@ t_stackmatch g_stackmatch[] =
{TK_UNTIL, LINEBREAK},
{TK_UNTIL, TK_PAREN_OPEN},
{TK_UNTIL, TK_LBRACE},
{TK_UNTIL, FUNC_NAME},
{TK_UNTIL, COMPLETE_COMMANDS},
{TK_UNTIL, TK_BANG},
{TK_UNTIL, SEPARATOR_OP},
@ -361,10 +365,33 @@ t_stackmatch g_stackmatch[] =
{TK_UNTIL, TK_PAREN_CLOSE},
{TK_UNTIL, COMPLETE_CONDITION},
{TK_UNTIL, CONDITION},
{FUNC_NAME, LINEBREAK},
{FUNC_NAME, TK_BANG},
{FUNC_NAME, TK_PAREN_OPEN},
{FUNC_NAME, TK_LBRACE},
{FUNC_NAME, FUNC_NAME},
{FUNC_NAME, COMPLETE_COMMANDS},
{FUNC_NAME, SEPARATOR_OP},
{FUNC_NAME, NEWLINE_LIST},
{FUNC_NAME, SEQUENCE},
{FUNC_NAME, TK_WHILE},
{FUNC_NAME, FUNC_NAME},
{FUNC_NAME, TK_UNTIL},
{FUNC_NAME, FUNC_NAME},
{FUNC_NAME, TK_DO},
{FUNC_NAME, TK_ELIF},
{FUNC_NAME, TK_ELSE},
{FUNC_NAME, TK_THEN},
{FUNC_NAME, TK_PAREN_CLOSE},
{FUNC_NAME, COMPLETE_CONDITION},
{FUNC_NAME, CONDITION},
{FUNC_NAME, COMPOUND_LIST},
{FUNC_NAME, CASE_LIST_NS},
{TK_FOR, LINEBREAK},
{TK_FOR, TK_BANG},
{TK_FOR, TK_PAREN_OPEN},
{TK_FOR, TK_LBRACE},
{TK_FOR, FUNC_NAME},
{TK_FOR, COMPLETE_COMMANDS},
{TK_FOR, SEPARATOR_OP},
{TK_FOR, NEWLINE_LIST},
@ -395,7 +422,6 @@ t_stackmatch g_stackmatch[] =
{TK_LBRACE, TK_UNTIL},
{TK_LBRACE, TK_DO},
{TK_LBRACE, TK_PAREN_CLOSE},
{TK_LBRACE, TK_LBRACE},
{TK_LBRACE, TK_IF},
{TK_LBRACE, TK_ELIF},
{TK_LBRACE, TK_THEN},
@ -599,6 +625,7 @@ t_stackmatch g_stackmatch[] =
{NEWLINE_LIST, TK_PAREN_OPEN},
{NEWLINE_LIST, TK_LBRACE},
{NEWLINE_LIST, PROGRAM},
{NEWLINE_LIST, SEQUENCE},
{HERE_END, TK_DLESS},
{HERE_END, TK_DLESS},
{HERE_END, TK_DLESSDASH},
@ -813,14 +840,6 @@ t_stackmatch g_stackmatch[] =
{COMPLETE_CONDITION, COMPLETE_COMMANDS},
{COMPLETE_CONDITION, COMPLETE_CONDITION},
{COMPLETE_CONDITION, SEQUENCE},
{BRACE_GROUP, LINEBREAK},
{BRACE_GROUP, TK_PAREN_OPEN},
{BRACE_GROUP, TK_LBRACE},
{BRACE_GROUP, COMPLETE_COMMANDS},
{BRACE_GROUP, TK_BANG},
{BRACE_GROUP, SEPARATOR_OP},
{BRACE_GROUP, NEWLINE_LIST},
{BRACE_GROUP, SEQUENCE},
{FNAME, LINEBREAK},
{FNAME, TK_PAREN_OPEN},
{FNAME, TK_LBRACE},
@ -833,6 +852,7 @@ t_stackmatch g_stackmatch[] =
{FUNCTION_DEFINITION, LINEBREAK},
{FUNCTION_DEFINITION, TK_PAREN_OPEN},
{FUNCTION_DEFINITION, TK_LBRACE},
{FUNCTION_DEFINITION, FUNC_NAME},
{FUNCTION_DEFINITION, COMPLETE_COMMANDS},
{FUNCTION_DEFINITION, TK_BANG},
{FUNCTION_DEFINITION, SEPARATOR_OP},
@ -841,6 +861,7 @@ t_stackmatch g_stackmatch[] =
{UNTIL_CLAUSE, LINEBREAK},
{UNTIL_CLAUSE, TK_PAREN_OPEN},
{UNTIL_CLAUSE, TK_LBRACE},
{UNTIL_CLAUSE, FUNC_NAME},
{UNTIL_CLAUSE, COMPLETE_COMMANDS},
{UNTIL_CLAUSE, TK_BANG},
{UNTIL_CLAUSE, SEPARATOR_OP},
@ -885,6 +906,7 @@ t_stackmatch g_stackmatch[] =
{IF_CLAUSE, TK_BANG},
{IF_CLAUSE, TK_PAREN_OPEN},
{IF_CLAUSE, TK_LBRACE},
{IF_CLAUSE, FUNC_NAME},
{IF_CLAUSE, COMPLETE_COMMANDS},
{IF_CLAUSE, SEPARATOR_OP},
{IF_CLAUSE, NEWLINE_LIST},
@ -907,6 +929,7 @@ t_stackmatch g_stackmatch[] =
{BRACE_CLAUSE, LINEBREAK},
{BRACE_CLAUSE, TK_PAREN_OPEN},
{BRACE_CLAUSE, TK_LBRACE},
{BRACE_CLAUSE, FUNC_NAME},
{BRACE_CLAUSE, COMPLETE_COMMANDS},
{BRACE_CLAUSE, TK_BANG},
{BRACE_CLAUSE, SEPARATOR_OP},
@ -936,6 +959,7 @@ t_stackmatch g_stackmatch[] =
{CASE_CLAUSE, TK_BANG},
{CASE_CLAUSE, TK_PAREN_OPEN},
{CASE_CLAUSE, TK_LBRACE},
{CASE_CLAUSE, FUNC_NAME},
{CASE_CLAUSE, COMPLETE_COMMANDS},
{CASE_CLAUSE, SEPARATOR_OP},
{CASE_CLAUSE, NEWLINE_LIST},
@ -963,6 +987,7 @@ t_stackmatch g_stackmatch[] =
{FOR_CLAUSE, TK_BANG},
{FOR_CLAUSE, TK_PAREN_OPEN},
{FOR_CLAUSE, TK_LBRACE},
{FOR_CLAUSE, FUNC_NAME},
{FOR_CLAUSE, COMPLETE_COMMANDS},
{FOR_CLAUSE, SEPARATOR_OP},
{FOR_CLAUSE, NEWLINE_LIST},
@ -1004,6 +1029,7 @@ t_stackmatch g_stackmatch[] =
{SUBSHELL, NEWLINE_LIST},
{SUBSHELL, SEQUENCE},
{SUBSHELL, TK_LBRACE},
{SUBSHELL, TK_PAREN_OPEN},
{SUBSHELL, SEPARATOR_OP},
{SUBSHELL, NEWLINE_LIST},
{SUBSHELL, TK_DO},
@ -1243,7 +1269,6 @@ int eval_sym(t_list **stack, t_sym new_sym)
if (!*stack)
return (1);
head = (*stack)->content;
DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
i = 0;
while (g_stackmatch[i].top)
{
@ -1253,3 +1278,7 @@ int eval_sym(t_list **stack, t_sym new_sym)
}
return (1);
}
/*
** DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
*/

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */
/* Updated: 2017/03/16 22:11:41 by ariard ### ########.fr */
/* Updated: 2017/03/17 18:00:34 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,22 +40,16 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
while (*token)
{
produce_sym(&parser->stack, parser->new_sym, token);
DG("new sym %s", read_state(*parser->new_sym));
if (eval_sym(&parser->stack, *parser->new_sym))
return ((parser->state = ERROR));
else
{
if (aggregate_sym(&parser->stack, parser->new_sym, &parser->state))
return (0);
push_stack(&parser->stack, *parser->new_sym);
}
// ft_read_stack(parser->stack);
if (aggregate_sym(&parser->stack, parser->new_sym, &parser->state))
return (0);
push_stack(&parser->stack, *parser->new_sym);
if (*(head = (parser->stack)->content) == PROGRAM)
parser->state = SUCCESS;
else
parser->state = UNDEFINED;
build_tree(ast, token);
/* btree_print(STDBUG, *ast, &ft_putast); */
if ((end_instruction(&parser->stack) && !(*token)->next))
insert_linebreak(token);
else

View file

@ -6,41 +6,42 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
/* Updated: 2017/03/16 17:51:54 by ariard ### ########.fr */
/* Updated: 2017/03/17 18:42:58 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int pop_heredoc(t_list **lst)
static char *join_heredoc_data(char *old_data, char *token_data)
{
char *del;
char *new;
del = old_data;
new = ft_str3join(old_data, token_data, "\n");
ft_strdel(&del);
return (new);
}
int pop_heredoc(t_list **lst)
{
t_token *token;
t_list **head;
t_redir *redir;
char *tmp;
token = (*lst)->content;
if (token->type == HEREDOCDATA && data_singleton()->parser.heredoc_queue != NULL)
if (token->type == HEREDOCDATA
&& data_singleton()->parser.heredoc_queue != NULL)
{
head = &data_singleton()->parser.heredoc_queue;
if (!(head = &data_singleton()->parser.heredoc_queue))
return (0);
redir = *(t_redir**)(*head)->content;
if (head && token)
{
/* DG("comparing w/ input [%s], head @ %p", token->data, *head); */
/* DG("redir1 @ %p word=[%s]", redir, redir->word); */
if (ft_strcmp((char *)token->data, redir->word) == 0)
{
ft_lst_delif(head, (t_redir**)(*head)->content, ft_addrcmp, ft_lst_cfree);
/* DG("matched heredoc EOF, new head @ %p", *head); */
}
else
{
tmp = redir->heredoc_data;
redir->heredoc_data = ft_str3join(redir->heredoc_data,
(char*)token->data, "\n");
ft_strdel(&tmp);
}
}
if (ft_strcmp((char *)token->data, redir->word) == 0)
ft_lst_delif(head, (t_redir**)(*head)->content,
ft_addrcmp, ft_lst_cfree);
else
redir->heredoc_data = join_heredoc_data(redir->heredoc_data,
(char*)token->data);
ft_lstdel(lst, &token_free);
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/16 19:30:17 by ariard #+# #+# */
/* Updated: 2017/03/16 23:21:28 by ariard ### ########.fr */
/* Updated: 2017/03/17 17:55:38 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,9 +14,9 @@
void parser_destroy(t_parser *parser)
{
parser->state = SUCCESS;
parser->state = SUCCESS;
ft_lstdel(&parser->stack, &ft_lst_cfree);
ft_lstdel(&data_singleton()->parser.heredoc_queue, &ft_lst_cfree);
free(parser->new_sym);
parser->new_sym = NULL;
parser->new_sym = NULL;
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
/* Updated: 2017/03/16 21:31:55 by ariard ### ########.fr */
/* Updated: 2017/03/17 18:09:37 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -62,9 +62,10 @@ t_prodmatch g_prodmatch[] =
{TK_ASSIGNMENT_WORD, SEPARATOR_OP, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, TK_WHILE, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, TK_UNTIL, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, TK_DO, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, TK_FOR, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, TK_IF, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, TK_FI, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, TK_THEN, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, TK_ELIF, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, TK_ELSE, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, NEWLINE_LIST, CMD_PREFIX},
@ -93,6 +94,7 @@ t_prodmatch g_prodmatch[] =
{TK_NEWLINE, TK_ELIF, NEWLINE_LIST},
{TK_NEWLINE, TK_ELSE, NEWLINE_LIST},
{TK_NEWLINE, TK_THEN, NEWLINE_LIST},
{TK_NEWLINE, FUNC_NAME, NEWLINE_LIST},
{TK_NEWLINE, CMD_NAME, NEWLINE_LIST},
{TK_NEWLINE, COMPLETE_COMMANDS, NEWLINE_LIST},
{TK_NEWLINE, LINEBREAK, NEWLINE_LIST},
@ -102,7 +104,7 @@ t_prodmatch g_prodmatch[] =
{TK_NEWLINE, CMD_SUPERIOR, LINEBREAK},
{TK_NEWLINE, PIPE_SEMI_SEQUENCE, LINEBREAK},
{TK_NEWLINE, PIPE_CLOSE_SEQUENCE, LINEBREAK},
{TK_NEWLINE, SEQUENCE, LINEBREAK},
{TK_NEWLINE, SEQUENCE, NEWLINE_LIST},
{TK_NEWLINE, CASE_LIST_NS, NEWLINE_LIST},
{TK_NEWLINE, COMPOUND_LIST, NEWLINE_LIST},
{TK_NEWLINE, COMPLETE_CONDITION, NEWLINE_LIST},
@ -127,24 +129,17 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst)
t_sym *head;
int i;
if (!*stack)
DG("stack absente");
if (!*stack || !*lst)
return (1);
token = (*lst)->content;
head = (*stack)->content;
DG("produce stack : %s && token : %s", read_state(*head),
read_state(token->type));
i = 0;
*new_sym = 0;
while (g_prodmatch[i].new_sym)
{
if (token->type == g_prodmatch[i].token
&& *head == g_prodmatch[i].stack)
{
// DG("MATCH : %s", read_state(g_prodmatch[i].new_sym));
*new_sym = g_prodmatch[i].new_sym;
}
i++;
}
if (!*new_sym)

View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redir_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/17 17:46:50 by ariard #+# #+# */
/* Updated: 2017/03/17 17:49:10 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int redir_init(t_type type, t_redir *redir)
{
redir->n = (type == TK_LESS || type == TK_DLESS
|| type == TK_LESSAND) ? STDIN : STDOUT;
redir->type = type;
redir->heredoc_data = NULL;
redir->word = NULL;
return (0);
}

View file

@ -6,13 +6,13 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/16 20:31:32 by ariard #+# #+# */
/* Updated: 2017/03/16 22:11:59 by ariard ### ########.fr */
/* Updated: 2017/03/17 18:24:46 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int stack_init(t_parser *parser)
int stack_init(t_parser *parser)
{
ft_lstdel(&parser->stack, NULL);
push_stack(&parser->stack, TERMINUS);