until exec ok
This commit is contained in:
parent
490f81ee23
commit
c0977b20ff
19 changed files with 83 additions and 24 deletions
|
|
@ -55,6 +55,7 @@ exec/exec_while.c\
|
||||||
exec/exec_if.c\
|
exec/exec_if.c\
|
||||||
exec/exec_else.c\
|
exec/exec_else.c\
|
||||||
exec/exec_elif.c\
|
exec/exec_elif.c\
|
||||||
|
exec/exec_until.c\
|
||||||
exec/ft_exec.c\
|
exec/ft_exec.c\
|
||||||
exec/ft_findexec.c\
|
exec/ft_findexec.c\
|
||||||
exec/launch_process.c\
|
exec/launch_process.c\
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
hello
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/06 18:59:24 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:41:13 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -92,6 +92,7 @@ int exec_while(t_btree **ast);
|
||||||
int exec_if(t_btree **ast);
|
int exec_if(t_btree **ast);
|
||||||
int exec_elif(t_btree **ast);
|
int exec_elif(t_btree **ast);
|
||||||
int exec_else(t_btree **ast);
|
int exec_else(t_btree **ast);
|
||||||
|
int exec_until(t_btree **ast);
|
||||||
int exec_default(t_btree **ast);
|
int exec_default(t_btree **ast);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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/02/06 15:13:20 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:35:43 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -52,6 +52,7 @@ typedef long long t_type;
|
||||||
# define TK_FI (1 << 25)
|
# define TK_FI (1 << 25)
|
||||||
# define TK_ELIF (1 << 26)
|
# define TK_ELIF (1 << 26)
|
||||||
# define TK_ELSE (1 << 27)
|
# define TK_ELSE (1 << 27)
|
||||||
|
# define TK_UNTIL (1 << 28)
|
||||||
|
|
||||||
# define TK_WORD (TK_N_WORD | TK_Q_WORD | TK_DQ_WORD)
|
# define TK_WORD (TK_N_WORD | TK_Q_WORD | TK_DQ_WORD)
|
||||||
# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
|
# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/06 19:02:48 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:35:28 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
|
|
||||||
# include "minishell.h"
|
# include "minishell.h"
|
||||||
|
|
||||||
|
#define INSTRUCTION (TK_WHILE | TK_IF | TK_ELIF | TK_NEWLINE | TK_SEMI\
|
||||||
|
| TK_ELSE | TK_UNTIL)
|
||||||
|
|
||||||
typedef struct s_parser t_parser;
|
typedef struct s_parser t_parser;
|
||||||
typedef struct s_ld t_ld;
|
typedef struct s_ld t_ld;
|
||||||
typedef struct s_astnode t_astnode;
|
typedef struct s_astnode t_astnode;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
ls | cat
|
ls | cat
|
||||||
|
pwd | cat > file1
|
||||||
|
|
|
||||||
8
42sh/sample/until.sh
Normal file
8
42sh/sample/until.sh
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
until [ 1 ]
|
||||||
|
do
|
||||||
|
echo LOOP1
|
||||||
|
until [ 1 ]
|
||||||
|
do
|
||||||
|
echo hello
|
||||||
|
done
|
||||||
|
done > file1
|
||||||
16
42sh/sample/until2.sh
Normal file
16
42sh/sample/until2.sh
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
ONE=0
|
||||||
|
while [ $ONE -le 10 ]
|
||||||
|
do
|
||||||
|
TWO=0
|
||||||
|
while [ $TWO -le 10 ]
|
||||||
|
do
|
||||||
|
THREE=0
|
||||||
|
while [ $THREE -le 10 ]
|
||||||
|
do
|
||||||
|
echo world
|
||||||
|
((THREE++))
|
||||||
|
done
|
||||||
|
((TWO++))
|
||||||
|
done
|
||||||
|
((ONE++))
|
||||||
|
done > file1
|
||||||
|
|
@ -13,4 +13,4 @@ do
|
||||||
((TWO--))
|
((TWO--))
|
||||||
done
|
done
|
||||||
((ONE--))
|
((ONE--))
|
||||||
done
|
done > file1
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
|
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/06 18:55:00 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:39:25 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
25
42sh/src/exec/exec_until.c
Normal file
25
42sh/src/exec/exec_until.c
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* exec_until.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/02/06 20:42:21 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "exec.h"
|
||||||
|
|
||||||
|
int exec_until(t_btree **ast)
|
||||||
|
{
|
||||||
|
int test;
|
||||||
|
|
||||||
|
test = 0;
|
||||||
|
while (test++ != 10)
|
||||||
|
ft_exec(&(*ast)->right);
|
||||||
|
|
||||||
|
// btree_delone(ast, &ast_free);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/06 18:58:09 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:38:07 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,6 +27,7 @@ t_execmap g_execmap[] =
|
||||||
{TK_IF, &exec_if},
|
{TK_IF, &exec_if},
|
||||||
{TK_ELIF, &exec_elif},
|
{TK_ELIF, &exec_elif},
|
||||||
{TK_ELSE, &exec_else},
|
{TK_ELSE, &exec_else},
|
||||||
|
{TK_UNTIL, &exec_until},
|
||||||
{TK_COMMAND | TK_SUBSHELL, &exec_command},
|
{TK_COMMAND | TK_SUBSHELL, &exec_command},
|
||||||
{0, 0},
|
{0, 0},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */
|
/* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/04 15:12:32 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:27:07 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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/02/06 15:10:59 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:37:28 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -43,6 +43,8 @@ int get_reserved_words(t_list **alst)
|
||||||
token->type = TK_ELIF;
|
token->type = TK_ELIF;
|
||||||
else if (ft_strncmp(token->data, "else", 4) == 0)
|
else if (ft_strncmp(token->data, "else", 4) == 0)
|
||||||
token->type = TK_ELSE;
|
token->type = TK_ELSE;
|
||||||
|
else if (ft_strncmp(token->data, "until", 5) == 0)
|
||||||
|
token->type = TK_UNTIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
previous_token = token;
|
previous_token = token;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
|
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/06 19:16:59 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:37:16 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -40,6 +40,8 @@ char *ft_putast(void *nodein)
|
||||||
return ("ELIF");
|
return ("ELIF");
|
||||||
else if (node->type == TK_ELSE)
|
else if (node->type == TK_ELSE)
|
||||||
return ("ELSE");
|
return ("ELSE");
|
||||||
|
else if (node->type == TK_UNTIL)
|
||||||
|
return ("UNTIL");
|
||||||
else if (node->type == TK_NEWLINE)
|
else if (node->type == TK_NEWLINE)
|
||||||
return ("NEW");
|
return ("NEW");
|
||||||
else if (node->type == TK_GREAT)
|
else if (node->type == TK_GREAT)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
|
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/06 19:26:06 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:58:54 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ int shell_script()
|
||||||
{
|
{
|
||||||
if (parse(&ast, &token))
|
if (parse(&ast, &token))
|
||||||
return (1);
|
return (1);
|
||||||
// btree_print(STDBUG, ast, &ft_putast);
|
btree_print(STDBUG, ast, &ft_putast);
|
||||||
if (ft_exec(&ast))
|
if (ft_exec(&ast))
|
||||||
return (1);
|
return (1);
|
||||||
ast = NULL;
|
ast = NULL;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */
|
/* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/06 19:26:04 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:37:26 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
t_parser g_parser[] =
|
t_parser g_parser[] =
|
||||||
{
|
{
|
||||||
{TK_WHILE | TK_IF | TK_ELIF | TK_NEWLINE | TK_SEMI | TK_ELSE, &get_sub_instruction},
|
{INSTRUCTION, &get_sub_instruction},
|
||||||
{TK_AND_IF | TK_OR_IF, &parse_separator},
|
{TK_AND_IF | TK_OR_IF, &parse_separator},
|
||||||
{TK_AMP, &parse_separator},
|
{TK_AMP, &parse_separator},
|
||||||
{TK_PIPE, &parse_separator},
|
{TK_PIPE, &parse_separator},
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/03 16:56:55 by ariard #+# #+# */
|
/* Created: 2017/02/03 16:56:55 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/06 19:18:17 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:30:13 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -101,7 +101,7 @@ int get_instruction(t_list **lst)
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (token->type & TK_NEWLINE)
|
if (token->type & TK_NEWLINE)
|
||||||
return (get_simple_instruction(&start, lst));
|
return (get_simple_instruction(&start, lst));
|
||||||
else if (token->type & TK_WHILE)
|
else if (token->type & (TK_WHILE | TK_UNTIL))
|
||||||
return (get_loop_instruction(&start, lst));
|
return (get_loop_instruction(&start, lst));
|
||||||
else if (token->type & TK_IF)
|
else if (token->type & TK_IF)
|
||||||
return (get_condition_instruction(&start, lst));
|
return (get_condition_instruction(&start, lst));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/05 22:05:26 by ariard #+# #+# */
|
/* Created: 2017/02/05 22:05:26 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/06 19:08:17 by ariard ### ########.fr */
|
/* Updated: 2017/02/06 20:37:24 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,17 +17,17 @@ int get_sub_instruction(t_btree **ast, t_list **start, t_list **lst)
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (token->type == TK_NEWLINE)
|
if (token->type & TK_NEWLINE)
|
||||||
return (parse_separator(ast, start, lst));
|
return (parse_separator(ast, start, lst));
|
||||||
else if (token->type == TK_WHILE)
|
else if (token->type & (TK_WHILE | TK_UNTIL))
|
||||||
return (parse_while(ast, start, lst));
|
return (parse_while(ast, start, lst));
|
||||||
else if (token->type == TK_IF)
|
else if (token->type & TK_IF)
|
||||||
return (parse_if(ast, start, lst));
|
return (parse_if(ast, start, lst));
|
||||||
else if (token->type == TK_ELIF)
|
else if (token->type & TK_ELIF)
|
||||||
return (parse_elif(ast, start, lst));
|
return (parse_elif(ast, start, lst));
|
||||||
else if (token->type == TK_ELSE)
|
else if (token->type & TK_ELSE)
|
||||||
return (parse_else(ast, start, lst));
|
return (parse_else(ast, start, lst));
|
||||||
else if (token->type == TK_SEMI)
|
else if (token->type & TK_SEMI)
|
||||||
return (parse_separator(ast, start, lst));
|
return (parse_separator(ast, start, lst));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue