aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ast.h19
-rw-r--r--include/eval.h39
-rw-r--r--include/lexer.h1
-rw-r--r--include/minishell.h14
-rw-r--r--include/parser.h16
5 files changed, 47 insertions, 42 deletions
diff --git a/include/ast.h b/include/ast.h
index bcb5e11..53221fa 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ast.h :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:38 by charles #+# #+# */
-/* Updated: 2020/06/14 17:47:10 by charles ### ########.fr */
+/* Updated: 2020/06/18 13:35:38 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,36 +26,37 @@
struct s_ast;
/*
-** \brief Line struct
+** \brief Operation struct
** \param left AST to the left of separator
** \param right AST to the right of separator
** \param sep Type of separator
*/
-typedef struct s_line
+typedef struct s_op
{
struct s_ast *left;
struct s_ast *right;
enum e_token_tag sep;
-} t_line;
+} t_op;
/*
** \brief AST node tag (type)
** \param TAG_CMD Command AST node
-** \param TAG_LINE Line AST node
+** \param TAG_OP Operation AST node
*/
enum e_ast_tag
{
AST_CMD,
- AST_LINE,
+ AST_OP,
+ AST_OP_PARENT,
};
/*
** \brief AST node struct
** \param tag Node tag
-** \param line Line struct
+** \param op Operation struct
** \param cmd_argv Array of string tokens
** \param in STDIN redirection string tokens
** \param out STDOUT redirection string tokens
@@ -67,7 +68,7 @@ typedef struct s_ast
enum e_ast_tag tag;
union
{
- t_line line;
+ t_op op;
t_ftlst *cmd_argv;
};
t_ftlst *redirs;
diff --git a/include/eval.h b/include/eval.h
index f834d45..60d6f23 100644
--- a/include/eval.h
+++ b/include/eval.h
@@ -3,10 +3,10 @@
/* ::: :::::::: */
/* eval.h :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:30 by charles #+# #+# */
-/* Updated: 2020/06/15 11:09:49 by charles ### ########.fr */
+/* Updated: 2020/06/18 13:38:53 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,6 +19,7 @@
*/
# include "minishell.h"
+# include "lexer.h"
# include "ast.h"
/*
@@ -44,10 +45,10 @@ typedef struct s_eval_status
typedef struct
{
t_eval_state *state;
- t_line *line;
+ t_op *op;
int fd_in;
int fd_out;
-} t_fork_param_line;
+} t_fork_param_op;
typedef struct
{
@@ -57,21 +58,16 @@ typedef struct
t_builtin_func builtin;
} t_fork_param_cmd;
-#define MS_NO_FD -2
+# define MS_NO_FD -2
+# define FDS_WRITE 1
+# define FDS_READ 0
/*
-** eval.c
+** op.c
*/
-int eval(int fd_in, int fd_out, t_eval_state *state, t_ast *ast);
-
-/*
-** exec.c
-*/
-
-bool exec_is_path(char *path_str);
-bool exec_is_valid(char *exec_path);
-char *exec_search_path(t_path path, char *path_var, char *exec_name);
+int eval_op(int fds[2], t_env env, t_path path, t_op *op);
+int eval(int fds[2], t_env env, t_path path, t_ast *ast);
enum e_error
{
@@ -99,12 +95,21 @@ void error_eval_put(enum e_error id, char *unexpected);
** cmd.c
*/
-int eval_cmd(t_env env, t_path path, t_ast *ast);
+int fork_wrap(int fds[2], void *passed, int (*wrapped)(void *param));
+int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast);
/*
** redir.c
*/
-bool redir_extract(t_ftlst *redirs, t_env env, int *fd_in, int *fd_out);
+bool redir_extract(t_ftlst *redirs, t_env env, int fds[2]);
+
+/*
+** exec.c
+*/
+
+bool exec_is_path(char *exec_name);
+bool exec_is_valid(char *exec_path);
+char *exec_search_path(t_path path, char *path_var, char *exec_name);
#endif
diff --git a/include/lexer.h b/include/lexer.h
index b0e7f65..43c3821 100644
--- a/include/lexer.h
+++ b/include/lexer.h
@@ -24,6 +24,7 @@ enum e_token_tag
TAG_IS_STR = TAG_STR | TAG_STR_SINGLE | TAG_STR_DOUBLE,
TAG_IS_REDIR = TAG_REDIR_IN | TAG_REDIR_OUT | TAG_REDIR_APPEND,
+ TAG_IS_SEP = TAG_AND | TAG_END | TAG_OR | TAG_PIPE,
};
typedef struct
diff --git a/include/minishell.h b/include/minishell.h
index 148766f..5f4f56a 100644
--- a/include/minishell.h
+++ b/include/minishell.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/26 15:33:51 by cacharle #+# #+# */
-/* Updated: 2020/06/17 12:51:48 by charles ### ########.fr */
+/* Updated: 2020/06/18 13:45:27 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -42,18 +42,6 @@
# define PIPE_CLOSED -1
-/*
-** \brief Pipe write index
-*/
-
-# define PIPE_WRITE 1
-
-/*
-** \brief Pipe read index
-*/
-
-# define PIPE_READ 0
-
# define BUILTIN_NOT_FOUND -2
typedef t_ftht* t_path;
diff --git a/include/parser.h b/include/parser.h
index 2bfa9d5..302c45f 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -3,10 +3,10 @@
/* ::: :::::::: */
/* parser.h :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */
-/* Updated: 2020/06/14 10:31:20 by charles ### ########.fr */
+/* Updated: 2020/06/18 13:18:13 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -37,10 +37,20 @@
** parse.c
*/
+
t_ret *parse(t_ftlst *input);
+t_ret *parse_op(t_ftlst *input);
+t_ret *parse_expr(t_ftlst *input);
+t_ret *parse_cmd(t_ftlst *input);
+
+// utils
+t_ret *ret_wrap_ast(t_ast *ast, t_ftlst *rest);
+t_ftlst *push_token(t_ftlst **tokens, t_token *pushed);
+
+
+
t_ast *push_cmd(t_ast *ast, t_ftlst *ret);
t_ast *push_redir(t_ast *ast, t_ftlst *rest);
-
int parse_cmd_str_true_false(enum e_token_tag tag);
int parse_redir_true_false(enum e_token_tag tag);