parsing virtually finished exept heredoc

This commit is contained in:
Jack Halford 2016-11-24 23:11:07 +01:00
parent 2f2e7c03b1
commit aa456796ac
16 changed files with 61 additions and 75 deletions

View file

@ -26,11 +26,12 @@
# define TK_WORD 0x0100
# define TK_COMMAND 0x0200
# define TK_REDIR 0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20
# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
typedef long long t_type;
typedef enum e_lexstate t_lexstate;
typedef struct s_token t_token;
typedef struct s_data t_data;
typedef int t_lexer(t_list **alst,
char *str);

View file

@ -25,6 +25,8 @@
# include <sys/types.h>
# include <signal.h>
# define SHELL_NAME "minishell"
typedef enum e_qstate t_qstate;
typedef struct s_data t_data;

@ -1 +1 @@
Subproject commit a9043dc03b7b46d4644785b77bc38736481deedc
Subproject commit 2a60fb6dcefcf969d29c0c70f4da61a305f9ccf2

View file

@ -5,7 +5,9 @@ int exec_pipe(t_btree *ast)
int filedes[2];
pipe(filedes);
ft_debug();
dup2(filedes[1], 1);
ft_debug();
ft_exec(ast->left);
close(filedes[1]);
dup2(filedes[0], 0);

View file

@ -22,10 +22,7 @@ int ft_exec(t_btree *ast)
while (g_exec[i].type)
{
if (item->type == g_exec[i].type)
{
(*g_exec[i].f)(ast);
return (0);
}
return ((*g_exec[i].f)(ast));
i++;
}
return (0);

View file

@ -5,7 +5,7 @@ int lexer_greatand(t_list **alst, char *str)
t_token *token;
token = (*alst)->content;
token->type = GREATAND;
token->type = TK_GREATAND;
if (ft_isdigit(*str))
{
token_append(token, *str);

View file

@ -5,7 +5,7 @@ int lexer_lessand(t_list **alst, char *str)
t_token *token;
token = (*alst)->content;
token->type = LESSAND;
token->type = TK_LESSAND;
if (ft_isdigit(*str))
{
token_append(token, *str);

View file

@ -18,34 +18,41 @@ void ft_putast2(void *nodein)
node = nodein;
if (node->type == TK_SEMI)
ft_putendl(";");
ft_putendl("SEMI");
else if (node->type == TK_PIPE)
ft_putendl("|");
ft_putendl("PIPE");
else if (node->type == TK_COMMAND)
{
ft_putstr("COMMAND: ");
ft_putstr(node->u_data.sstr[0]);
/* ft_sstrprint(node->u_data.sstr, ','); */
/* char **sstr = node->u_data.sstr; */
/* while (*sstr) */
/* ft_printf("%s,", *sstr++); */
ft_sstrprint(node->u_data.sstr, ',');
ft_putchar('\n');
}
if (node->type | TK_REDIR)
else if (node->type & TK_REDIR)
{
ft_putnbr(node->u_data.redir.n);
if (node->type == TK_GREATAND || node->type == TK_LESSAND)
{
if (node->type == TK_GREATAND)
ft_putstr(">&:");
else
ft_putstr("<&:");
ft_putnbr(node->u_data.redir.u_word.fd);
if (node->u_data.redir.close)
ft_putstr(" (closed)");
}
else
{
if (node->type == TK_GREAT)
ft_putendl(">:");
else if (node->type == TK_LESS)
ft_putendl("<:");
ft_putstr("<:");
else if (node->type == TK_DGREAT)
ft_putendl(">>:");
ft_putstr(">>:");
else if (node->type == TK_DLESS)
ft_putendl("<<:");
else if (node->type == TK_GREATAND)
ft_putendl(">&:");
else if (node->type == TK_LESSAND)
ft_putendl("<&:");
ft_putstr("<<:");
ft_putstr(node->u_data.redir.u_word.word);
}
ft_putchar('\n');
}
else
ft_putendl("OTHER");

View file

@ -38,8 +38,8 @@ int main(void)
btree_apply_infix(ast, &ft_putast2);
/* ft_lstdel(&token, &token_free); */
token = NULL;
/* if (ft_exec(ast)) */
/* return (1); */
if (ft_exec(ast))
return (1);
}
return (0);

View file

@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_less.c :+: :+: :+: */
/* parse_dgreat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@ -26,11 +26,10 @@ int parse_dgreat(t_btree **ast, t_list **start, t_list **lst)
next_tok = (*lst)->next->content;
if (next_tok->type != TK_WORD)
return (1);
node->u_data.redir.n = ft_atoi(tok->data);
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
/* ft_lstdelone(lst, &token_free); */
/* ft_lstdelone(&(*lst)->next, &token_free); */
ft_parse(&(*ast)->left, start);
return (0);
}

View file

@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_less.c :+: :+: :+: */
/* parse_dless.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@ -19,7 +19,7 @@ int parse_dless(t_btree **ast, t_list **start, t_list **lst)
t_token *next_tok;
node = (*ast)->item;
node->type = TK_DGREAT;
node->type = TK_DLESS;
if (!(*lst)->next)
return (1);
tok = (*lst)->content;
@ -27,11 +27,8 @@ int parse_dless(t_btree **ast, t_list **start, t_list **lst)
if (next_tok->type != TK_WORD)
return (1);
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
/* ft_lst_delif(&start, lst->content, &ft_addrcmp, &token_free); */
/* ft_lst_delif(&start, lst->next->content, &ft_addrcmp, &token_free); */
/* ft_parse(&(*ast)->right, (*lst)->next->next); */
ft_lstdelone(lst, &token_free);
ft_lstdelone(&(*lst)->next, &token_free);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
return (0);
}

View file

@ -26,9 +26,8 @@ int parse_great(t_btree **ast, t_list **start, t_list **lst)
next_tok = (*lst)->next->content;
if (next_tok->type != TK_WORD)
return (1);
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
node->u_data.redir.n = ft_atoi(tok->data);
ft_printf("stored redir n=%i, word=%s\n", node->u_data.redir.n, node->u_data.redir.u_word.word);
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);

View file

@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_less.c :+: :+: :+: */
/* parse_greatand.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@ -16,22 +16,16 @@ int parse_greatand(t_btree **ast, t_list **start, t_list **lst)
{
t_astnode *node;
t_token *tok;
t_token *next_tok;
char *and;
node = (*ast)->item;
node->type = TK_GREATAND;
if (!(*lst)->next)
return (1);
tok = (*lst)->content;
next_tok = (*lst)->next->content;
if (next_tok->type != TK_WORD)
return (1);
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
/* ft_lst_delif(&start, lst->content, &ft_addrcmp, &token_free); */
/* ft_lst_delif(&start, lst->next->content, &ft_addrcmp, &token_free); */
/* ft_parse(&(*ast)->right, (*lst)->next->next); */
ft_lstdelone(lst, &token_free);
ft_lstdelone(&(*lst)->next, &token_free);
and = ft_strchr(tok->data, '&');
node->u_data.redir.u_word.fd = ft_atoi(and + 1);
node->u_data.redir.close =
tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
return (0);
}

View file

@ -26,11 +26,10 @@ int parse_less(t_btree **ast, t_list **start, t_list **lst)
next_tok = (*lst)->next->content;
if (next_tok->type != TK_WORD)
return (1);
node->u_data.redir.n = ft_atoi(tok->data);
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
/* ft_lstdelone(lst, &token_free); */
/* ft_lstdelone(&(*lst)->next, &token_free); */
ft_parse(&(*ast)->left, start);
return (0);
}

View file

@ -1,4 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
@ -17,22 +16,16 @@ int parse_lessand(t_btree **ast, t_list **start, t_list **lst)
{
t_astnode *node;
t_token *tok;
t_token *next_tok;
char *and;
node = (*ast)->item;
node->type = TK_DGREAT;
if (!(*lst)->next)
return (1);
node->type = TK_LESSAND;
tok = (*lst)->content;
next_tok = (*lst)->next->content;
if (next_tok->type != TK_WORD)
return (1);
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
/* ft_lst_delif(&start, lst->content, &ft_addrcmp, &token_free); */
/* ft_lst_delif(&start, lst->next->content, &ft_addrcmp, &token_free); */
/* ft_parse(&(*ast)->right, (*lst)->next->next); */
ft_lstdelone(lst, &token_free);
ft_lstdelone(&(*lst)->next, &token_free);
and = ft_strchr(tok->data, '&');
node->u_data.redir.u_word.fd = ft_atoi(and + 1);
node->u_data.redir.close =
tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
return (0);
}

View file

@ -21,11 +21,7 @@ int parse_word(t_btree **ast, t_list **start, t_list **lst)
token = (*lst)->content;
node = (*ast)->item;
node->type = TK_COMMAND;
ft_printf("adding '%s' to sstr\n", token->data);
node->u_data.sstr = ft_sstradd(node->u_data.sstr, token->data);
/* ft_printf("added '%s'\n", node->u_data.sstr[0]); */
ft_sstrprint(node->u_data.sstr, ',');
ft_putchar('\n');
ft_parse(ast, &(*lst)->next);
ft_lstdelone(lst, &token_free);
return (0);