qMerge branch 'pda_execution' of github.com:jzck/42sh into pda_execution

This commit is contained in:
william 2017-03-05 17:18:57 +01:00
commit 0d5408b114
21 changed files with 85 additions and 107 deletions

View file

@ -179,7 +179,7 @@ lexer/lexer_assignement_word.c\
lexer/lexer_backslash.c\
lexer/lexer_bquote.c\
lexer/lexer_comment.c\
lexer/lexer_curly_brackets.c\
lexer/lexer_curly_braces.c\
lexer/lexer_default.c\
lexer/lexer_delim.c\
lexer/lexer_dless.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:14:25 by jhalford ### ########.fr */
/* Updated: 2017/03/05 15:19:44 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:35:49 by jhalford ### ########.fr */
/* Updated: 2017/03/05 16:28:37 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:58:18 by jhalford ### ########.fr */
/* Updated: 2017/03/05 16:28:17 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,8 +23,8 @@
| TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE)
enum e_lexstate
{
PAREN,
DEFAULT,
PAREN,
NEWLINE,
DELIM,
SEP,
@ -111,7 +111,7 @@ int lexer_dquote(t_list **alst, t_lexer *lexer);
int lexer_bquote(t_list **alst, t_lexer *lexer);
int lexer_backslash(t_list **alst, t_lexer *lexer);
int lexer_paren(t_list **alst, t_lexer *lexer);
int lexer_curly_brackets(t_list **alst, t_lexer *lexer);
int lexer_curly_braces(t_list **alst, t_lexer *lexer);
int lexer_assignement_word(t_list **alst, t_lexer *lexer);
int lexer_comment(t_list **alst, t_lexer *lexer);
int lexer_end(t_list **alst, t_lexer *lexer);

@ -1 +1 @@
Subproject commit 282df927230b2c6da253f8fc9d7ca0eedc0fe30c
Subproject commit 0270e3651474c1b20bb0d6873f5c6188ccf43897

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
/* Updated: 2017/03/04 17:09:11 by ariard ### ########.fr */
/* Updated: 2017/03/05 15:58:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,5 +33,4 @@ void ast_free(void *data, size_t content_size)
}
// if (node->type == WORDLIST)
// do clear
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:14:10 by jhalford ### ########.fr */
/* Updated: 2017/03/05 15:42:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:30:04 by wescande ### ########.fr */
/* Updated: 2017/03/05 16:32:22 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,13 +14,11 @@
int launch_process(t_process *p)
{
// t_exec *exec;
int pid;
// exec = &data_singleton()->exec;
DG("gonna launch [%s]", p->av[0]);
DG("fdin=[%i]", p->fdin);
DG("fdout=[%i]", p->fdout);
/* DG("gonna launch [%s]", p->av[0]); */
/* DG("fdin=[%i]", p->fdin); */
/* DG("fdout=[%i]", p->fdout); */
if (p->attributes & PROCESS_BUILTIN && IS_PIPESINGLE(*p))
{
if (process_redirect(p))
@ -28,41 +26,38 @@ int launch_process(t_process *p)
set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env), 1);
return (1);
}
else
p->attributes &= ~PROCESS_STATE_MASK;
p->attributes |= PROCESS_RUNNING;
if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT)
&& access(p->path, X_OK) == -1)
{
p->attributes &= ~PROCESS_STATE_MASK;
p->attributes |= PROCESS_RUNNING;
if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT)
&& access(p->path, X_OK) == -1)
{
ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->av[0]);
set_exitstatus(126, 1);
return (1);
}
pid = fork();
if (pid == 0)
{
if (p->attributes & PROCESS_UNKNOWN)
{
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]);
exit(127);
/* set_exitstatus(127, 1); */
}
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
(*p->execf)(p->path, p->av, data_singleton()->env);
exit(43);
}
else if (pid > 0)
{
p->pid = pid;
process_setgroup(p, pid);
return (0);
}
else if (pid == -1)
ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->av[0]);
set_exitstatus(126, 1);
return (1);
}
pid = fork();
if (pid == 0)
{
if (p->attributes & PROCESS_UNKNOWN)
{
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]);
exit(127);
}
process_setgroup(p, 0);
process_setsig();
DG("gonna redirect");
if (process_redirect(p))
exit (1);
(*p->execf)(p->path, p->av, data_singleton()->env);
ft_dprintf(2, "{red}%s: internal excve error{eoc}\n", SHELL_NAME);
}
else if (pid > 0)
{
p->pid = pid;
process_setgroup(p, pid);
return (0);
}
else if (pid == -1)
ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:49:27 by jhalford ### ########.fr */
/* Updated: 2017/03/05 15:59:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 18:12:57 by ariard #+# #+# */
/* Updated: 2017/03/03 20:02:24 by ariard ### ########.fr */
/* Updated: 2017/03/05 15:58:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,11 +19,14 @@ void redir_free(void *data, size_t content_size)
(void)content_size;
redir = data;
if (redir->type == TK_GREAT || redir->type == TK_LESS || redir->type == TK_DGREAT)
{
/* DG("word.word: %s", redir->word.word); */
ft_strdel(&redir->word.word);
else
redir->word.fd = 0;
redir->type = 0;
redir->n = 0;
redir->close = 1;
}
/* else */
/* redir->word.fd = 0; */
/* redir->type = 0; */
/* redir->n = 0; */
/* redir->close = 1; */
free(redir);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:18:57 by jhalford ### ########.fr */
/* Updated: 2017/03/05 15:42:45 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/02 17:48:50 by jhalford ### ########.fr */
/* Updated: 2017/03/05 16:00:27 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,6 +20,6 @@ void process_free(void *content, size_t content_size)
p = content;
ft_strdel(&p->path);
ft_sstrfree(p->av);
ft_lstdel(&p->redirs, ft_lst_cfree);
/* ft_lstdel(&p->redirs, ft_lst_cfree); */
free(p);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 17:39:45 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:40:24 by jhalford ### ########.fr */
/* Updated: 2017/03/05 16:27:04 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

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

View file

@ -1,46 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_curly_brackets.c :+: :+: :+: */
/* lexer_curly_braces.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 21:24:50 by ariard #+# #+# */
/* Updated: 2017/02/24 21:48:52 by ariard ### ########.fr */
/* Created: 2017/03/05 16:29:35 by jhalford #+# #+# */
/* Updated: 2017/03/05 16:29:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int lexer_curly_brackets(t_list **alst, t_lexer *lexer)
int lexer_curly_braces(t_list **alst, t_lexer *lexer)
{
t_token *token;
t_list **lst;
t_token *token;
DG("lexer curly brackets");
lst = alst;
if (*alst)
{
token = (*alst)->content;
if (token->type)
lst = &(*alst)->next;
}
token = token_init();
*lst = ft_lstnew(token, sizeof(*token));
token = (*lst)->content;
token = (*alst)->content;
if (token->type)
lexer_lex(&(*alst)->next, lexer);
if (lexer->str[lexer->pos] == '{')
{
DG("lbrace");
token->type = TK_LBRACE;
push(&lexer->stack, CURLY_BRACKETS);
push(&lexer->stack, PAREN);
}
else if (lexer->stack && *(int*)lexer->stack->content == CURLY_BRACKETS)
else if (get_lexer_stack(*lexer))
{
DG("rbrace");
token->type = TK_RBRACE;
pop(&lexer->stack);
}
lexer->pos++;
lexer->state = DEFAULT;
return (lexer_lex(&(*lst)->next, lexer));
return (lexer_lex(&(*alst)->next, lexer));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:55:57 by jhalford ### ########.fr */
/* Updated: 2017/03/05 16:20:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
/* Updated: 2017/03/04 20:51:21 by ariard ### ########.fr */
/* Updated: 2017/03/05 16:28:15 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,8 +14,8 @@
int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
{
&lexer_paren,
&lexer_default,
&lexer_paren,
&lexer_newline,
&lexer_delim,
&lexer_sep,
@ -31,7 +31,7 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
&lexer_bquote,
&lexer_bquote,
&lexer_backslash,
&lexer_curly_brackets,
&lexer_curly_braces,
&lexer_assignement_word,
&lexer_comment,
&lexer_end,

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 17:37:15 by jhalford #+# #+# */
/* Updated: 2017/03/05 14:46:43 by jhalford ### ########.fr */
/* Updated: 2017/03/05 16:29:28 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,29 +15,21 @@
int lexer_paren(t_list **alst, t_lexer *lexer)
{
t_token *token;
t_list **lst;
lst = alst;
if (*alst)
{
token = (*alst)->content;
if (token->type)
lst = &(*alst)->next;
}
token = token_init();
*lst = ft_lstnew(token, sizeof(*token));
token = (*lst)->content;
token = (*alst)->content;
if (token->type)
lexer_lex(&(*alst)->next, lexer);
if (lexer->str[lexer->pos] == '(')
{
token->type = TK_PAREN_OPEN;
push(&lexer->stack, PAREN);
}
else if (lexer->stack && *(int*)lexer->stack->content == PAREN)
else if (get_lexer_stack(*lexer))
{
token->type = TK_PAREN_CLOSE;
pop(&lexer->stack);
}
lexer->pos++;
lexer->state = DEFAULT;
return (lexer_lex(&(*lst)->next, lexer));
return (lexer_lex(&(*alst)->next, lexer));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */
/* Updated: 2017/03/01 16:25:30 by ariard ### ########.fr */
/* Updated: 2017/03/05 16:27:58 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,6 @@ void token_print(t_list *lst)
while (lst)
{
DG("token print");
if (lst->content)
token = lst->content;
if (token->type)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:42:31 by wescande ### ########.fr */
/* Updated: 2017/03/05 16:32:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

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