diff --git a/42sh/Makefile b/42sh/Makefile index 5a75871a..4b83d8f5 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -238,6 +238,7 @@ parser/add_redir.c\ parser/add_sep.c\ parser/add_subshell.c\ parser/add_var.c\ +parser/add_number.c\ parser/aggregate_sym.c\ parser/build_tree.c\ parser/error_syntax.c\ diff --git a/42sh/file b/42sh/file new file mode 100644 index 00000000..614d43df --- /dev/null +++ b/42sh/file @@ -0,0 +1,16 @@ +total 576 +-rwxr-xr-x 1 ariard 2016_paris 249036 Mar 5 17:14 42sh +-rw-r--r-- 1 ariard 2016_paris 8133 Mar 5 16:46 Makefile +-rw-r--r-- 1 ariard 2016_paris 16999 Mar 5 17:15 STDBUG +drwxr-xr-x 7 ariard 2016_paris 238 Mar 4 14:53 TESTSHELL +-rw-r--r-- 1 ariard 2016_paris 4396 Mar 4 14:53 donovan_segaults_06-02 +-rw-r--r-- 1 ariard 2016_paris 0 Mar 5 17:15 file +drwxr-xr-x 16 ariard 2016_paris 544 Mar 5 16:46 includes +drwxr-xr-x 12 ariard 2016_paris 408 Mar 5 16:50 libft +drwxr-xr-x 13 ariard 2016_paris 442 Mar 5 16:50 objs +-rw-r--r-- 1 ariard 2016_paris 0 Mar 4 14:53 parser_init.c +drwxr-xr-x 6 ariard 2016_paris 204 Mar 4 14:53 pdf +drwxr-xr-x 29 ariard 2016_paris 986 Mar 4 14:53 sample +drwxr-xr-x 14 ariard 2016_paris 476 Mar 4 14:53 src +-rwxr-xr-x 1 ariard 2016_paris 890 Mar 4 14:53 test_framework.sh +-rwxr-xr-x 1 ariard 2016_paris 690 Mar 4 14:53 update_makefile.sh diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index da36d5d1..a6fbd771 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -26,8 +26,6 @@ enum e_parstate SUCCESS, }; -# define TK_REDIR(x) (TK_LESS <= x && x <= TK_GREATAND) - # define MATCH_STACK(x, y) (x == y || y == ALL) struct s_parser @@ -127,6 +125,7 @@ int add_one_func(t_btree **ast, t_list **lst); int add_pipe(t_btree **ast, t_list **lst); int add_var(t_btree **ast, t_list **lst); int add_null(t_btree **ast, t_list **lst); +int add_ionumbr(t_btree **ast, t_list **lst); int isloop(t_btree **ast, t_list **lst); int isloop_condition(t_btree **ast, t_list **lst); @@ -143,6 +142,7 @@ int isdir_sep(t_btree **ast, t_list **list); int isdir_word(t_btree **ast, t_list **list); int isvar(t_btree **ast, t_list **list); int isnull(t_btree **ast, t_list **list); +int isionumber(t_btree **ast, t_list **lst); int join_ast(t_btree **ast, t_btree **new_node); int gen_node(t_btree **ast); @@ -156,17 +156,11 @@ struct s_distrostree extern t_distrostree g_distrostree[]; -union u_word -{ - char *word; - int fd; -}; - struct s_redir { t_flag type; int n; - t_word word; + char *word; int close; }; @@ -174,12 +168,12 @@ struct s_cmd { t_list *redir; t_ld *token; + t_list *wordlist; }; union u_astdata { t_cmd cmd; - t_list *wordlist; char **sstr; char *str; }; diff --git a/42sh/sample/for/for.sh b/42sh/sample/for/for.sh index 90cfffe6..9d942c9e 100644 --- a/42sh/sample/for/for.sh +++ b/42sh/sample/for/for.sh @@ -1,11 +1,4 @@ for i in hello bonjour salut comment do - for i in echo - do - pwd - done - for i in echo - do - pwd - done + ls done diff --git a/42sh/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index 4cb2db38..4975673e 100644 --- a/42sh/src/exec/ast_free.c +++ b/42sh/src/exec/ast_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:58:16 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 18:05:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ void read_redir(void *data) t_redir *redir; redir = data; - DG("file : [%s]", redir->word.word); + DG("file : [%s]", redir->word); } void ast_free(void *data, size_t content_size) @@ -29,7 +29,7 @@ void ast_free(void *data, size_t content_size) if (node->type == CMD) { ft_ld_clear(&node->data.cmd.token, &ft_tabdel); - ft_lstdel(&node->data.cmd.redir, &redir_free); +// ft_lstdel(&node->data.cmd.redir, &redir_free); } // if (node->type == WORDLIST) // do clear diff --git a/42sh/src/exec/exec_for.c b/42sh/src/exec/exec_for.c index eba6c713..270e12e2 100644 --- a/42sh/src/exec/exec_for.c +++ b/42sh/src/exec/exec_for.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 20:42:20 by ariard #+# #+# */ -/* Updated: 2017/03/04 18:17:05 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:22:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ int exec_for(t_btree **ast) char *var; node = (*ast)->item; - temp = node->data.wordlist; + temp = node->data.cmd.wordlist; var = temp->content; builtin_setenv("setenv", (char*[]){var, 0}, data_singleton()->local_var); while (temp) diff --git a/42sh/src/exec/redir_free.c b/42sh/src/exec/redir_free.c index 41ed42d2..5befbe63 100644 --- a/42sh/src/exec/redir_free.c +++ b/42sh/src/exec/redir_free.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 18:12:57 by ariard #+# #+# */ -/* Updated: 2017/03/05 15:58:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 18:06:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,11 +20,9 @@ void redir_free(void *data, size_t content_size) redir = data; if (redir->type == TK_GREAT || redir->type == TK_LESS || redir->type == TK_DGREAT) { - /* DG("word.word: %s", redir->word.word); */ - ft_strdel(&redir->word.word); + ft_strdel(&redir->word); } /* else */ - /* redir->word.fd = 0; */ /* redir->type = 0; */ /* redir->n = 0; */ /* redir->close = 1; */ diff --git a/42sh/src/exec/redirect_dgreat.c b/42sh/src/exec/redirect_dgreat.c index 62e01058..f890172b 100644 --- a/42sh/src/exec/redirect_dgreat.c +++ b/42sh/src/exec/redirect_dgreat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:07:37 by jhalford #+# #+# */ -/* Updated: 2017/02/06 22:27:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 18:10:36 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int redirect_dgreat(t_redir *redir) int fdnew; fdnew = redir->n; - if ((fdold = open(redir->word.word, + if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0) { DG("open errno=%i", errno); diff --git a/42sh/src/exec/redirect_dless.c b/42sh/src/exec/redirect_dless.c index 36f4a25a..0244098d 100644 --- a/42sh/src/exec/redirect_dless.c +++ b/42sh/src/exec/redirect_dless.c @@ -17,7 +17,7 @@ int redirect_dless(t_redir *redir) char *str; pipe(fds); - str = redir->word.word; + str = redir->word; write(fds[PIPE_WRITE], str, ft_strlen(str)); close(fds[PIPE_WRITE]); dup2(fds[PIPE_READ], 0); diff --git a/42sh/src/exec/redirect_great.c b/42sh/src/exec/redirect_great.c index bd6e170a..4ec227d8 100644 --- a/42sh/src/exec/redirect_great.c +++ b/42sh/src/exec/redirect_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ -/* Updated: 2017/02/06 22:42:05 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 18:07:25 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int redirect_great(t_redir* redir) int fdnew; fdnew = redir->n; - if ((fdold = open(redir->word.word, + if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { DG("open errno=%i", errno); diff --git a/42sh/src/exec/redirect_greatand.c b/42sh/src/exec/redirect_greatand.c index 70658424..34803f72 100644 --- a/42sh/src/exec/redirect_greatand.c +++ b/42sh/src/exec/redirect_greatand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */ -/* Updated: 2017/02/07 17:54:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 18:12:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,11 @@ int redirect_greatand(t_redir *redir) int fdold; int fdnew; + (void)redir; + (void)fdold; + (void)fdnew; DG("redir greatand"); + /* if (redir->close) { close(redir->n); @@ -33,5 +37,6 @@ int redirect_greatand(t_redir *redir) dup2_close(fdold, fdnew); else return (bad_fd(fdold)); + */ return (0); } diff --git a/42sh/src/exec/redirect_less.c b/42sh/src/exec/redirect_less.c index 8619db29..7942ce1a 100644 --- a/42sh/src/exec/redirect_less.c +++ b/42sh/src/exec/redirect_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */ -/* Updated: 2017/02/20 20:42:53 by ariard ### ########.fr */ +/* Updated: 2017/03/05 18:11:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,10 +18,10 @@ int redirect_less(t_redir *redir) int fdnew; fdnew = redir->n; - if ((fdold = open(redir->word.word, O_RDONLY)) < 0) + if ((fdold = open(redir->word, O_RDONLY)) < 0) { ft_dprintf(2, "{red}%s: no such file or directory: %s{eoc}\n", - SHELL_NAME, redir->word.word); + SHELL_NAME, redir->word); exit (1); } dup2(fdold, fdnew); diff --git a/42sh/src/exec/redirect_lessand.c b/42sh/src/exec/redirect_lessand.c index 15da4123..0442941d 100644 --- a/42sh/src/exec/redirect_lessand.c +++ b/42sh/src/exec/redirect_lessand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */ -/* Updated: 2017/02/07 17:54:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 18:13:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,10 @@ int redirect_lessand(t_redir *redir) int fdold; int fdnew; + (void)redir; + (void)fdold; + (void)fdnew; + /* if (redir->close) { close(redir->n); @@ -35,5 +39,6 @@ int redirect_lessand(t_redir *redir) } else return (bad_fd(fdold)); + */ return (0); } diff --git a/42sh/src/lexer/lexer_delim.c b/42sh/src/lexer/lexer_delim.c index 026a0f4a..648aa8a0 100644 --- a/42sh/src/lexer/lexer_delim.c +++ b/42sh/src/lexer/lexer_delim.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */ -/* Updated: 2017/02/25 19:56:31 by ariard ### ########.fr */ +/* Updated: 2017/03/05 17:08:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index 3ec6edcf..bd79af4d 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/05 18:42:43 by wescande ### ########.fr */ +/* Updated: 2017/03/05 19:30:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_number.c b/42sh/src/lexer/lexer_number.c index c5f1ce93..b7eb03b4 100644 --- a/42sh/src/lexer/lexer_number.c +++ b/42sh/src/lexer/lexer_number.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */ -/* Updated: 2017/03/05 17:15:52 by wescande ### ########.fr */ +/* Updated: 2017/03/05 18:03:34 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,35 +48,3 @@ int lexer_number(t_list **alst, t_lexer *lexer) return (lexer_lex(alst, lexer)); } } -/* -int lexer_number(t_list **alst, t_lexer *lexer) -{ - t_token *token; - t_lexstate state; - - token = (*alst)->content; - token->type = TK_IO_NUMBER; - if ((state = get_state_global(lexer)) - || (state = get_state_redir(lexer))) - { - lexer->state = state; - return (lexer_lex(alst, lexer)); - } - else if (ft_isdigit(lexer->str[lexer->pos]) - && (lexer->str[lexer->pos + 1] == '>' || lexer->str[lexer->pos + 1] == '<')) - { - token_append(token, lexer, 0, 0); - lexer->pos++; - return (lexer_number(alst, lexer)); - } - else - { - token->type = TK_WORD; - token_append(token, lexer, 0, 0); - lexer->pos++; - return (lexer_lex(alst, lexer)); - } - lexer->state = DEFAULT; - return (lexer_lex(alst, lexer)); -} -*/ diff --git a/42sh/src/lexer/lexer_paren.c b/42sh/src/lexer/lexer_paren.c index ee205745..db8b0545 100644 --- a/42sh/src/lexer/lexer_paren.c +++ b/42sh/src/lexer/lexer_paren.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 17:37:15 by jhalford #+# #+# */ -/* Updated: 2017/03/05 16:29:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:48:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 066379f2..d10c9e48 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/03 17:56:07 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 17:07:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index d2f3fd6e..25fc6457 100644 --- a/42sh/src/main/ft_putast.c +++ b/42sh/src/main/ft_putast.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ -/* Updated: 2017/03/03 20:05:54 by ariard ### ########.fr */ +/* Updated: 2017/03/05 14:57:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,8 @@ char *ft_putast(void *nodein) t_astnode *node; node = nodein; + if (node->type == WORDLIST) + return ("WORDLIST"); if (node->type == CMD) return ("CMD"); if (node->type == REDIR) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index ad4cbd63..47fed25d 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/05 16:32:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:47:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index 0eb38a40..74ab538e 100644 --- a/42sh/src/parser/add_case.c +++ b/42sh/src/parser/add_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 20:42:13 by ariard #+# #+# */ -/* Updated: 2017/03/05 15:33:58 by wescande ### ########.fr */ +/* Updated: 2017/03/05 17:30:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 691cfd9b..4b42a3dc 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/03/04 22:05:47 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:34:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,6 @@ int superflous_token(t_btree **ast, t_list **lst) t_token *token; (void)ast; - DG("superflous token"); if (*lst) { token = (*lst)->content; @@ -73,7 +72,6 @@ int add_cmd(t_btree **ast, t_list **lst) DG("add cmd"); while (i < 14) { - DG("test"); if (g_distrostree[i].test(ast, lst) == 1) { DG("add : %d", i); diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index 3096eb61..63481be3 100644 --- a/42sh/src/parser/add_loop.c +++ b/42sh/src/parser/add_loop.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ -/* Updated: 2017/03/05 15:33:35 by wescande ### ########.fr */ +/* Updated: 2017/03/05 16:46:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,7 @@ int isloop_condition(t_btree **ast, t_list **lst) if (*ast) { node = (*ast)->item; - if (node->type == TK_FOR && token->type == TK_WORD + if (node->type == TK_FOR && (token->type == TK_WORD || token->type == TK_NAME) && node->pattern == 0) return (1); } @@ -94,7 +94,8 @@ int add_loop_condition(t_btree **ast, t_list **lst) token = (*lst)->content; node = (*ast)->item; - ft_lsteadd(&node->data.wordlist, ft_lstnew(ft_strdup(token->data), + DG("add word"); + ft_lsteadd(&node->data.cmd.wordlist, ft_lstnew(ft_strdup(token->data), ft_strlen(token->data))); return (0); } diff --git a/42sh/src/parser/add_number.c b/42sh/src/parser/add_number.c new file mode 100644 index 00000000..84ffe8ca --- /dev/null +++ b/42sh/src/parser/add_number.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* add_number.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */ +/* Updated: 2017/03/05 18:15:40 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser.h" + +int isionumber(t_btree **ast, t_list **lst) +{ + t_token *token; + + (void)ast; + token = (*lst)->content; + if (token->type == TK_IO_NUMBER) + return (1); + return (0); +} + +int add_ionumber(t_btree **ast, t_list **lst) +{ + t_astnode *node; + t_token *token; + t_redir redir; + + if (!*ast) + gen_node(ast); + token = (*lst)->content; + node = (*ast)->item; + node->type = token->type; + redir.n = ft_atoi(token->data); + ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir))); + return (0); +} diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 6e7eb442..46d89b71 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/03/04 20:00:46 by ariard ### ########.fr */ +/* Updated: 2017/03/05 18:14:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,26 +14,14 @@ int isdir_sep(t_btree **ast, t_list **list) { - t_astnode *node; t_token *token; + (void)ast; token = (*list)->content; - if (*ast) - { - node = (*ast)->item; - if (node->type == CMD - && (token->type == TK_LESS || token->type == TK_GREAT - || token->type == TK_GREATAND || token->type == TK_LESSAND - || token->type == TK_DLESS || token->type == TK_DGREAT)) - return (1); - } - if (!*ast) - { - if (token->type == TK_LESS || token->type == TK_GREAT - || token->type == TK_GREATAND || token->type == TK_LESSAND - || token->type == TK_DLESS || token->type == TK_DGREAT) - return (1); - } + if (token->type == TK_LESS || token->type == TK_GREAT + || token->type == TK_GREATAND || token->type == TK_LESSAND + || token->type == TK_DLESS || token->type == TK_DGREAT) + return (1); return (0); } @@ -47,7 +35,10 @@ int isdir_word(t_btree **ast, t_list **list) { node = (*ast)->item; if (token->type == TK_WORD && node->type == REDIR) - return ((node->type = CMD)); + { + node->type = CMD; + return (1); + } } return (0); } @@ -65,11 +56,9 @@ int add_redir_word(t_btree **ast, t_list **lst) DG("add file"); redir = (ft_lstlast(node->data.cmd.redir))->content; if (redir->type == TK_DLESS) - redir->word.word = NULL; - else if (ft_stris((char *)token->data, &ft_isdigit)) - redir->word.fd = ft_atoi(token->data); + redir->word = NULL; else - redir->word.word = ft_strdup(token->data); + redir->word = ft_strdup(token->data); } return (0); } @@ -80,13 +69,17 @@ int add_redir_type(t_btree **ast, t_list **lst) t_token *token; t_redir redir; - DG("add redir"); if (!*ast) gen_node(ast); token = (*lst)->content; node = (*ast)->item; + if (!(node->type == TK_IO_NUMBER)) + { + redir.n = (token->type == TK_LESS || token->type == TK_DLESS + || token->type == TK_LESSAND) ? STDIN : STDOUT; + ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir))); + } node->type = REDIR; redir.type = token->type; - ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir))); return (0); } diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 03ae7a56..fb79eb04 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -1,5 +1,4 @@ -/* ************************************************************************** */ -/* */ +/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* aggregate_sym.c :+: :+: :+: */ /* +:+ +:+ +:+ */ @@ -316,21 +315,21 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) i = 0; head = (*stack)->content; - DG("aggregate head %s && sym %s", - read_state(*head), read_state(*new_sym)); +// DG("aggregate head %s && sym %s", +// read_state(*head), read_state(*new_sym)); 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)); +// 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)); +// DG("stack after pop: %s", read_state(*head)); } if (eval_sym(stack, *new_sym)) return ((*state = ERROR)); diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 1848f810..0ebefed7 100644 --- a/42sh/src/parser/build_tree.c +++ b/42sh/src/parser/build_tree.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ -/* Updated: 2017/03/04 20:56:42 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:04:14 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,6 +41,7 @@ t_treematch g_treematch[] = {TK_PAREN_OPEN, &add_cmd}, {TK_PAREN_CLOSE, &add_cmd}, {TK_FOR, &add_cmd}, + {TK_NAME, &add_cmd}, {TK_ASSIGNEMENT_WORD, &add_cmd}, {SUBSHELL, &add_cmd}, {TK_LBRACE, &add_cmd}, diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 9acbc37a..6a5f0724 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -1027,7 +1027,7 @@ int eval_sym(t_list **stack, t_sym new_sym) int i; head = (*stack)->content; - DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); +// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); i = 0; while (g_stackmatch[i].top) { diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index c0d40cd6..b959f9c5 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -37,12 +37,9 @@ 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)); +// DG("new sym %s", read_state(*parser->new_sym)); if (eval_sym(&parser->stack, *parser->new_sym)) -{ - DG("ERRROR"); return ((parser->state = ERROR)); -} else { aggregate_sym(&parser->stack, parser->new_sym, &parser->state); @@ -55,7 +52,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) else parser->state = UNDEFINED; build_tree(ast, token); -// btree_print(STDBUG, *ast, &ft_putast); + btree_print(STDBUG, *ast, &ft_putast); if ((end_instruction(&parser->stack) && !(*token)->next)) insert_linebreak(token); else diff --git a/42sh/src/parser/pop_stack.c b/42sh/src/parser/pop_stack.c index eea77345..b2b8c9d7 100644 --- a/42sh/src/parser/pop_stack.c +++ b/42sh/src/parser/pop_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 19:12:44 by ariard #+# #+# */ -/* Updated: 2017/03/03 14:28:02 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:28:52 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,6 @@ int pop_stack(t_list **stack, t_sym erase_sym) t_sym *head; t_list *temp; - DG("pop until :%s", read_state(erase_sym)); head = (*stack)->content; while ((*stack) && *head != erase_sym) { @@ -29,12 +28,5 @@ int pop_stack(t_list **stack, t_sym erase_sym) temp = *stack; (*stack) = (*stack)->next; ft_lstdelone(&temp, NULL); -/* - DG("pop until :%s", read_state(erase_sym)); - temp = *stack; - while (*temp != erase_sym) - *temp-- = 0; - *temp-- = 0; - *stack = temp; - */ return (0); + return (0); } diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 717c15ca..c2302123 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ -/* Updated: 2017/03/03 18:43:13 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:12:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -107,8 +107,8 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst) token = (*lst)->content; head = (*stack)->content; - DG("produce stack : %s && token : %s", read_state(*head), - read_state(token->type)); +// DG("produce stack : %s && token : %s", read_state(*head), +// read_state(token->type)); i = 0; *new_sym = 0; while (g_prodmatch[i].new_sym) @@ -116,7 +116,7 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst) if (token->type == g_prodmatch[i].token && *head == g_prodmatch[i].stack) { - DG("MATCH : %s", read_state(g_prodmatch[i].new_sym)); +// DG("MATCH : %s", read_state(g_prodmatch[i].new_sym)); *new_sym = g_prodmatch[i].new_sym; } i++; diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index 07be0e9c..ed89c93e 100644 --- a/42sh/src/parser/tree_wrapper.c +++ b/42sh/src/parser/tree_wrapper.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:57:44 by ariard #+# #+# */ -/* Updated: 2017/03/04 21:20:16 by ariard ### ########.fr */ +/* Updated: 2017/03/05 16:56:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ int gen_node(t_btree **ast) ft_bzero((void *)&((t_astnode *)(*ast)->item)->data, sizeof(t_astdata)); ((t_astnode *)(*ast)->item)->nest = 0; ((t_astnode *)(*ast)->item)->full = 0; - ((t_astnode *)(*ast)->item)->type = 0; + ((t_astnode *)(*ast)->item)->type = TK_NEWLINE; ((t_astnode *)(*ast)->item)->pattern = 0; } return (0);