add lst_find_until + exec script multilines ok
This commit is contained in:
parent
c79789b43a
commit
ca8fb52d34
18 changed files with 59 additions and 28 deletions
2
42sh/.gitignore
vendored
2
42sh/.gitignore
vendored
|
|
@ -6,3 +6,5 @@ debug
|
||||||
*.dSYM
|
*.dSYM
|
||||||
.script.sh.swp
|
.script.sh.swp
|
||||||
*.swp
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*.o
|
||||||
|
|
|
||||||
1
42sh/file1
Normal file
1
42sh/file1
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
11
|
||||||
|
|
@ -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/01/24 00:45:06 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 16:21:11 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/23 23:31:30 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 16:35:43 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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/01/20 18:26:51 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 16:46:36 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -66,5 +66,6 @@ int parse_lessand(t_btree **ast, t_list **start, t_list **lst);
|
||||||
int parse_greatand(t_btree **ast, t_list **start, t_list **lst);
|
int parse_greatand(t_btree **ast, t_list **start, t_list **lst);
|
||||||
int parse_word(t_btree **ast, t_list **start, t_list **lst);
|
int parse_word(t_btree **ast, t_list **start, t_list **lst);
|
||||||
int parse_subshell(t_btree **ast, t_list **start, t_list **lst);
|
int parse_subshell(t_btree **ast, t_list **start, t_list **lst);
|
||||||
|
int parse_newline(t_btree **ast, t_list **start, t_list **lst);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/19 21:52:47 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 16:01:58 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
ls pwd
|
ls | wc -l > file1
|
||||||
yolo
|
cd ; ls
|
||||||
|
pwd ; echo "hello world"
|
||||||
|
|
|
||||||
6
42sh/sample/condition.sh
Normal file
6
42sh/sample/condition.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ sh exitzero.sh ]
|
||||||
|
then
|
||||||
|
echo "hello world"
|
||||||
|
fi
|
||||||
2
42sh/sample/exitzero.sh
Normal file
2
42sh/sample/exitzero.sh
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
ls
|
||||||
|
exit (0)
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/24 01:25:40 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 17:54:08 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/23 23:19:46 by ariard #+# #+# */
|
/* Created: 2017/01/23 23:19:46 by ariard #+# #+# */
|
||||||
/* Updated: 2017/01/24 01:25:21 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 17:54:12 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/24 01:02:50 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 17:33:09 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/30 17:08:55 by jhalford #+# #+# */
|
/* Created: 2016/11/30 17:08:55 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/19 23:12:09 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 16:02:48 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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/01/24 01:25:38 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 18:06:42 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,31 +17,47 @@ int shell_script()
|
||||||
t_list *token;
|
t_list *token;
|
||||||
t_list *head;
|
t_list *head;
|
||||||
t_btree *ast;
|
t_btree *ast;
|
||||||
t_list *tmp;
|
t_list *list_tmp;
|
||||||
|
t_list *tmp2;
|
||||||
|
|
||||||
token = NULL;
|
token = NULL;
|
||||||
head = NULL;
|
head = NULL;
|
||||||
ast = NULL;
|
ast = NULL;
|
||||||
tmp = data_singleton()->script.queue;
|
list_tmp = data_singleton()->script.queue;
|
||||||
while (tmp)
|
while (list_tmp)
|
||||||
{
|
{
|
||||||
if (ft_tokenize(&token, tmp->content , DEFAULT))
|
if (ft_tokenize(&token, list_tmp->content , DEFAULT))
|
||||||
return (1);
|
return (1);
|
||||||
if (!token)
|
if (!token)
|
||||||
return (0);
|
return (0);
|
||||||
if (ft_post_tokenize(&token, tmp->content))
|
if (ft_post_tokenize(&token, list_tmp->content))
|
||||||
return (1);
|
return (1);
|
||||||
tmp = tmp->next;
|
list_tmp = list_tmp->next;
|
||||||
ft_lst_merge(&head, token);
|
ft_lst_merge(&head, token);
|
||||||
token = NULL;
|
token = NULL;
|
||||||
}
|
}
|
||||||
DG("after post_tokenize");
|
DG("after post_tokenize");
|
||||||
token_print(head);
|
token_print(head);
|
||||||
return (0);
|
while (head)
|
||||||
if (ft_parse(&ast, &token))
|
{
|
||||||
|
if (ft_parse(&ast, &head))
|
||||||
return (1);
|
return (1);
|
||||||
btree_print(STDBUG, ast, &ft_putast);
|
ft_lsteadd(&list_tmp, ft_lstnew(ast, sizeof (*ast)));
|
||||||
|
ast = NULL;
|
||||||
|
ft_lst_delif(&head, head->content, &ft_addrcmp, &token_free);
|
||||||
|
}
|
||||||
|
tmp2 = list_tmp;
|
||||||
|
while (tmp2)
|
||||||
|
{
|
||||||
|
btree_print(STDBUG, tmp2->content, &ft_putast);
|
||||||
|
tmp2 = tmp2->next;
|
||||||
|
}
|
||||||
|
while (list_tmp)
|
||||||
|
{
|
||||||
|
ast = list_tmp->content;
|
||||||
if (ft_exec(&ast))
|
if (ft_exec(&ast))
|
||||||
return (1);
|
return (1);
|
||||||
|
list_tmp = list_tmp->next;
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/01/23 23:15:05 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 18:06:40 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -26,6 +26,7 @@ t_parser g_parser[] =
|
||||||
{TK_GREATAND, &parse_greatand},
|
{TK_GREATAND, &parse_greatand},
|
||||||
{TK_SUBSHELL, &parse_subshell},
|
{TK_SUBSHELL, &parse_subshell},
|
||||||
{TK_WORD, &parse_word},
|
{TK_WORD, &parse_word},
|
||||||
|
{TK_NEWLINE, NULL},
|
||||||
{0, 0},
|
{0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -45,7 +46,8 @@ int ft_parse(t_btree **ast, t_list **start)
|
||||||
}
|
}
|
||||||
while (g_parser[i].type)
|
while (g_parser[i].type)
|
||||||
{
|
{
|
||||||
if ((lst = ft_lst_find(*start, &g_parser[i].type, &token_cmp_type)))
|
if ((lst = ft_lst_find_until(*start, &g_parser[i].type,
|
||||||
|
&g_parser[12].type, &token_cmp_type)))
|
||||||
{
|
{
|
||||||
if (g_parser[i].f)
|
if (g_parser[i].f)
|
||||||
(*g_parser[i].f)(ast, start, &lst);
|
(*g_parser[i].f)(ast, start, &lst);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/20 16:23:53 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 16:06:00 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */
|
/* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/23 23:17:04 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 17:54:27 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/20 00:07:56 by ariard ### ########.fr */
|
/* Updated: 2017/01/24 17:54:40 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue