expansion for + cleanage code get_reserved_word

This commit is contained in:
Antoine Riard 2017-03-06 19:05:43 +01:00
parent 9f87126762
commit 1dbc4653fd
16 changed files with 63 additions and 24 deletions

View file

@ -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\

View file

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

View file

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

View file

@ -168,7 +168,7 @@ struct s_cmd
{
t_list *redir;
t_ld *token;
t_list *wordlist;
t_ld *wordlist;
};
union u_astdata

@ -1 +1 @@
Subproject commit 6a2672a19268c6481525d9aaee5bd35722bbd75a
Subproject commit 318efc7cfb7b7cc9d3714fa19fd2be7382b6adec

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error_badidentifier.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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