This commit is contained in:
gwojda 2017-03-24 17:12:20 +01:00
commit aa08eba1c3
16 changed files with 31 additions and 35 deletions

1
42sh/file1 Normal file
View file

@ -0,0 +1 @@
world

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
/* Updated: 2017/03/24 17:00:06 by gwojda ### ########.fr */ /* Updated: 2017/03/24 17:10:56 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -193,6 +193,7 @@ enum e_sym
OPEN_FUNC, OPEN_FUNC,
CLOSE_FUNC, CLOSE_FUNC,
CLOSE_LIST, CLOSE_LIST,
OTHER,
REDIR, REDIR,
CMD, CMD,
HEREDOCDATA, HEREDOCDATA,

View file

@ -1,7 +1,2 @@
echo "echo hello" >> sample/infinite.sh echo "echo hello" >> sample/infinite.sh
echo hello echo hello
echo hello
echo hello
echo hello
echo hello
echo hello

View file

@ -4,13 +4,8 @@ do
TWO=0 TWO=0
while [ $TWO -le 10 ] while [ $TWO -le 10 ]
do do
THREE=0 echo world
while [ $THREE -le 10 ] math TWO + 1;
do
echo world
((THREE++))
done
((TWO++))
done done
((ONE++)) math ONE + 1;
done > file1 done > file1

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/23 16:25:23 by ariard #+# #+# */ /* Created: 2017/03/23 16:25:23 by ariard #+# #+# */
/* Updated: 2017/03/23 16:27:57 by ariard ### ########.fr */ /* Updated: 2017/03/24 16:36:39 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -45,6 +45,7 @@ int exec_func(t_btree **ast)
t_btree *func_ast; t_btree *func_ast;
t_list *old_func; t_list *old_func;
DG();
func_ast = btree_map(*ast, &node_copy); func_ast = btree_map(*ast, &node_copy);
if ((old_func = is_already_func(&func_ast))) if ((old_func = is_already_func(&func_ast)))
{ {

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */
/* Updated: 2017/03/23 00:51:22 by ariard ### ########.fr */ /* Updated: 2017/03/24 15:40:00 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,10 +21,8 @@ int exec_var(t_btree **ast)
char *equal; char *equal;
node = (*ast)->item; node = (*ast)->item;
DG("before");
if (!(av = token_to_argv(node->data.cmd.token, 1))) if (!(av = token_to_argv(node->data.cmd.token, 1)))
return (0); return (0);
DG("after");
var = av[0]; var = av[0];
if ((equal = ft_strchr(av[0], '='))) if ((equal = ft_strchr(av[0], '=')))
*equal = 0; *equal = 0;

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
/* Updated: 2017/03/23 16:35:59 by ariard ### ########.fr */ /* Updated: 2017/03/24 16:53:04 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,8 +19,6 @@ int plaunch_function(t_process *p)
{ {
static int protection; static int protection;
if (!protection)
protection = 0;
if (protection >= FUNC_LVL) if (protection >= FUNC_LVL)
return (SH_ERR(FUNCERR_0)); return (SH_ERR(FUNCERR_0));
protection++; protection++;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
/* Updated: 2017/03/23 16:35:25 by ariard ### ########.fr */ /* Updated: 2017/03/24 15:51:24 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,6 +36,7 @@ int process_redirect(t_process *p)
fd_replace(p->fdout, STDOUT); fd_replace(p->fdout, STDOUT);
while (redirs) while (redirs)
{ {
DG();
redir = redirs->content; redir = redirs->content;
if (redir->n > 9) if (redir->n > 9)
return (bad_fd(redir->n)); return (bad_fd(redir->n));

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:02:58 by ariard #+# #+# */ /* Created: 2017/03/08 00:02:58 by ariard #+# #+# */
/* Updated: 2017/03/20 16:26:50 by gwojda ### ########.fr */ /* Updated: 2017/03/24 15:54:27 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,6 +19,7 @@ void *redir_copy(void *data)
if (!data) if (!data)
return (NULL); return (NULL);
DG();
old = data; old = data;
new = (t_redir *)ft_memalloc(sizeof(t_redir)); new = (t_redir *)ft_memalloc(sizeof(t_redir));
new->type = old->type; new->type = old->type;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
/* Updated: 2017/03/20 18:15:43 by gwojda ### ########.fr */ /* Updated: 2017/03/24 15:59:36 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,6 +21,7 @@ int redirect_great(t_redir *redir)
if ((fdold = open(redir->word, if ((fdold = open(redir->word,
O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
exit(1); exit(1);
DG("%d %d", fdold, fdnew);
dup2(fdold, fdnew); dup2(fdold, fdnew);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/03/23 16:49:28 by ariard ### ########.fr */ /* Updated: 2017/03/24 16:56:50 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -86,6 +86,8 @@ static int add_data_node(t_btree **ast, t_list **lst)
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->type == TK_CASE || node->type == TK_PAREN_OPEN))
node->pattern = 1; node->pattern = 1;
if (token->type == SUBSHELL || token->type == TK_LBRACE)
node->nest = 1;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
/* Updated: 2017/03/23 16:26:09 by ariard ### ########.fr */ /* Updated: 2017/03/24 16:51:13 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,9 +26,6 @@ int isfunc_name(t_btree **ast, t_list **lst)
node->type = FNAME; node->type = FNAME;
return (1); return (1);
} }
if (node->type == FNAME && token->type == TK_PAREN_CLOSE
&& node->nest == 0)
return (1);
} }
return (0); return (0);
} }
@ -62,7 +59,8 @@ int add_func_cmd(t_btree **ast, t_list **lst)
if ((token->type == TK_CASE || token->type == TK_WHILE if ((token->type == TK_CASE || token->type == TK_WHILE
|| token->type == TK_IF || token->type == TK_UNTIL || token->type == TK_IF || token->type == TK_UNTIL
|| token->type == TK_FOR || token->type == SUBSHELL || token->type == TK_FOR || token->type == SUBSHELL
|| token->type == TK_LBRACE) && node->type == FNAME) || token->type == TK_LBRACE || token->type == TK_PAREN_OPEN)
&& node->type == FNAME)
node->nest++; node->nest++;
if ((token->type == TK_DONE || token->type == TK_ESAC if ((token->type == TK_DONE || token->type == TK_ESAC
|| token->type == TK_FI || token->type == TK_RBRACE || token->type == TK_FI || token->type == TK_RBRACE

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
/* Updated: 2017/03/23 16:29:03 by ariard ### ########.fr */ /* Updated: 2017/03/24 15:55:55 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -71,6 +71,7 @@ int add_redir_word(t_btree **ast, t_list **lst)
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
DG("node type is %s", read_state(node->type));
if (node->data.cmd.redir) if (node->data.cmd.redir)
{ {
redir = (ft_lstlast(node->data.cmd.redir))->content; redir = (ft_lstlast(node->data.cmd.redir))->content;
@ -111,6 +112,7 @@ int add_redir_type(t_btree **ast, t_list **lst)
gen_node(ast); gen_node(ast);
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
DG("node type is %s", read_state(node->type));
if (!(node->type == TK_IO_NUMBER)) if (!(node->type == TK_IO_NUMBER))
{ {
redir_init(token->type, &redir); redir_init(token->type, &redir);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */
/* Updated: 2017/03/22 15:32:43 by ariard ### ########.fr */ /* Updated: 2017/03/24 17:02:29 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -47,7 +47,7 @@ int add_subshell_cmd(t_btree **ast, t_list **lst)
if (((token->type == TK_PAREN_CLOSE && node->type == SUBSHELL) if (((token->type == TK_PAREN_CLOSE && node->type == SUBSHELL)
|| (token->type == TK_RBRACE && node->type == TK_LBRACE)) && node->nest > 0) || (token->type == TK_RBRACE && node->type == TK_LBRACE)) && node->nest > 0)
node->nest--; node->nest--;
else if (token->type == TK_PAREN_CLOSE && node->type == SUBSHELL if (token->type == TK_PAREN_CLOSE && node->type == SUBSHELL
&& node->nest == 0) && node->nest == 0)
return ((node->full = 1)); return ((node->full = 1));
else if (token->type == TK_RBRACE && node->type == TK_LBRACE else if (token->type == TK_RBRACE && node->type == TK_LBRACE

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/03/24 15:01:36 by ariard ### ########.fr */ /* Updated: 2017/03/24 17:02:43 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -72,6 +72,8 @@ static int check_cache(t_token *token, int cache)
if (token->type == TK_PAREN_OPEN && cache != TK_IN && cache != TK_DSEMI if (token->type == TK_PAREN_OPEN && cache != TK_IN && cache != TK_DSEMI
&& cache != TK_WORD) && cache != TK_WORD)
token->type = SUBSHELL; token->type = SUBSHELL;
if (token->type == TK_PAREN_CLOSE && cache == TK_PAREN_OPEN)
token->type = OTHER;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */ /* Created: 2017/03/11 16:17:38 by ariard #+# #+# */
/* Updated: 2017/03/24 15:18:51 by ariard ### ########.fr */ /* Updated: 2017/03/24 17:01:05 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */