diff --git a/42sh/Makefile b/42sh/Makefile index 83025081..08954103 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -96,6 +96,7 @@ exec/redirect_less.c\ exec/redirect_lessand.c\ exec/set_exitstatus.c\ exec/set_process.c\ +exec/error_badidentifier.c\ glob/command_getoutput.c\ glob/dir_glob.c\ glob/esc_print.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 4afa61d6..e7d93dc5 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/06 12:33:24 by wescande ### ########.fr */ +/* Updated: 2017/03/06 18:11:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -147,4 +147,6 @@ char **token_to_argv(t_ld *ld, int do_match); int add_new_job(t_job *job); +int error_badidentifier(char *name); + #endif diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 9cd38208..d47b2e0f 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/03/06 17:52:13 by ariard ### ########.fr */ +/* Updated: 2017/03/06 18:28:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 49eb2ddc..25c8bcd7 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -168,7 +168,7 @@ struct s_cmd { t_list *redir; t_ld *token; - t_list *wordlist; + t_ld *wordlist; }; union u_astdata diff --git a/42sh/libft b/42sh/libft index 6a2672a1..318efc7c 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit 6a2672a19268c6481525d9aaee5bd35722bbd75a +Subproject commit 318efc7cfb7b7cc9d3714fa19fd2be7382b6adec diff --git a/42sh/src/exec/error_badidentifier.c b/42sh/src/exec/error_badidentifier.c new file mode 100644 index 00000000..9883f60d --- /dev/null +++ b/42sh/src/exec/error_badidentifier.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* error_badidentifier.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/06 18:03:51 by ariard #+# #+# */ +/* Updated: 2017/03/06 18:11:26 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "exec.h" + +int error_badidentifier(char *name) +{ + ft_putstr_fd("`", 2); + ft_putstr(name); + ft_putstr_fd("' not a valid identifier", 2); + return (1); +} diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index fdf22068..6bbed2be 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ -/* Updated: 2017/03/06 15:03:36 by ariard ### ########.fr */ +/* Updated: 2017/03/06 18:51:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_for.c b/42sh/src/exec/exec_for.c index 91606fe6..5159c515 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/05 15:22:49 by ariard ### ########.fr */ +/* Updated: 2017/03/06 19:02:36 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,20 +15,28 @@ int exec_for(t_btree **ast) { t_astnode *node; - t_list *temp; -// char **av = NULL; + t_ld *temp; + char **av; char *var; + int i; node = (*ast)->item; temp = node->data.cmd.wordlist; - var = temp->content; + var = ((char **)(temp->content))[0]; + if (ft_isdigit(var[0])) + return (error_badidentifier(var)); temp = temp->next; -// declare error bad identifier while (temp) - { - builtin_setenv("setenv", (char*[]){var, temp->content, 0}, - data_singleton()->local_var); - ft_exec(&(*ast)->right); + { + i = 0; + av = token_to_argv(temp, 1); + while (av[i]) + { + builtin_setenv("setenv", (char*[]){var, av[i], 0}, + data_singleton()->local_var); + ft_exec(&(*ast)->right); + i++; + } temp = temp->next; } return (0); diff --git a/42sh/src/exec/exec_semi.c b/42sh/src/exec/exec_semi.c index 5f03aa23..c7848424 100644 --- a/42sh/src/exec/exec_semi.c +++ b/42sh/src/exec/exec_semi.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */ -/* Updated: 2017/03/04 17:23:50 by ariard ### ########.fr */ +/* Updated: 2017/03/06 18:09:54 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index a56782fa..6b78f9cb 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/03/06 15:01:32 by ariard ### ########.fr */ +/* Updated: 2017/03/06 18:08:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index 7ec05157..3be94f58 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/06 12:26:11 by wescande ### ########.fr */ +/* Updated: 2017/03/06 18:41:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index 6f29ae61..4d14e54d 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/03/06 17:56:14 by ariard ### ########.fr */ +/* Updated: 2017/03/06 17:59:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 489ec97f..42793da2 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/06 16:40:03 by ariard ### ########.fr */ +/* Updated: 2017/03/06 18:48:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index 63481be3..2bb3cd59 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 16:46:50 by ariard ### ########.fr */ +/* Updated: 2017/03/06 19:02:46 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -91,11 +91,18 @@ int add_loop_condition(t_btree **ast, t_list **lst) { t_astnode *node; t_token *token; + char **my_tab; token = (*lst)->content; node = (*ast)->item; DG("add word"); - ft_lsteadd(&node->data.cmd.wordlist, ft_lstnew(ft_strdup(token->data), - ft_strlen(token->data))); + if ((my_tab = (char **)malloc(sizeof(char *) * 4))) + { + my_tab[0] = ft_strdup(token->data); + my_tab[1] = (char *)dup_char_esc(token->esc, token->size >> 3); + my_tab[2] = (char *)dup_char_esc(token->esc2, token->size >> 3); + my_tab[3] = NULL; + } + ft_ld_pushback(&node->data.cmd.wordlist, my_tab); return (0); } diff --git a/42sh/src/parser/error_syntax.c b/42sh/src/parser/error_syntax.c index 161b1ac3..d48228c6 100644 --- a/42sh/src/parser/error_syntax.c +++ b/42sh/src/parser/error_syntax.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:15:35 by ariard #+# #+# */ -/* Updated: 2017/03/06 17:50:43 by ariard ### ########.fr */ +/* Updated: 2017/03/06 18:07:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index ed89c93e..81415d2e 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/05 16:56:00 by ariard ### ########.fr */ +/* Updated: 2017/03/06 19:01:18 by ariard ### ########.fr */ /* */ /* ************************************************************************** */