redirection ok, further test needed
This commit is contained in:
parent
21245cac3b
commit
e675eceb87
18 changed files with 67 additions and 36 deletions
16
42sh/fi
Normal file
16
42sh/fi
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
42sh
|
||||
Makefile
|
||||
STDBUG
|
||||
TESTSHELL
|
||||
donovan_segaults_06-02
|
||||
fi
|
||||
file
|
||||
includes
|
||||
libft
|
||||
objs
|
||||
parser_init.c
|
||||
pdf
|
||||
sample
|
||||
src
|
||||
test_framework.sh
|
||||
update_makefile.sh
|
||||
31
42sh/file
31
42sh/file
|
|
@ -1,16 +1,15 @@
|
|||
total 576
|
||||
-rwxr-xr-x 1 ariard 2016_paris 249036 Mar 5 17:14 42sh
|
||||
-rw-r--r-- 1 ariard 2016_paris 8133 Mar 5 16:46 Makefile
|
||||
-rw-r--r-- 1 ariard 2016_paris 16999 Mar 5 17:15 STDBUG
|
||||
drwxr-xr-x 7 ariard 2016_paris 238 Mar 4 14:53 TESTSHELL
|
||||
-rw-r--r-- 1 ariard 2016_paris 4396 Mar 4 14:53 donovan_segaults_06-02
|
||||
-rw-r--r-- 1 ariard 2016_paris 0 Mar 5 17:15 file
|
||||
drwxr-xr-x 16 ariard 2016_paris 544 Mar 5 16:46 includes
|
||||
drwxr-xr-x 12 ariard 2016_paris 408 Mar 5 16:50 libft
|
||||
drwxr-xr-x 13 ariard 2016_paris 442 Mar 5 16:50 objs
|
||||
-rw-r--r-- 1 ariard 2016_paris 0 Mar 4 14:53 parser_init.c
|
||||
drwxr-xr-x 6 ariard 2016_paris 204 Mar 4 14:53 pdf
|
||||
drwxr-xr-x 29 ariard 2016_paris 986 Mar 4 14:53 sample
|
||||
drwxr-xr-x 14 ariard 2016_paris 476 Mar 4 14:53 src
|
||||
-rwxr-xr-x 1 ariard 2016_paris 890 Mar 4 14:53 test_framework.sh
|
||||
-rwxr-xr-x 1 ariard 2016_paris 690 Mar 4 14:53 update_makefile.sh
|
||||
42sh
|
||||
Makefile
|
||||
STDBUG
|
||||
TESTSHELL
|
||||
donovan_segaults_06-02
|
||||
file
|
||||
includes
|
||||
libft
|
||||
objs
|
||||
parser_init.c
|
||||
pdf
|
||||
sample
|
||||
src
|
||||
test_framework.sh
|
||||
update_makefile.sh
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ int add_one_func(t_btree **ast, t_list **lst);
|
|||
int add_pipe(t_btree **ast, t_list **lst);
|
||||
int add_var(t_btree **ast, t_list **lst);
|
||||
int add_null(t_btree **ast, t_list **lst);
|
||||
int add_ionumbr(t_btree **ast, t_list **lst);
|
||||
int add_ionumber(t_btree **ast, t_list **lst);
|
||||
|
||||
int isloop(t_btree **ast, t_list **lst);
|
||||
int isloop_condition(t_btree **ast, t_list **lst);
|
||||
|
|
@ -158,7 +158,7 @@ extern t_distrostree g_distrostree[];
|
|||
|
||||
struct s_redir
|
||||
{
|
||||
t_flag type;
|
||||
t_type type;
|
||||
int n;
|
||||
char *word;
|
||||
/* int close; */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/04 19:50:36 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:31:28 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,7 +33,6 @@ typedef struct s_redir t_redir;
|
|||
typedef struct s_cmd t_cmd;
|
||||
typedef union u_astdata t_astdata;
|
||||
typedef union u_word t_word;
|
||||
typedef long long t_type;
|
||||
|
||||
typedef int t_condition;
|
||||
typedef struct s_job t_job;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 0270e3651474c1b20bb0d6873f5c6188ccf43897
|
||||
Subproject commit 318efc7cfb7b7cc9d3714fa19fd2be7382b6adec
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 15:42:36 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:03:36 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/04 17:16:30 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:01:32 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 18:08:57 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:04:17 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 19:40:54 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:12:23 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,11 +33,14 @@ int process_redirect(t_process *p)
|
|||
while (redirs)
|
||||
{
|
||||
redir = redirs->content;
|
||||
DG("redir type :%s", read_state(redir->type));
|
||||
DG("redir word : %s", redir->word);
|
||||
if (redir->n > 9)
|
||||
return (bad_fd(redir->n));
|
||||
i = 0;
|
||||
while (g_redirmap[i].type)
|
||||
{
|
||||
DG("process redirect");
|
||||
if (g_redirmap[i].type == redir->type)
|
||||
{
|
||||
if ((g_redirmap[i].f)(redir))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 19:35:02 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/06 14:58:57 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,6 +18,7 @@ int redirect_great(t_redir* redir)
|
|||
int fdnew;
|
||||
|
||||
fdnew = redir->n;
|
||||
DG("redir great");
|
||||
if ((fdold = open(redir->word,
|
||||
O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 18:11:13 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:05:40 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,6 +18,7 @@ int redirect_less(t_redir *redir)
|
|||
int fdnew;
|
||||
|
||||
fdnew = redir->n;
|
||||
DG("redirect less");
|
||||
if ((fdold = open(redir->word, O_RDONLY)) < 0)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: no such file or directory: %s{eoc}\n",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/04 20:42:13 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/05 17:30:19 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:11:04 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ int iscase_pattern(t_btree **ast, t_list **lst)
|
|||
t_astnode *node;
|
||||
t_token *token;
|
||||
|
||||
DG(" add pattern");
|
||||
// DG(" add pattern");
|
||||
node = NULL;
|
||||
token = (*lst)->content;
|
||||
if (*ast)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/05 16:34:17 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:57:48 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,6 +27,7 @@ t_distrostree g_distrostree[] =
|
|||
{&iscase, &add_case_cmd},
|
||||
{&issubshell, &add_subshell_cmd},
|
||||
{&isfunc, &add_func_cmd},
|
||||
{&isionumber, &add_ionumber},
|
||||
{&isnull, &add_null},
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/05 18:19:26 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:56:00 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -38,6 +38,7 @@ int add_ionumber(t_btree **ast, t_list **lst)
|
|||
t_token *token;
|
||||
t_redir redir;
|
||||
|
||||
DG("add io_number");
|
||||
if (!*ast)
|
||||
gen_node(ast);
|
||||
token = (*lst)->content;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/05 18:14:00 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:54:24 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -67,6 +67,8 @@ int add_redir_word(t_btree **ast, t_list **lst)
|
|||
{
|
||||
DG("add file");
|
||||
redir = (ft_lstlast(node->data.cmd.redir))->content;
|
||||
DG("now redir.type :%s", read_state(redir->type));
|
||||
DG("n is ? : %d", redir->n);
|
||||
if (redir->type == TK_DLESS)
|
||||
redir->word = NULL;
|
||||
else
|
||||
|
|
@ -80,6 +82,7 @@ int add_redir_type(t_btree **ast, t_list **lst)
|
|||
t_astnode *node;
|
||||
t_token *token;
|
||||
t_redir redir;
|
||||
t_redir *temp;
|
||||
|
||||
if (!*ast)
|
||||
gen_node(ast);
|
||||
|
|
@ -87,11 +90,17 @@ int add_redir_type(t_btree **ast, t_list **lst)
|
|||
node = (*ast)->item;
|
||||
if (!(node->type == TK_IO_NUMBER))
|
||||
{
|
||||
DG("add redir");
|
||||
redir.n = (token->type == TK_LESS || token->type == TK_DLESS
|
||||
|| token->type == TK_LESSAND) ? STDIN : STDOUT;
|
||||
redir.type = token->type;
|
||||
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = (ft_lstlast(node->data.cmd.redir))->content;
|
||||
temp->type = token->type;
|
||||
}
|
||||
node->type = REDIR;
|
||||
redir.type = token->type;
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/05 15:04:14 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/06 15:55:07 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,6 +21,7 @@ t_treematch g_treematch[] =
|
|||
{TK_LESS, &add_cmd},
|
||||
{TK_DGREAT, &add_cmd},
|
||||
{TK_DLESS, &add_cmd},
|
||||
{TK_IO_NUMBER, &add_cmd},
|
||||
{TK_OR_IF, &add_sep},
|
||||
{TK_AND_IF, &add_sep},
|
||||
{TK_AMP, &add_sep},
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
|||
while (*token)
|
||||
{
|
||||
produce_sym(&parser->stack, parser->new_sym, token);
|
||||
DG("new sym %s", read_state(*parser->new_sym));
|
||||
// DG("new sym %s", read_state(*parser->new_sym));
|
||||
if (eval_sym(&parser->stack, *parser->new_sym))
|
||||
return ((parser->state = ERROR));
|
||||
else
|
||||
|
|
@ -52,7 +52,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
|||
else
|
||||
parser->state = UNDEFINED;
|
||||
build_tree(ast, token);
|
||||
// btree_print(STDBUG, *ast, &ft_putast);
|
||||
btree_print(STDBUG, *ast, &ft_putast);
|
||||
if ((end_instruction(&parser->stack) && !(*token)->next))
|
||||
insert_linebreak(token);
|
||||
else
|
||||
|
|
|
|||
0
42sh/yolo
Normal file
0
42sh/yolo
Normal file
Loading…
Reference in a new issue