modifs math

This commit is contained in:
Antoine Riard 2017-03-17 23:21:25 +01:00
commit 50971a7e23
23 changed files with 84 additions and 127 deletions

View file

@ -214,7 +214,6 @@ lexer/get_reserved_words.c\
lexer/get_state_global.c\ lexer/get_state_global.c\
lexer/get_state_redir.c\ lexer/get_state_redir.c\
lexer/insert_newline.c\ lexer/insert_newline.c\
lexer/lexer_assignement_word.c\
lexer/lexer_backslash.c\ lexer/lexer_backslash.c\
lexer/lexer_bquote.c\ lexer/lexer_bquote.c\
lexer/lexer_curly_braces.c\ lexer/lexer_curly_braces.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 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 20:19:18 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,7 +36,6 @@ enum e_lexstate
BQUOTE, BQUOTE,
BACKSLASH, BACKSLASH,
CURLY_BRACKETS, CURLY_BRACKETS,
ASSIGNEMENT_WORD,
END, END,
}; };
@ -92,7 +91,7 @@ char *stack_to_prompt(t_list *stack);
t_lexstate get_state_global(t_lexer *lexer); t_lexstate get_state_global(t_lexer *lexer);
t_lexstate get_state_redir(t_lexer *lexer); t_lexstate get_state_redir(t_lexer *lexer);
int get_lexer_stack(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); int insert_newline(t_list **alst);
void lexer_init(t_lexer *lexer); void lexer_init(t_lexer *lexer);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/03/17 18:56:44 by ariard ### ########.fr */ /* Updated: 2017/03/17 23:20:13 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,12 +41,11 @@
struct s_data struct s_data
{ {
t_flag opts; t_flag opts;
int fd;
char **env; char **env;
int argc; int argc;
char **argv; char **argv;
t_line line; t_line line;
t_list *token;
t_btree *ast;
t_lexer lexer; t_lexer lexer;
t_parser parser; t_parser parser;
t_comp *comp; t_comp *comp;

View file

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

View file

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

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
/* Updated: 2017/03/17 18:56:00 by ariard ### ########.fr */ /* Updated: 2017/03/17 23:19:52 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 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_STATE_MASK;
p->attrs |= PROCESS_COMPLETED; p->attrs |= PROCESS_COMPLETED;
if (WIFSIGNALED(status) && DEBUG_MODE) if (WIFSIGNALED(status))
ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", psignal(WTERMSIG(status), NULL);
(int)pid, WTERMSIG(status)); /* ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", */
/* (int)pid, WTERMSIG(status)); */
} }
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:05:55 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) static void process_format_state(t_process *p)
{ {
int state; int state;
char *statestr;
state = p->attrs & PROCESS_STATE_MASK; state = p->attrs & PROCESS_STATE_MASK;
statestr = NULL;
if (state == PROCESS_RUNNING) if (state == PROCESS_RUNNING)
ft_putstr("running "); ft_asprintf(&statestr, "running");
else if (state == PROCESS_SUSPENDED) else if (state == PROCESS_SUSPENDED)
ft_putstr("suspended"); ft_asprintf(&statestr, "suspended");
else if (state == PROCESS_CONTINUED) else if (state == PROCESS_CONTINUED)
{ {
ft_putstr("continued"); ft_asprintf(&statestr, "continued");
p->attrs &= ~PROCESS_STATE_MASK; p->attrs &= ~PROCESS_STATE_MASK;
p->attrs |= PROCESS_RUNNING; p->attrs |= PROCESS_RUNNING;
} }
else if (state == PROCESS_COMPLETED) else if (state == PROCESS_COMPLETED)
{ {
if (p->status == 0) if (WIFSIGNALED(p->status))
ft_putstr("done "); ft_asprintf(&statestr, strsignal(WTERMSIG(p->status)));
else if (p->status == 0)
ft_asprintf(&statestr, "done");
else 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) static void process_format_com_long(t_list **plist)

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:07:05 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 20:19:59 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,16 +31,14 @@ t_rvwords g_rvwords[] =
static int recognization_rvwords(t_token *pv_tk, t_token *at_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_SEMI || pv_tk->type == TK_PIPE
|| pv_tk->type == TK_WHILE || pv_tk->type == TK_DONE || pv_tk->type == TK_WHILE || pv_tk->type == TK_DONE
|| pv_tk->type == TK_DO || pv_tk->type == TK_IF || pv_tk->type == TK_DO || pv_tk->type == TK_IF
|| pv_tk->type == TK_FI || pv_tk->type == TK_THEN || pv_tk->type == TK_FI || pv_tk->type == TK_THEN
|| pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE || pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE
|| pv_tk->type == TK_DSEMI) || (pv_tk->type == TK_PAREN_CLOSE || pv_tk->type == TK_DSEMI) || (pv_tk->type == TK_PAREN_CLOSE
&& at_tk->type == TK_PAREN_OPEN)) && at_tk->type == TK_PAREN_OPEN));
return (1);
return (0);
} }
static int match_words(t_token *token) static int match_words(t_token *token)
@ -60,14 +58,12 @@ static int match_words(t_token *token)
return (0); return (0);
} }
int get_reserved_words(t_list **alst) int get_reserved_words(t_list *temp)
{ {
t_token *token; t_token *token;
t_token *pv_tk; t_token *pv_tk;
t_token *ante_token; t_token *ante_token;
t_list *temp;
temp = *alst;
pv_tk = NULL; pv_tk = NULL;
ante_token = NULL; ante_token = NULL;
while (temp) while (temp)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:39:06 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

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> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:56:49 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 21:01:45 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ int lexer_backslash(t_list **alst, t_lexer *lexer)
t_token *token; t_token *token;
token = (*alst)->content; token = (*alst)->content;
token->type = TK_WORD; token->type = token->type ? token->type : TK_WORD;
lexer->pos++; lexer->pos++;
lexer->state = WORD; lexer->state = WORD;
if (lexer->str[lexer->pos] == 0) if (lexer->str[lexer->pos] == 0)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 22:03:48 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 21:01:50 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@ int lexer_bquote(t_list **alst, t_lexer *lexer)
int back; int back;
token = (*alst)->content; token = (*alst)->content;
token->type = TK_WORD; token->type = token->type ? token->type : TK_WORD;
back = 0; back = 0;
if (lexer->str[lexer->pos] == '`') if (lexer->str[lexer->pos] == '`')
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:21 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]; c = lexer->str[lexer->pos];
if ((lexer->state = get_state_global(lexer))) if ((lexer->state = get_state_global(lexer)))
{
DG("got state %i",lexer->state);
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
}
if ((lexer->state = get_state_redir(lexer))) if ((lexer->state = get_state_redir(lexer)))
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));
DG("no special state, %c",lexer->str[lexer->pos]);
lexer->state = ft_isdigit(c) ? NUMBER : WORD; lexer->state = ft_isdigit(c) ? NUMBER : WORD;
token = (*alst)->content; token = (*alst)->content;
token->type = TK_WORD; token->type = TK_WORD;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:58 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 20:08:02 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ int lexer_dquote(t_list **alst, t_lexer *lexer)
t_token *token; t_token *token;
token = (*alst)->content; token = (*alst)->content;
token->type = TK_WORD; token->type = token->type ? token->type : TK_WORD;
if (lexer->str[lexer->pos] == '"') if (lexer->str[lexer->pos] == '"')
{ {
if (get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD)) 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] == '\\') else if (lexer->str[lexer->pos] == '\\')
{ {
if (lexer->str[lexer->pos + 1] == 0) if (lexer->str[lexer->pos + 1] == 0)
return(lexer_backslash(alst, lexer)); return (lexer_backslash(alst, lexer));
token_append(token, lexer, 1, 1); token_append(token, lexer, 1, 1);
} }
else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE)) else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:08:51 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_bquote,
&lexer_backslash, &lexer_backslash,
&lexer_curly_braces, &lexer_curly_braces,
&lexer_assignement_word,
&lexer_end, &lexer_end,
}; };

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:08 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; t_token *token;
token = (*alst)->content; token = (*alst)->content;
token->type = TK_WORD; token->type = token->type ? token->type : TK_WORD;
if (lexer->str[lexer->pos] == '\'') if (lexer->str[lexer->pos] == '\'')
{ {
lexer->pos++; lexer->pos++;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 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 20:17:23 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,20 +18,21 @@ int lexer_word(t_list **alst, t_lexer *lexer)
t_lexstate state; t_lexstate state;
token = (*alst)->content; token = (*alst)->content;
token->type = TK_WORD; token->type = token->type ? token->type : TK_WORD;
if ((state = get_state_global(lexer)) if ((state = get_state_global(lexer))
|| (state = get_state_redir(lexer))) || (state = get_state_redir(lexer)))
{
lexer->state = state; lexer->state = state;
return (lexer_lex(alst, lexer)); else if (lexer->str[lexer->pos] == '='
}
if (lexer->str[lexer->pos] == '='
&& word_is_assignment((char *[]){token->data, (char *)token->esc})) && word_is_assignment((char *[]){token->data, (char *)token->esc}))
{ {
lexer->state = ASSIGNEMENT_WORD; token->type = TK_ASSIGNMENT_WORD;
return (lexer_lex(alst, lexer)); 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)); return (lexer_lex(alst, lexer));
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */ /* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
/* Updated: 2017/03/17 20:04:42 by ariard ### ########.fr */ /* Updated: 2017/03/17 23:21:04 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -82,8 +82,8 @@ int ft_read_stdin(char **input)
if (read_stdin(&ret, &j) < 0) if (read_stdin(&ret, &j) < 0)
return (-1); return (-1);
DG("key value hex = %x", ret); DG("key value hex = %x", ret);
// if (ft_completion(ret, str, pos)) if (ft_completion(ret, str, pos))
// continue ; continue ;
while (g_key[j].value && g_key[j].value != ret) while (g_key[j].value && g_key[j].value != ret)
++j; ++j;
if (g_key[j].value && (ret = g_key[j].f(str, pos))) if (g_key[j].value && (ret = g_key[j].f(str, pos)))

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/17 20:02:57 by ariard ### ########.fr */ /* Updated: 2017/03/17 23:19:22 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,7 @@ int readline(int has_prompt, char **input)
if (!has_prompt) if (!has_prompt)
data_singleton()->line.prompt_size = 1; data_singleton()->line.prompt_size = 1;
if (!SH_IS_INTERACTIVE(data_singleton()->opts)) 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); readline_init(has_prompt);
ret = ft_read_stdin(input); ret = ft_read_stdin(input);
if (ret < 0) if (ret < 0)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 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 21:18:44 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@ int data_init(int ac, char **av)
{ {
t_data *data; t_data *data;
char *term_name; char *term_name;
char* shlvl; char *shlvl;
data = data_singleton(); data = data_singleton();
data->argc = ac; data->argc = ac;
@ -38,8 +38,6 @@ int data_init(int ac, char **av)
data->opts = 0; data->opts = 0;
exec_reset(); exec_reset();
data->lst_func = NULL; data->lst_func = NULL;
data->token = NULL;
data->ast = NULL;
lexer_init(&data->lexer); lexer_init(&data->lexer);
parser_init(&data->parser); parser_init(&data->parser);
if ((term_name = ft_getenv(data->env, "TERM")) == NULL) if ((term_name = ft_getenv(data->env, "TERM")) == NULL)

View file

@ -28,7 +28,7 @@ static int do_readline_routine(char **stream)
return (ret); return (ret);
} }
static int do_lexer_routine(char *stream) static int do_lexer_routine(t_list **token, char *stream)
{ {
t_list *ltoken; t_list *ltoken;
t_data *data; t_data *data;
@ -42,8 +42,8 @@ static int do_lexer_routine(char *stream)
ft_strappend(&data->lexer.str, stream); ft_strappend(&data->lexer.str, stream);
if (get_lexer_stack(data->lexer) == BACKSLASH) if (get_lexer_stack(data->lexer) == BACKSLASH)
pop(&data->lexer.stack); pop(&data->lexer.stack);
ltoken = ft_lstlast(data->token); ltoken = ft_lstlast(*token);
if (lexer_lex(data->token ? &ltoken : &data->token, &data->lexer) < 0) if (lexer_lex(*token ? &ltoken : token, &data->lexer) < 0)
exit(1); exit(1);
if (get_lexer_stack(data->lexer) > 2) if (get_lexer_stack(data->lexer) > 2)
return (1); return (1);
@ -51,24 +51,24 @@ static int do_lexer_routine(char *stream)
return (0); return (0);
} }
static int do_parser_routine(void) static int do_parser_routine(t_list **token, t_btree **ast)
{ {
t_data *data; t_data *data;
data = data_singleton(); data = data_singleton();
if (get_reserved_words(&data->token)) if (get_reserved_words(*token))
return (1); return (1);
if (insert_newline(&data->token)) if (insert_newline(token))
return (1); return (1);
if (data->parser.state == SUCCESS && stack_init(&data->parser)) if (data->parser.state == SUCCESS && stack_init(&data->parser))
exit(1); exit(1);
if (ft_parse(&data->ast, &data->token, &data->parser)) if (ft_parse(ast, token, &data->parser))
exit(1); exit(1);
if ((data->lexer.state = data->parser.heredoc_queue ? HEREDOC : DEFAULT)) if ((data->lexer.state = data->parser.heredoc_queue ? HEREDOC : DEFAULT))
return (0); return (0);
if (data->parser.state == ERROR) if (data->parser.state == ERROR)
{ {
error_syntax(&data->token); error_syntax(token);
return (1); return (1);
} }
else if (data->parser.state == SUCCESS) else if (data->parser.state == SUCCESS)
@ -76,7 +76,7 @@ static int do_parser_routine(void)
return (0); return (0);
} }
static int handle_instruction() static int handle_instruction(t_list **token, t_btree **ast)
{ {
int ret; int ret;
char *stream; char *stream;
@ -88,18 +88,15 @@ static int handle_instruction()
{ {
if ((ret = do_readline_routine(&stream)) > 0) if ((ret = do_readline_routine(&stream)) > 0)
return (ret); return (ret);
sleep(10);
return (1);
if (do_lexer_routine(stream) > 0) if (do_lexer_routine(stream) > 0)
continue ; continue ;
sleep(10); if (do_lexer_routine(token, stream) > 0)
return (1); continue ;
token_print(data->token); if (do_parser_routine(token, ast) > 0)
if (do_parser_routine() > 0)
break ; break ;
} }
/* btree_print(STDBUG, ast, &ft_putast); */ /* 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); exit(1);
if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str) if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str)
ft_add_str_in_history(data->lexer.str); ft_add_str_in_history(data->lexer.str);
@ -110,6 +107,8 @@ int main(int ac, char **av)
{ {
int ret; int ret;
t_data *data; t_data *data;
t_list *token;
t_btree *ast;
g_argv = av; g_argv = av;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
@ -117,14 +116,16 @@ int main(int ac, char **av)
if (shell_init(ac, av)) if (shell_init(ac, av))
return (1); return (1);
DG("JOBC is %s", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF"); DG("JOBC is %s", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF");
token = NULL;
ast = NULL;
data = data_singleton(); data = data_singleton();
while (1) while (1)
{ {
ret = handle_instruction(); ret = handle_instruction(&token, &ast);
lexer_destroy(&data->lexer); lexer_destroy(&data->lexer);
parser_destroy(&data->parser); parser_destroy(&data->parser);
ft_lstdel(&data->token, &ft_lst_cfree); ft_lstdel(&token, &token_free);
btree_del(&data->ast, &ft_lst_cfree); btree_del(&ast, &ast_free);
if (ret == 1) if (ret == 1)
break ; break ;
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 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:18:46 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,11 +33,10 @@ int get_input_fd(char **av)
else if (data->opts & SH_OPTS_LC) else if (data->opts & SH_OPTS_LC)
{ {
pipe(fds); pipe(fds);
dup2_close(fds[PIPE_READ], 10);
fd = 10;
file = *cliopts_getdata(av); file = *cliopts_getdata(av);
write(fds[PIPE_WRITE], file, ft_strlen(file)); write(fds[PIPE_WRITE], file, ft_strlen(file));
close(fds[PIPE_WRITE]); close(fds[PIPE_WRITE]);
dup2_close(fds[PIPE_READ], (fd = 10));
fcntl(fd, F_SETFD, FD_CLOEXEC); fcntl(fd, F_SETFD, FD_CLOEXEC);
return (fd); return (fd);
} }
@ -93,6 +92,7 @@ int shell_init(int ac, char **av)
} }
if (cliopts_get(av, g_opts, data)) if (cliopts_get(av, g_opts, data))
return (ft_perror()); return (ft_perror());
data->fd = get_input_fd(av);
if (SH_IS_INTERACTIVE(data->opts)) if (SH_IS_INTERACTIVE(data->opts))
interactive_settings(); interactive_settings();
return (0); return (0);