aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/ast.h95
-rw-r--r--include/eval.h6
-rw-r--r--include/parser.h (renamed from include/parse.h)6
-rw-r--r--src/ast.c29
-rw-r--r--src/eval/eval.c300
-rw-r--r--src/eval/pipe.c60
-rw-r--r--src/main.c109
-rw-r--r--src/parse/parse.c10
-rw-r--r--src/preprocess.c14
9 files changed, 308 insertions, 321 deletions
diff --git a/include/ast.h b/include/ast.h
index 2f3a11d..790ac29 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:38 by charles #+# #+# */
-/* Updated: 2020/06/09 11:44:45 by charles ### ########.fr */
+/* Updated: 2020/06/14 10:28:53 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,30 +20,8 @@
# include <stdlib.h>
# include <stdbool.h>
-# include "libft_mem.h"
-# include "libft_util.h"
-
-/*
-** \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 e_bool
-{
- TRUE,
- FALSE,
-} t_bool;
-
-typedef enum e_sep
-{
- SEP_END,
- SEP_PIPE,
- SEP_AND,
- SEP_OR,
-} t_sep;
+# include "libft_lst.h"
+# include "lexer.h"
struct s_ast;
@@ -54,29 +32,12 @@ struct s_ast;
** \param sep Type of separator
*/
-typedef struct s_line
-{
- struct s_ast *left;
- struct s_ast *right;
- e_token_tag 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 s_cmd
+typedef struct s_line
{
- t_ftlst *argv; // change to t_ftvec of t_token
- t_token *in; // change to t_token
- t_token *out; // change to t_token
- bool is_append;
-} t_cmd;
+ struct s_ast *left;
+ struct s_ast *right;
+ enum e_token_tag sep;
+} t_line;
/*
** \brief AST node tag (type)
@@ -84,37 +45,43 @@ typedef struct s_cmd
** \param TAG_LINE Line AST node
*/
-typedef enum e_ast_tag
+enum e_ast_tag
{
- TAG_CMD,
- TAG_LINE,
-} t_ast_tag;
+ AST_CMD,
+ AST_LINE,
+};
/*
** \brief AST node struct
** \param tag Node tag
-** \param cmd Command struct
** \param line Line struct
+** \param cmd_argv Array of string tokens
+** \param in STDIN redirection string tokens
+** \param out STDOUT redirection string tokens
+** \param is_append True if out redirection is append to file
*/
-typedef struct s_ast
+typedef struct s_ast
{
- t_ast_tag tag;
+ enum e_ast_tag tag;
union
{
- t_line line;
- t_cmd cmd;
+ t_line line;
+ t_ftlst *cmd_argv;
};
-} t_ast;
+ t_ftlst *in;
+ t_ftlst *out;
+ bool is_append;
+} t_ast;
-typedef struct s_ret
+typedef struct s_ret
{
- t_token *unexpected;
- t_ast *ast;
- t_ftlst *rest;
-} t_ret;
+ t_token *unexpected;
+ t_ast *ast;
+ t_ftlst *rest;
+} t_ret;
-t_ast *ast_new(t_ast_tag tag, void *data);
-void ast_destroy(t_ast *ast);
+t_ast *ast_new(enum e_ast_tag tag);
+void ast_destroy(t_ast *ast);
#endif
diff --git a/include/eval.h b/include/eval.h
index fc149b2..8fbbb1c 100644
--- a/include/eval.h
+++ b/include/eval.h
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:30 by charles #+# #+# */
-/* Updated: 2020/05/04 11:58:16 by charles ### ########.fr */
+/* Updated: 2020/06/14 10:33:54 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -75,7 +75,7 @@ char *exec_search_path(t_path path, char *path_var, char *exec_name);
** pipe.c
*/
-int pipe_setup_parent(t_cmd *cmd, int pipe_in[2], int pipe_out[2]);
-int pipe_setup_child(int pipe_in[2], int pipe_out[2]);
+// int pipe_setup_parent(t_cmd *cmd, int pipe_in[2], int pipe_out[2]);
+// int pipe_setup_child(int pipe_in[2], int pipe_out[2]);
#endif
diff --git a/include/parse.h b/include/parser.h
index 6cb50b8..80d039b 100644
--- a/include/parse.h
+++ b/include/parser.h
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* parse.h :+: :+: :+: */
+/* parser.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */
-/* Updated: 2020/06/13 11:59:47 by charles ### ########.fr */
+/* Updated: 2020/06/14 10:31:20 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -43,6 +43,6 @@
** parse.c
*/
-t_ast *parse(t_ftlst *lst);
+t_ret *parse(t_ftlst *input);
#endif
diff --git a/src/ast.c b/src/ast.c
index 4c66fa7..98ca4ac 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:42 by charles #+# #+# */
-/* Updated: 2020/05/04 12:00:20 by charles ### ########.fr */
+/* Updated: 2020/06/14 10:29:21 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,25 +20,22 @@
/*
** \brief Create a new AST node according to `tag`
** \param tag Tag of node
-** \param data Pointer to node data (t_cmd or t_line)
-** which will be copied in ast::data union
** \return Created node or NULL on error
*/
-t_ast *ast_new(t_ast_tag tag, void *data)
+t_ast *ast_new(enum e_ast_tag tag)
{
t_ast *ast;
- if (data == NULL)
- return (NULL);
if ((ast = (t_ast*)malloc(sizeof(t_ast))) == NULL)
return (NULL);
- ft_bzero(ast, sizeof(t_ast));
ast->tag = tag;
- if (tag == TAG_CMD)
- ft_memcpy(&ast->cmd, (t_cmd*)data, sizeof(t_cmd));
- else if (tag == TAG_LINE)
- ft_memcpy(&ast->line, (t_line*)data, sizeof(t_line));
+ ast->in = NULL;
+ ast->out = NULL;
+ ast->is_append = false;
+ ast->line.left = NULL;
+ ast->line.right = NULL;
+ ast->cmd_argv = NULL;
return (ast);
}
@@ -51,13 +48,13 @@ void ast_destroy(t_ast *ast)
{
if (ast == NULL)
return ;
- if (ast->tag == TAG_CMD)
+ if (ast->tag == AST_CMD)
{
- ft_split_destroy(ast->cmd.argv);
- free(ast->cmd.in);
- free(ast->cmd.out);
+ ft_lstdestroy(&ast->cmd_argv, (void (*)(void*))token_destroy);
+ ft_lstdestroy(&ast->in, (void (*)(void*))token_destroy);
+ ft_lstdestroy(&ast->out, (void (*)(void*))token_destroy);
}
- else if (ast->tag == TAG_LINE)
+ else if (ast->tag == AST_LINE)
{
ast_destroy(ast->line.left);
ast_destroy(ast->line.right);
diff --git a/src/eval/eval.c b/src/eval/eval.c
index c4df1c9..1e0a8d7 100644
--- a/src/eval/eval.c
+++ b/src/eval/eval.c
@@ -6,156 +6,156 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:21 by charles #+# #+# */
-/* Updated: 2020/05/15 00:12:51 by charles ### ########.fr */
+/* Updated: 2020/06/14 10:34:11 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-/*
-** \file eval.c
-** \brief Evaluation of an AST
-*/
-
-#include "eval.h"
-
-/*
-** \brief Wrap a function in a fork
-** \param fd_in fork input file descriptor
-** \param fd_out fork output file descriptor
-** \param passed param of the wrapped function
-** \param wrapped function to wrap
-*/
-
-int fork_wrap(
- int fd_in,
- int fd_out,
- void *passed,
- int (*wrapped)(void *param))
-{
- int status;
- pid_t child_pid;
-
- if ((child_pid = fork()) == -1)
- return (-1);
- if (child_pid == 0)
- {
- if (dup2(STDIN_FILENO, fd_in) == -1 ||
- dup2(STDOUT_FILENO, fd_out) == -1)
- exit(EXIT_FAILURE);
- if ((status = wrapped(passed)) == -1)
- exit(EXIT_FAILURE);
- exit(status);
- }
- wait(&child_pid);
- return (WEXITSTATUS(child_pid));
-}
-
-int run_builtin(t_eval_state *state, char **argv)
-{
- return (builtin_dispatch_run(argv, state->env));
-}
-
-/*
-** \brief execve syscall wrapper passed it to fork_wrap
-** \param param function params
-** \return execve return value
-*/
-
-int execve_wrapper(void *param)
-{
- return (execve(
- ((t_fork_param_execve*)param)->exec_path,
- ((t_fork_param_execve*)param)->argv,
- ((t_fork_param_execve*)param)->envp
- ));
-}
-
-/*
-** \brief Evaluate a command
-** \param state Evaluation state
-** \param cmd Command to evaluate
-** \return Executable status or -1 on error
-*/
-
-static int eval_cmd(int fd_in, int fd_out, t_eval_state *state, t_cmd *cmd)
-{
- t_fork_param_execve param;
-
- if (builtin_check_exec_name(cmd->argv[0]))
- return (run_builtin(state, cmd->argv));
- param.exec_path = exec_search_path(
- state->path, env_search(state->env, "PATH"), cmd->argv[0]);
- if (param.exec_path == NULL)
- return (-1);
- if (cmd->in != NULL && (fd_in = open(cmd->in, O_RDONLY)) == -1)
- return (-1);
- if (cmd->out != NULL && (fd_out = open(cmd->out,
- (cmd->is_append ? O_APPEND : O_WRONLY) | O_CREAT)) == -1)
- return (-1);
- param.argv = cmd->argv;
- param.envp = (char**)state->env->data;
- return (fork_wrap(fd_in, fd_out, &param, &execve_wrapper));
-}
-
-/*
-** \brief Evaluate a line
-** \param state State of the evaluation
-** \param line Line to evaluate
-** \return Last Executed command status or -1 on error
-*/
-
-static int eval_line(void *param)
-{
- int status;
- t_eval_state *state;
- t_line *line;
- int fd_in;
- int fd_out;
-
- state = ((t_fork_param_line*)param)->state;
- line = ((t_fork_param_line*)param)->line;
- fd_in = ((t_fork_param_line*)param)->fd_in;
- fd_out = ((t_fork_param_line*)param)->fd_out;
-
- /* if (line->right == NULL) */
- /* return (eval(state, line->left)); */
-
- /* if (line->sep == SEP_PIPE) */
- /* pipe(state->p); */
-
- if (line->left->tag == TAG_LINE)
- {
- return (fork_wrap(fd_in, fd_out, param, &eval_line));
- }
- if ((status = eval(fd_in, fd_out, state, line->left)) == -1)
- return (-1);
- if ((line->sep == SEP_AND && status != 0) ||
- (line->sep == SEP_OR && status == 0))
- return (status);
-
- return (eval(fd_in, fd_out, state, line->right));
-}
-
-/*
-** \brief Evaluate an AST
-** \param state State of the evaluation
-** \param ast Abstract syntax tree to evaluate
-** \return Last command status or -1 on error
-*/
-
-int eval(int fd_in, int fd_out, t_eval_state *state, t_ast *ast)
-{
- t_fork_param_line param;
-
- errno = 0;
- if (ast->tag == TAG_LINE)
- {
- param.state = state;
- param.line = &ast->line;
- param.fd_in = fd_in;
- param.fd_out = fd_out;
- return (eval_line(&param));
- }
- if (ast->tag == TAG_CMD)
- return (eval_cmd(fd_in, fd_out, state, &ast->cmd));
- return (-1);
-}
+/* #<{(| */
+/* ** \file eval.c */
+/* ** \brief Evaluation of an AST */
+/* |)}># */
+/* */
+/* #include "eval.h" */
+/* */
+/* #<{(| */
+/* ** \brief Wrap a function in a fork */
+/* ** \param fd_in fork input file descriptor */
+/* ** \param fd_out fork output file descriptor */
+/* ** \param passed param of the wrapped function */
+/* ** \param wrapped function to wrap */
+/* |)}># */
+/* */
+/* int fork_wrap( */
+/* int fd_in, */
+/* int fd_out, */
+/* void *passed, */
+/* int (*wrapped)(void *param)) */
+/* { */
+/* int status; */
+/* pid_t child_pid; */
+/* */
+/* if ((child_pid = fork()) == -1) */
+/* return (-1); */
+/* if (child_pid == 0) */
+/* { */
+/* if (dup2(STDIN_FILENO, fd_in) == -1 || */
+/* dup2(STDOUT_FILENO, fd_out) == -1) */
+/* exit(EXIT_FAILURE); */
+/* if ((status = wrapped(passed)) == -1) */
+/* exit(EXIT_FAILURE); */
+/* exit(status); */
+/* } */
+/* wait(&child_pid); */
+/* return (WEXITSTATUS(child_pid)); */
+/* } */
+/* */
+/* int run_builtin(t_eval_state *state, char **argv) */
+/* { */
+/* return (builtin_dispatch_run(argv, state->env)); */
+/* } */
+/* */
+/* #<{(| */
+/* ** \brief execve syscall wrapper passed it to fork_wrap */
+/* ** \param param function params */
+/* ** \return execve return value */
+/* |)}># */
+/* */
+/* int execve_wrapper(void *param) */
+/* { */
+/* return (execve( */
+/* ((t_fork_param_execve*)param)->exec_path, */
+/* ((t_fork_param_execve*)param)->argv, */
+/* ((t_fork_param_execve*)param)->envp */
+/* )); */
+/* } */
+/* */
+/* #<{(| */
+/* ** \brief Evaluate a command */
+/* ** \param state Evaluation state */
+/* ** \param cmd Command to evaluate */
+/* ** \return Executable status or -1 on error */
+/* |)}># */
+/* */
+/* static int eval_cmd(int fd_in, int fd_out, t_eval_state *state, t_cmd *cmd) */
+/* { */
+/* t_fork_param_execve param; */
+/* */
+/* if (builtin_check_exec_name(cmd->argv[0])) */
+/* return (run_builtin(state, cmd->argv)); */
+/* param.exec_path = exec_search_path( */
+/* state->path, env_search(state->env, "PATH"), cmd->argv[0]); */
+/* if (param.exec_path == NULL) */
+/* return (-1); */
+/* if (cmd->in != NULL && (fd_in = open(cmd->in, O_RDONLY)) == -1) */
+/* return (-1); */
+/* if (cmd->out != NULL && (fd_out = open(cmd->out, */
+/* (cmd->is_append ? O_APPEND : O_WRONLY) | O_CREAT)) == -1) */
+/* return (-1); */
+/* param.argv = cmd->argv; */
+/* param.envp = (char**)state->env->data; */
+/* return (fork_wrap(fd_in, fd_out, &param, &execve_wrapper)); */
+/* } */
+/* */
+/* #<{(| */
+/* ** \brief Evaluate a line */
+/* ** \param state State of the evaluation */
+/* ** \param line Line to evaluate */
+/* ** \return Last Executed command status or -1 on error */
+/* |)}># */
+/* */
+/* static int eval_line(void *param) */
+/* { */
+/* int status; */
+/* t_eval_state *state; */
+/* t_line *line; */
+/* int fd_in; */
+/* int fd_out; */
+/* */
+/* state = ((t_fork_param_line*)param)->state; */
+/* line = ((t_fork_param_line*)param)->line; */
+/* fd_in = ((t_fork_param_line*)param)->fd_in; */
+/* fd_out = ((t_fork_param_line*)param)->fd_out; */
+/* */
+/* #<{(| if (line->right == NULL) |)}># */
+/* #<{(| return (eval(state, line->left)); |)}># */
+/* */
+/* #<{(| if (line->sep == SEP_PIPE) |)}># */
+/* #<{(| pipe(state->p); |)}># */
+/* */
+/* if (line->left->tag == AST_LINE) */
+/* { */
+/* return (fork_wrap(fd_in, fd_out, param, &eval_line)); */
+/* } */
+/* if ((status = eval(fd_in, fd_out, state, line->left)) == -1) */
+/* return (-1); */
+/* if ((line->sep == SEP_AND && status != 0) || */
+/* (line->sep == SEP_OR && status == 0)) */
+/* return (status); */
+/* */
+/* return (eval(fd_in, fd_out, state, line->right)); */
+/* } */
+/* */
+/* #<{(| */
+/* ** \brief Evaluate an AST */
+/* ** \param state State of the evaluation */
+/* ** \param ast Abstract syntax tree to evaluate */
+/* ** \return Last command status or -1 on error */
+/* |)}># */
+/* */
+/* int eval(int fd_in, int fd_out, t_eval_state *state, t_ast *ast) */
+/* { */
+/* t_fork_param_line param; */
+/* */
+/* errno = 0; */
+/* if (ast->tag == TAG_LINE) */
+/* { */
+/* param.state = state; */
+/* param.line = &ast->line; */
+/* param.fd_in = fd_in; */
+/* param.fd_out = fd_out; */
+/* return (eval_line(&param)); */
+/* } */
+/* if (ast->tag == TAG_CMD) */
+/* return (eval_cmd(fd_in, fd_out, state, &ast->cmd)); */
+/* return (-1); */
+/* } */
diff --git a/src/eval/pipe.c b/src/eval/pipe.c
deleted file mode 100644
index 125c013..0000000
--- a/src/eval/pipe.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* pipe.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/04/01 17:05:58 by charles #+# #+# */
-/* Updated: 2020/04/01 17:05:59 by charles ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-/*
-** \file pipe.c
-** \brief Pipes setup
-*/
-
-#include "eval.h"
-
-/*
-** \brief Setup STDIN and STDOUT pipe in the parent process
-** \param cmd Command to setup
-** \param pipe_in STDIN pipe
-** \param pipe_out STDOUT pipe
-** \return -1 on error, 0 otherwise
-*/
-
-int pipe_setup_parent(t_cmd *cmd, int pipe_in[2], int pipe_out[2])
-{
- if (cmd->in != NULL)
- {
- if ((pipe_in[PIPE_WRITE] = open(cmd->in, O_RDONLY)) < 0)
- return (-1);
- }
- if (cmd->out != NULL)
- {
- if ((pipe_out[PIPE_READ] = open(cmd->out,
- (cmd->is_append ? O_WRONLY : O_APPEND) | O_CREAT)) < 0)
- return (-1);
- }
- return (0);
-}
-
-/*
-** \brief Setup STDIN and STDOUT pipe in the child process
-** \param pipe_in STDIN pipe
-** \param pipe_out STDOUT pipe
-** \return -1 on error, 0 otherwise
-*/
-
-int pipe_setup_child(int pipe_in[2], int pipe_out[2])
-{
- if (pipe_in[PIPE_READ] != PIPE_CLOSED)
- if (dup2(STDIN_FILENO, pipe_in[PIPE_READ]) == -1)
- return (-1);
- if (pipe_out[PIPE_WRITE] != PIPE_CLOSED)
- if (dup2(STDOUT_FILENO, pipe_out[PIPE_WRITE]) == -1)
- return (-1);
- return (0);
-}
diff --git a/src/main.c b/src/main.c
index c426f74..5d3e9d8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */
-/* Updated: 2020/06/13 11:56:27 by charles ### ########.fr */
+/* Updated: 2020/06/14 10:36:06 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,20 +20,103 @@
#include "lexer.h"
#include "parser.h"
+int main(int argc, char **argv, char **envp)
+{
+ (void)argc;
+ (void)argv;
+ /* (void)envp; */
+ /* t_path path; */
+ t_env env;
+ /* char *line; */
+ /* int ret; */
+ env = env_from_array(envp);
+ /* path = path_update(NULL, env_search(env, "PATH")); */
+ /* */
+ /* t_ast *ast; */
+ /* t_line line; */
+ /* t_cmd cmd; */
+ /* t_eval_state state; */
+ /* */
+ /* cmd.argv = ft_split("ls -l", ' '); */
+ /* cmd.in = NULL; */
+ /* cmd.out = NULL; */
+ /* cmd.is_append = false; */
+ /* */
+ /* line.left = ast_new(TAG_CMD, &cmd); */
+ /* line.right = NULL; */
+ /* line.sep = SEP_END; */
+ /* ast = ast_new(TAG_LINE, &line); */
+ /* printf("%p\n", ast); */
+ /* printf("%d\n", ast->tag); */
+ /* printf("%p\n", ast->data.line.left); */
+ /* printf("%p\n", ast->data.line.right); */
+ /* printf("%d\n", ast->data.line.left->tag); */
+ /* printf("%p\n", ast->data.line.left->data.cmd.argv); */
+ /* printf("%s\n", ast->data.line.left->data.cmd.argv[0]); */
+ /* printf("%s\n", ast->data.line.left->data.cmd.argv[1]); */
+ /* state.pipe_in[0] = -1; */
+ /* state.pipe_in[1] = -1; */
+ /* state.pipe_out[0] = -1; */
+ /* state.pipe_out[1] = -1; */
+ /* state.path = path; */
+ /* state.env = env; */
+ /* t_io_frame frame; */
+ /* io_frame_init(&frame); */
+ /* printf("ret: %d %s\n", eval(&frame,&state, ast), strerror(errno)); */
+ /* char buf[2048]; */
+ /* printf("%s\n", getcwd(buf, 2048)); */
+ /* builtin_env(NULL, state.env); */
+ /* ast_destroy(ast); */
+ /* while ((ret = ft_next_line(STDIN_FILENO, &line)) == 1) */
+ /* { */
+ /* if (eval(parse(line)) == -1) */
+ /* continue ; // and display error */
+ /* free(line); */
+ /* } */
+ /* free(line); */
+ /* ft_htdestroy(path, free); */
+ /* ms_glob("src#<{(|"); */
+ /* char *j = ms_glob("|)}>#*.c"); */
+ /* printf("%s\n", j); */
+ /* free(j); */
+ t_ftvec *v = ft_vecnew(32);
+ ft_vecpush(v, token_new(TAG_STR, "$TERM$LFS$TERM$TERM."));
+ ft_vecpush(v, token_new(TAG_STR, "$$LFS$TERM$TERM."));
+ ft_vecpush(v, token_new(TAG_STR, "*/*.c$TERM"));
+ ft_vecpush(v, token_new(TAG_STR, "src/*.c include/*.h"));
+ ft_vecpush(v, token_new(TAG_STR, "$A$B"));
+ ft_vecpush(v, token_new(TAG_STR, "\\$TERM"));
+ ft_vecpush(v, token_new(TAG_STR, "$TER\\M"));
+ ft_vecpush(v, token_new(TAG_STR, "\\\\"));
+ ft_vecpush(v, token_new(TAG_STR_SINGLE, "''''$TEST\\TEST"));
+ ft_vecpush(v, token_new(TAG_STR_DOUBLE, ",$TEST,$B,"));
+ ft_vecpush(v, token_new(TAG_STR_DOUBLE | TAG_STICK, "$TEST"));
+ ft_vecpush(v, token_new(TAG_STR_DOUBLE | TAG_STICK, "$TEST"));
+ ft_vecpush(v, token_new(TAG_STR_DOUBLE , "$TEST"));
+ ft_vecpush(v, token_new(TAG_STR_DOUBLE | TAG_STICK, "$TEST"));
+ ft_vecpush(v, token_new(TAG_STR_SINGLE, "$TEST"));
+ char **as = preprocess(v, env);
+ char **tmp = as;
+ while (*as != NULL)
+ puts(*as++);
+ ft_split_destroy(tmp);
+ ft_vecdestroy(env, free);
+ return (0);
+}
/////////////////////////////////////////////////////////////////////////////////////////
// lexer main
/////////////////////////////////////////////////////////////////////////////////////////
- int main(void)
- {
- char *input;
-
- if (!(input = malloc(sizeof(char) * ft_strlen(argv[1]) + 1)))
- return(0);
- ft_strlcpy(input, argv[1], ft_strlen(argv[1]) + 1);
-
- lexer(input);
- exit(0);
- return (0);
- } */
+/* int main(void) */
+/* { */
+/* char *input; */
+/* */
+/* if (!(input = malloc(sizeof(char) * ft_strlen(argv[1]) + 1))) */
+/* return(0); */
+/* ft_strlcpy(input, argv[1], ft_strlen(argv[1]) + 1); */
+/* */
+/* lexer(input); */
+/* exit(0); */
+/* return (0); */
+/* } */
diff --git a/src/parse/parse.c b/src/parse/parse.c
index a240377..92797c8 100644
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -3,17 +3,17 @@
** \brief Parser
*/
-#include "parse.h"
-#include <stdio.h>
+#include "parser.h"
+// stdio.h est deja include dans minishell.h temporairement
+// (comme ca on doit le retirer a un seul endroit a la fin)
-
-t_ret *parse(t_ftlst *lst)
+t_ret *parse(t_ftlst *input)
{
t_ret *ret;
if(!(ret = malloc(sizeof(t_ret) * 1)))
return(NULL);
- ret->rest = lst;
+ ret->rest = input;
return NULL;
}
diff --git a/src/preprocess.c b/src/preprocess.c
index 1034068..badf3cf 100644
--- a/src/preprocess.c
+++ b/src/preprocess.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/03 08:58:49 by charles #+# #+# */
-/* Updated: 2020/06/12 11:57:17 by charles ### ########.fr */
+/* Updated: 2020/06/14 10:33:17 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,9 +16,9 @@
static bool st_escapable(char c, enum e_token_tag tag)
{
- if (tag & LTAG_STR)
+ if (tag & TAG_STR)
return (true);
- if ((tag & LTAG_STR_DOUBLE) && (c == '\\' || c == '"' || c == '$'))
+ if ((tag & TAG_STR_DOUBLE) && (c == '\\' || c == '"' || c == '$'))
return (true);
return (false);
}
@@ -91,7 +91,7 @@ static int st_splat_arg(t_ftvec *argv, int i)
j = 0;
while (strs[j] != NULL)
{
- if (ft_vecinsert_safe(argv, i + j, token_new(LTAG_STR, strs[j])) == NULL)
+ if (ft_vecinsert_safe(argv, i + j, token_new(TAG_STR, strs[j])) == NULL)
{
token_destroy(splated);
ft_split_destroy(strs);
@@ -122,10 +122,10 @@ char **preprocess(t_ftvec *argv, t_env env)
while (++i < argv->size)
{
token = argv->data[i];
- if (token->tag & LTAG_STR_SINGLE)
+ if (token->tag & TAG_STR_SINGLE)
continue ;
token->content = st_iterpolate_env(token->content, token->tag, env);
- if (token->tag & LTAG_STR)
+ if (token->tag & TAG_STR)
{
if (ft_strchr(token->content, '*') != NULL)
token->content = st_iterpolate_globs(token->content);
@@ -139,7 +139,7 @@ char **preprocess(t_ftvec *argv, t_env env)
while (++i < argv->size - 1)
{
token = argv->data[i];
- while (token->tag & LTAG_STICK && i + 1 < argv->size)
+ while (token->tag & TAG_STICK && i + 1 < argv->size)
{
next = argv->data[i + 1];
token->content = ft_strjoinf_fst(token->content, next->content);