subshell doing

This commit is contained in:
Antoine Riard 2017-03-05 19:21:00 +01:00
commit b23c28bf2f
15 changed files with 59 additions and 73 deletions

View file

@ -178,7 +178,6 @@ lexer/insert_newline.c\
lexer/lexer_assignement_word.c\ lexer/lexer_assignement_word.c\
lexer/lexer_backslash.c\ lexer/lexer_backslash.c\
lexer/lexer_bquote.c\ lexer/lexer_bquote.c\
lexer/lexer_comment.c\
lexer/lexer_curly_braces.c\ lexer/lexer_curly_braces.c\
lexer/lexer_default.c\ lexer/lexer_default.c\
lexer/lexer_delim.c\ lexer/lexer_delim.c\

View file

@ -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/03/05 16:28:17 by jhalford ### ########.fr */ /* Updated: 2017/03/05 17:29:09 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -42,7 +42,6 @@ enum e_lexstate
BACKSLASH, BACKSLASH,
CURLY_BRACKETS, CURLY_BRACKETS,
ASSIGNEMENT_WORD, ASSIGNEMENT_WORD,
COMMENT,
END, END,
}; };

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/03/05 16:32:22 by jhalford ### ########.fr */ /* Updated: 2017/03/05 18:08:57 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -45,11 +45,12 @@ int launch_process(t_process *p)
} }
process_setgroup(p, 0); process_setgroup(p, 0);
process_setsig(); process_setsig();
DG("gonna redirect");
if (process_redirect(p)) if (process_redirect(p))
exit (1); exit (1);
if (p->attributes & PROCESS_BUILTIN)
exit((*p->execf)(p->path, p->av, data_singleton()->env));
(*p->execf)(p->path, p->av, data_singleton()->env); (*p->execf)(p->path, p->av, data_singleton()->env);
ft_dprintf(2, "{red}%s: internal excve error{eoc}\n", SHELL_NAME); ft_dprintf(2, "{red}%s: internal execve error on %s{eoc}\n", SHELL_NAME, p->av[0]);
} }
else if (pid > 0) else if (pid > 0)
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
/* Updated: 2017/03/03 16:32:15 by jhalford ### ########.fr */ /* Updated: 2017/03/05 18:09:31 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */ /* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
/* Updated: 2017/03/03 16:45:40 by jhalford ### ########.fr */ /* Updated: 2017/03/05 18:07:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,7 @@
char *command_getoutput(char *command) char *command_getoutput(char *command)
{ {
return (command); return (ft_strdup(command));
/* int fds[2]; */ /* int fds[2]; */
/* t_btree *ast; */ /* t_btree *ast; */
/* t_astnode item; */ /* t_astnode item; */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ /* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
/* Updated: 2017/03/05 16:28:14 by jhalford ### ########.fr */ /* Updated: 2017/03/05 17:29:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,8 +20,6 @@ t_lexstate get_state_global(t_lexer *lexer)
DG("check, c=%c", lexer->str[lexer->pos]); DG("check, c=%c", lexer->str[lexer->pos]);
if (ft_is_delim(c)) if (ft_is_delim(c))
return (DELIM); return (DELIM);
else if (c == '#')
return (COMMENT);
else if (c == '&' || c == ';' || c == '|') else if (c == '&' || c == ';' || c == '|')
return (SEP); return (SEP);
else if (c == '\\') else if (c == '\\')

View file

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_comment.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/07 12:15:59 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:31:17 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
int lexer_comment(t_list **alst, t_lexer *lexer)
{
// t_token *token;
// token = (*alst)->content;
if (lexer->str[lexer->pos] == '\n')
return (lexer_lex(&(*alst)->next, lexer));
return (lexer_comment(alst, lexer));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ /* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */
/* Updated: 2017/02/20 20:52:24 by ariard ### ########.fr */ /* Updated: 2017/03/05 17:09:20 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,13 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_end.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */
/* Updated: 2017/03/05 17:29:17 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_end(t_list **alst, t_lexer *lexer) int lexer_end(t_list **alst, t_lexer *lexer)
{ {
t_token *token; t_token *token;
if ((*alst && (lexer->state == QUOTE if ((*alst && (lexer->state == QUOTE || lexer->state == DQUOTE
|| lexer->state == DQUOTE || lexer->state == BQUOTE)) || get_lexer_stack(*lexer) == DLESS)
|| lexer->state == BQUOTE))
|| get_lexer_stack(*lexer) == DLESS)
{ {
ft_strappend(&lexer->str, (char[]){'\n', 0}); ft_strappend(&lexer->str, (char[]){'\n', 0});
lexer->pos++; lexer->pos++;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */ /* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */
/* Updated: 2017/02/25 20:12:58 by ariard ### ########.fr */ /* Updated: 2017/03/05 18:20:02 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,10 +36,7 @@ int lexer_great(t_list **alst, t_lexer *lexer)
lexer->state = DEFAULT; lexer->state = DEFAULT;
return (lexer_lex(&(*alst)->next, lexer)); return (lexer_lex(&(*alst)->next, lexer));
} }
else token->type = TK_GREAT;
{ lexer->state = DEFAULT;
token->type = TK_GREAT; return (lexer_lex(&(*alst)->next, lexer));
lexer->state = DEFAULT;
return (lexer_lex(&(*alst)->next, lexer));
}
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */ /* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */
/* Updated: 2017/02/25 20:11:03 by ariard ### ########.fr */ /* Updated: 2017/03/05 18:23:55 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,19 +18,22 @@ int lexer_greatand(t_list **alst, t_lexer *lexer)
token = (*alst)->content; token = (*alst)->content;
token->type = TK_GREATAND; token->type = TK_GREATAND;
if (ft_isdigit(lexer->str[lexer->pos])) /* if (ft_isdigit(lexer->str[lexer->pos]))
{ {
token_append(token, lexer, 0, 0); // token_append(token, lexer, 0, 0);
lexer->pos++; // lexer->pos++;
return (lexer_greatand(alst, lexer)); // DG();
}
else if (lexer->str[lexer->pos] == '-')
{
token_append(token, lexer, 0, 0);
lexer->pos++;
lexer->state = DEFAULT; lexer->state = DEFAULT;
return (lexer_lex(&(*alst)->next, lexer)); return (lexer_lex(&(*alst)->next, lexer));
} }
else if (lexer->str[lexer->pos] == '-')
{
// token_append(token, lexer, 0, 0);
// lexer->pos++;
lexer->state = DEFAULT;
return (lexer_lex(&(*alst)->next, lexer));
}*/
lexer->state = DEFAULT; lexer->state = DEFAULT;
return (lexer_lex(alst, lexer)); return (lexer_lex(&(*alst)->next, lexer));
//return (lexer_lex(alst, lexer));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */ /* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */
/* Updated: 2017/02/25 20:11:17 by ariard ### ########.fr */ /* Updated: 2017/03/05 18:19:48 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -37,10 +37,7 @@ int lexer_less(t_list **alst, t_lexer *lexer)
ft_lsteadd(&lexer->heredoc_stack, ft_lstnew(alst, sizeof(alst))); ft_lsteadd(&lexer->heredoc_stack, ft_lstnew(alst, sizeof(alst)));
return (lexer_lex(&(*alst)->next, lexer)); return (lexer_lex(&(*alst)->next, lexer));
} }
else token->type = TK_LESS;
{ lexer->state = DEFAULT;
token->type = TK_LESS; return (lexer_lex(&(*alst)->next, lexer));
lexer->state = DEFAULT;
return (lexer_lex(&(*alst)->next, lexer));
}
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */ /* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */
/* Updated: 2017/02/25 20:11:10 by ariard ### ########.fr */ /* Updated: 2017/03/05 18:05:39 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,11 +18,14 @@ int lexer_lessand(t_list **alst, t_lexer *lexer)
token = (*alst)->content; token = (*alst)->content;
token->type = TK_LESSAND; token->type = TK_LESSAND;
if (ft_isdigit(lexer->str[lexer->pos])) lexer->state = DEFAULT;
return (lexer_lex(&(*alst)->next, lexer));
/* if (ft_isdigit(lexer->str[lexer->pos]))
{ {
token_append(token, lexer, 0, 0); token_append(token, lexer, 0, 0);
lexer->pos++; lexer->pos++;
return (lexer_lessand(alst, lexer)); lexer->state = DEFAULT;
return (lexer_lex(&(*alst)->next, lexer));
} }
else if (lexer->str[lexer->pos] == '-') else if (lexer->str[lexer->pos] == '-')
{ {
@ -32,5 +35,5 @@ int lexer_lessand(t_list **alst, t_lexer *lexer)
return (lexer_lex(&(*alst)->next, lexer)); return (lexer_lex(&(*alst)->next, lexer));
} }
lexer->state = DEFAULT; lexer->state = DEFAULT;
return (lexer_lex(alst, lexer)); return (lexer_lex(alst, lexer));*/
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
/* Updated: 2017/03/05 16:49:13 by ariard ### ########.fr */ /* Updated: 2017/03/05 19:20:27 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,7 +33,6 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
&lexer_backslash, &lexer_backslash,
&lexer_curly_braces, &lexer_curly_braces,
&lexer_assignement_word, &lexer_assignement_word,
&lexer_comment,
&lexer_end, &lexer_end,
}; };
@ -51,7 +50,10 @@ int lexer_lex(t_list **alst, t_lexer *lexer)
{ {
t_token *token; t_token *token;
if (lexer->str[lexer->pos] == 0) if (lexer->str[lexer->pos] == 0
|| (lexer->str[lexer->pos] == '#'
&& lexer->state != QUOTE
&& lexer->state != DQUOTE))
return (lexer_end(alst, lexer)); return (lexer_end(alst, lexer));
if (!*alst) if (!*alst)
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */ /* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */
/* Updated: 2017/03/05 16:28:38 by jhalford ### ########.fr */ /* Updated: 2017/03/05 17:45:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */