redir io number seems good
This commit is contained in:
parent
1086d95d89
commit
cba548d0ae
14 changed files with 81 additions and 49 deletions
|
|
@ -239,6 +239,7 @@ parser/add_redir.c\
|
|||
parser/add_sep.c\
|
||||
parser/add_subshell.c\
|
||||
parser/add_var.c\
|
||||
parser/add_number.c\
|
||||
parser/aggregate_sym.c\
|
||||
parser/build_tree.c\
|
||||
parser/error_syntax.c\
|
||||
|
|
|
|||
|
|
@ -125,6 +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 isloop(t_btree **ast, t_list **lst);
|
||||
int isloop_condition(t_btree **ast, t_list **lst);
|
||||
|
|
@ -141,6 +142,7 @@ int isdir_sep(t_btree **ast, t_list **list);
|
|||
int isdir_word(t_btree **ast, t_list **list);
|
||||
int isvar(t_btree **ast, t_list **list);
|
||||
int isnull(t_btree **ast, t_list **list);
|
||||
int isionumber(t_btree **ast, t_list **lst);
|
||||
|
||||
int join_ast(t_btree **ast, t_btree **new_node);
|
||||
int gen_node(t_btree **ast);
|
||||
|
|
@ -154,17 +156,11 @@ struct s_distrostree
|
|||
|
||||
extern t_distrostree g_distrostree[];
|
||||
|
||||
union u_word
|
||||
{
|
||||
char *word;
|
||||
int fd;
|
||||
};
|
||||
|
||||
struct s_redir
|
||||
{
|
||||
t_flag type;
|
||||
int n;
|
||||
t_word word;
|
||||
char *word;
|
||||
int close;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 17:02:27 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/05 18:05:43 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ void read_redir(void *data)
|
|||
t_redir *redir;
|
||||
|
||||
redir = data;
|
||||
DG("file : [%s]", redir->word.word);
|
||||
DG("file : [%s]", redir->word);
|
||||
}
|
||||
|
||||
void ast_free(void *data, size_t content_size)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/03 18:12:57 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/05 15:58:13 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/05 18:06:24 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,11 +20,9 @@ void redir_free(void *data, size_t 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);
|
||||
ft_strdel(&redir->word);
|
||||
}
|
||||
/* else */
|
||||
/* redir->word.fd = 0; */
|
||||
/* redir->type = 0; */
|
||||
/* redir->n = 0; */
|
||||
/* redir->close = 1; */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:07:37 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/06 22:27:10 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/05 18:10:36 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ int redirect_dgreat(t_redir *redir)
|
|||
int fdnew;
|
||||
|
||||
fdnew = redir->n;
|
||||
if ((fdold = open(redir->word.word,
|
||||
if ((fdold = open(redir->word,
|
||||
O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0)
|
||||
{
|
||||
DG("open errno=%i", errno);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ int redirect_dless(t_redir *redir)
|
|||
char *str;
|
||||
|
||||
pipe(fds);
|
||||
str = redir->word.word;
|
||||
str = redir->word;
|
||||
write(fds[PIPE_WRITE], str, ft_strlen(str));
|
||||
close(fds[PIPE_WRITE]);
|
||||
dup2(fds[PIPE_READ], 0);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/06 22:42:05 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/05 18:07:25 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ int redirect_great(t_redir* redir)
|
|||
int fdnew;
|
||||
|
||||
fdnew = redir->n;
|
||||
if ((fdold = open(redir->word.word,
|
||||
if ((fdold = open(redir->word,
|
||||
O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
||||
{
|
||||
DG("open errno=%i", errno);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/07 17:54:40 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/05 18:12:26 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,7 +17,11 @@ int redirect_greatand(t_redir *redir)
|
|||
int fdold;
|
||||
int fdnew;
|
||||
|
||||
(void)redir;
|
||||
(void)fdold;
|
||||
(void)fdnew;
|
||||
DG("redir greatand");
|
||||
/*
|
||||
if (redir->close)
|
||||
{
|
||||
close(redir->n);
|
||||
|
|
@ -33,5 +37,6 @@ int redirect_greatand(t_redir *redir)
|
|||
dup2_close(fdold, fdnew);
|
||||
else
|
||||
return (bad_fd(fdold));
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/20 20:42:53 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/05 18:11:13 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,10 +18,10 @@ int redirect_less(t_redir *redir)
|
|||
int fdnew;
|
||||
|
||||
fdnew = redir->n;
|
||||
if ((fdold = open(redir->word.word, O_RDONLY)) < 0)
|
||||
if ((fdold = open(redir->word, O_RDONLY)) < 0)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: no such file or directory: %s{eoc}\n",
|
||||
SHELL_NAME, redir->word.word);
|
||||
SHELL_NAME, redir->word);
|
||||
exit (1);
|
||||
}
|
||||
dup2(fdold, fdnew);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/07 17:54:57 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/05 18:13:11 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,6 +17,10 @@ int redirect_lessand(t_redir *redir)
|
|||
int fdold;
|
||||
int fdnew;
|
||||
|
||||
(void)redir;
|
||||
(void)fdold;
|
||||
(void)fdnew;
|
||||
/*
|
||||
if (redir->close)
|
||||
{
|
||||
close(redir->n);
|
||||
|
|
@ -35,5 +39,6 @@ int redirect_lessand(t_redir *redir)
|
|||
}
|
||||
else
|
||||
return (bad_fd(fdold));
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 17:21:51 by ariard ### ########.fr */
|
||||
>>>>>>> origin/pda_execution
|
||||
/* Updated: 2017/03/05 18:03:34 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/04 20:42:13 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/05 16:47:15 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/05 17:30:19 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
40
42sh/src/parser/add_number.c
Normal file
40
42sh/src/parser/add_number.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* add_number.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/05 17:28:31 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/05 18:15:40 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int isionumber(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_token *token;
|
||||
|
||||
(void)ast;
|
||||
token = (*lst)->content;
|
||||
if (token->type == TK_IO_NUMBER)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int add_ionumber(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_token *token;
|
||||
t_redir redir;
|
||||
|
||||
if (!*ast)
|
||||
gen_node(ast);
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
node->type = token->type;
|
||||
redir.n = ft_atoi(token->data);
|
||||
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/05 17:22:24 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/05 18:14:00 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,26 +14,14 @@
|
|||
|
||||
int isdir_sep(t_btree **ast, t_list **list)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_token *token;
|
||||
|
||||
(void)ast;
|
||||
token = (*list)->content;
|
||||
if (*ast)
|
||||
{
|
||||
node = (*ast)->item;
|
||||
if (node->type == CMD
|
||||
&& (token->type == TK_LESS || token->type == TK_GREAT
|
||||
|| token->type == TK_GREATAND || token->type == TK_LESSAND
|
||||
|| token->type == TK_DLESS || token->type == TK_DGREAT))
|
||||
return (1);
|
||||
}
|
||||
if (!*ast)
|
||||
{
|
||||
if (token->type == TK_LESS || token->type == TK_GREAT
|
||||
|| token->type == TK_GREATAND || token->type == TK_LESSAND
|
||||
|| token->type == TK_DLESS || token->type == TK_DGREAT)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -68,11 +56,9 @@ int add_redir_word(t_btree **ast, t_list **lst)
|
|||
DG("add file");
|
||||
redir = (ft_lstlast(node->data.cmd.redir))->content;
|
||||
if (redir->type == TK_DLESS)
|
||||
redir->word.word = NULL;
|
||||
else if (ft_stris((char *)token->data, &ft_isdigit))
|
||||
redir->word.fd = ft_atoi(token->data);
|
||||
redir->word = NULL;
|
||||
else
|
||||
redir->word.word = ft_strdup(token->data);
|
||||
redir->word = ft_strdup(token->data);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -88,10 +74,12 @@ int add_redir_type(t_btree **ast, t_list **lst)
|
|||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
if (!(node->type == TK_IO_NUMBER))
|
||||
{
|
||||
redir.n = (token->type == TK_LESS || token->type == TK_DLESS
|
||||
|| token->type == TK_LESSAND) ? STDIN : STDOUT;
|
||||
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
|
||||
}
|
||||
node->type = REDIR;
|
||||
redir.type = token->type;
|
||||
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue