aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ast.h80
-rw-r--r--include/minishell.h13
-rw-r--r--include/ms_eval.h71
-rw-r--r--include/ms_parse.h42
4 files changed, 130 insertions, 76 deletions
diff --git a/include/ast.h b/include/ast.h
new file mode 100644
index 0000000..4ee3396
--- /dev/null
+++ b/include/ast.h
@@ -0,0 +1,80 @@
+#ifndef AST_H
+# define AST_H
+
+/**
+** \file ast.h
+** \brief AST structs
+*/
+
+/**
+** \brief Separator type
+** \param SEP_END Regular command end `;`
+** \param SEP_PIPE Pipe output of left to right `|`
+** \param SEP_AND Execute right if left status == 0 `&&`
+** \param SEP_OR Execute right if left status != 0 `||`
+*/
+
+typedef enum
+{
+ SEP_END,
+ SEP_PIPE,
+ SEP_AND,
+ SEP_OR,
+} t_sep;
+
+typedef struct s_ast t_ast;
+/**
+** \brief Line struct
+** \param left AST to the left of separator
+** \param right AST to the right of separator
+** \param sep Type of separator
+*/
+
+typedef struct
+{
+ t_ast *left;
+ t_ast *right;
+ t_sep sep;
+} t_line;
+
+/**
+** \brief Command struct
+** \param argv Array of string, all arguments beginning with executable name
+** \param in STDIN redirection filename
+** \param out STDOUT redirection filename
+** \param is_append True if out redirection is append to file
+*/
+
+typedef struct
+{
+ char **argv;
+ char *in;
+ char *out;
+ bool is_append;
+} t_cmd;
+
+typedef enum
+{
+ TAG_CMD,
+ TAG_LINE,
+} t_ast_tag;
+
+/**
+** \brief AST node struct
+** \param type Node type
+** \param data Union containning possible node data
+** \param data::cmd Command struct
+** \param data::line Line struct
+*/
+
+struct s_ast
+{
+ t_ast_tag tag;
+ union
+ {
+ t_line line;
+ t_cmd cmd;
+ } data;
+};
+
+#endif
diff --git a/include/minishell.h b/include/minishell.h
index 9931b15..6a00ca8 100644
--- a/include/minishell.h
+++ b/include/minishell.h
@@ -35,18 +35,25 @@
# include "libft_util.h"
# include "ms_parse.h"
+// # include "ms_eval.h"
+
+/**
+** \brief Value of pipe entry if closed
+*/
+
+# define PIPE_CLOSED -1
/**
** \brief Pipe write index
*/
-# define MS_PIPE_WRITE 1
+# define PIPE_WRITE 1
/**
** \brief Pipe read index
*/
-# define MS_PIPE_READ 0
+# define PIPE_READ 0
typedef t_ftht* t_path;
typedef t_ftht* t_env;
@@ -80,6 +87,6 @@ int ms_exit(void);
** util.c - various utilitary functions
*/
-void ms_ht_del_str_entry(t_ftht_content *content);
+void ms_ht_del_str_entry(t_ftht_entry *entry);
#endif
diff --git a/include/ms_eval.h b/include/ms_eval.h
index 12c2b7e..b53b845 100644
--- a/include/ms_eval.h
+++ b/include/ms_eval.h
@@ -6,71 +6,38 @@
** \brief Evaluation module
*/
-/*
-** arg:
-** type ARG
-** value string
-**
-** redir in:
-** type REDIRIN
-** value fd
-**
-** redir out:
-** type REDIROUT
-** value fd
-**
-** redir append:
-** type REDIRAPPEND
-** value fd
-*/
+# include "minishell.h"
/**
-** \enum t_val_type
-** \brief A type for an evaluation node
-**
-** \param VAL_ERR error
-** \param VAL_ERR argument
-** \param VAL_REDIR redirection
-** \param VAL_SEXPR S-expression
+** \brief Evaluation state struct
*/
-typedef enum
+typedef struct
{
- VAL_ERR,
- VAL_ARG,
- VAL_EXEC,
- VAL_REDIR_IN,
- VAL_REDIR_OUT,
- VAL_REDIR_APPEND,
- VAL_CMD,
- VAL_SEXPR,
-} t_val_type;
+ int status;
+ int in_pipe[2]; // need stack pipe
+ int out_pipe[2];
+ t_path path;
+ t_env env;
+} t_eval_state;
/**
-** \brief An evaluation node struct
-** \param type type of node
-** \param data union of possible data
-** \param data::fd file descriptor for redirection node
-** \param data::str string for error, arguments, command
+** \brief Evaluation status struct
*/
typedef struct
{
- t_val_type type;
- union
- {
- char *str;
- int code;
- int fd;
- } data;
-} t_val;
+ char *err;
+ int status;
+} t_eval_status;
+
/**
-** \brief evaluate an AST
-** \param path path to commands executable
-** \param env environment variables
-** \param ast Abstract syntax tree to evaluate
+** \brief Evaluate an AST
+** \param state State of the evaluation
+** \param ast Abstract syntax tree to evaluate
*/
-int ms_eval(t_path path, t_env env, t_ast *ast);
+
+int ms_eval(t_eval_state *state, t_ast *ast);
#endif
diff --git a/include/ms_parse.h b/include/ms_parse.h
index 0810ec2..0a33ccf 100644
--- a/include/ms_parse.h
+++ b/include/ms_parse.h
@@ -14,6 +14,7 @@
# define MS_PARSE_H
# include "minishell.h"
+# include "ast.h"
/**
** \file ms_parse.h
@@ -41,16 +42,16 @@
** \param TAG_REDIR_APPEND `>>`
*/
-typedef enum
-{
- TAG_STRING,
- TAG_SEP,
- TAG_REDIR_OUT,
- TAG_REDIR_IN,
- TAG_REDIR_APPEND,
- TAG_CMD,
- TAG_LINE,
-} t_tag;
+// typedef enum
+// {
+// TAG_STRING,
+// TAG_SEP,
+// TAG_REDIR_OUT,
+// TAG_REDIR_IN,
+// TAG_REDIR_APPEND,
+// TAG_CMD,
+// TAG_LINE,
+// } t_ast_tag;
/**
** \brief AST (Abstract Syntax Tree)
@@ -60,14 +61,13 @@ typedef enum
** \param children children nodes
*/
-typedef struct s_ast
-{
- t_tag tag;
- char* content;
- int children_num;
- struct s_ast** children;
-} t_ast;
-
+// typedef struct s_ast
+// {
+// t_tag tag;
+// char* content;
+// int children_num;
+// struct s_ast** children;
+// } t_ast;
/*
** lexer.c
@@ -85,8 +85,8 @@ t_ast *ms_parse(char *input);
** ast.c
*/
-t_ast *ms_ast_new(t_tag tag);
-void ms_ast_destroy(t_ast *ast);
-void ms_ast_iter(t_ast *ast, void (*f)(void *f_arg, t_ast *children), void *arg);
+// t_ast *ms_ast_new(t_tag tag);
+// void ms_ast_destroy(t_ast *ast);
+// void ms_ast_iter(t_ast *ast, void (*f)(void *f_arg, t_ast *children), void *arg);
#endif