aboutsummaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse')
-rwxr-xr-x[-rw-r--r--]src/parse/cmd_parse.c3
-rwxr-xr-x[-rw-r--r--]src/parse/parse.c45
-rwxr-xr-xsrc/parse/redir_parse.c27
3 files changed, 65 insertions, 10 deletions
diff --git a/src/parse/cmd_parse.c b/src/parse/cmd_parse.c
index 07070a1..562cea3 100644..100755
--- a/src/parse/cmd_parse.c
+++ b/src/parse/cmd_parse.c
@@ -18,12 +18,13 @@ t_ast *parse_cmd(t_ast *ast, t_ftlst *rest)
new = rest->data;
if (ast == NULL)
{
+
ast = ast_new(AST_CMD);
ast->cmd_argv = ft_lstnew((t_token *)rest->data);
}
else
{
- new = ft_lstnew(rest->data);
+ new = ft_lstnew((t_token *)rest->data);
ft_lstpush_back(&ast->cmd_argv, (void *)new);
}
return (ast);
diff --git a/src/parse/parse.c b/src/parse/parse.c
index 4fc0aa7..bb19bea 100644..100755
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -15,6 +15,7 @@ t_ret *parse(t_ftlst *input)
t_ret *ret;
t_ret *first;
enum e_token_tag tag;
+ int i = 0;
if(!(ret = malloc(sizeof(t_ret) * 1)))
return(NULL);
@@ -26,18 +27,44 @@ t_ret *parse(t_ftlst *input)
while (ret->rest != NULL)
{
tag = ((t_token *)ret->rest->data)->tag;
- printf("%d\n", tag);
- if (parse_redir_true_false(tag))
- ;
if (parse_cmd_str_true_false(tag))
+ {
ret->ast = parse_cmd(ret->ast, ret->rest);
- ret->rest = ret->rest->next;
+ }
+ else if (parse_redir_true_false(tag))
+ {
+ ret->ast = parse_redir(ret->ast, ret->rest);
+ ret->rest = ret->rest->next;
+ if (ret->rest != NULL)
+ ret->ast = parse_redir(ret->ast, ret->rest);
+ printf("%s\n","ici" );
+ ret->rest = ret->rest->next;
+ if (ret->rest != NULL)
+ {
+ tag = ((t_token *)ret->rest->data)->tag;
+ if(tag & TAG_IS_STR & TAG_STICK)
+ ret->ast = parse_redir(ret->ast, ret->rest);
+ }
+ }
+ if (ret->rest != NULL)
+ ret->rest = ret->rest->next;
}
while(ret->ast->cmd_argv != NULL)
- {
- printf("%s\n", ((t_token *)ret->ast->cmd_argv->data)->content);
- ret->ast->cmd_argv = ret->ast->cmd_argv->next;
- }
- free(ret->ast);
+ {
+ printf("%s\n", ((t_token *)ret->ast->cmd_argv->data)->content);
+ ret->ast->cmd_argv = ret->ast->cmd_argv->next;
+ }
+ while(ret->ast->redirs != NULL)
+ {
+ if (i == 0)
+ {
+ printf("redir");
+ i++;
+ }
+ printf("%s\n", ((t_token *)ret->ast->redirs->data)->content);
+ ret->ast->redirs = ret->ast->redirs->next;
+ }
+ ast_destroy(ret->ast);
+ ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy);
return NULL;
}
diff --git a/src/parse/redir_parse.c b/src/parse/redir_parse.c
new file mode 100755
index 0000000..bdcb3ab
--- /dev/null
+++ b/src/parse/redir_parse.c
@@ -0,0 +1,27 @@
+
+#include "parser.h"
+
+int parse_redir_true_false(enum e_token_tag tag)
+{
+ if (tag & TAG_IS_REDIR)
+ return (1);
+ return (0);
+}
+
+t_ast *parse_redir(t_ast *ast, t_ftlst *rest)
+{
+ t_ftlst *new;
+
+ new = rest->data;
+ if (ast == NULL)
+ {
+ ast = ast_new(AST_CMD);
+ ast->redirs = ft_lstnew((t_token *)rest->data);
+ }
+ else
+ {
+ new = ft_lstnew((t_token *)rest->data);
+ ft_lstpush_back(&ast->redirs, (void *)new);
+ }
+ return (ast);
+}