aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/ast.h6
-rw-r--r--include/parse.h2
-rw-r--r--src/main.c130
-rw-r--r--src/parse/lexer.c26
-rw-r--r--src/parse/parse.c12
5 files changed, 24 insertions, 152 deletions
diff --git a/include/ast.h b/include/ast.h
index e63ab22..a5e55bb 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -101,6 +101,12 @@ typedef struct s_ast
};
} t_ast;
+typedef struct s_ret
+{
+ t_ast *as;
+ t_ftlst *rest;
+}
+
t_ast *ast_new(t_ast_tag tag, void *data);
void ast_destroy(t_ast *ast);
diff --git a/include/parse.h b/include/parse.h
index ec95ef9..6cb50b8 100644
--- a/include/parse.h
+++ b/include/parse.h
@@ -43,6 +43,6 @@
** parse.c
*/
-t_ast *parse(char **input);
+t_ast *parse(t_ftlst *lst);
#endif
diff --git a/src/main.c b/src/main.c
index 5dac612..c426f74 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,129 +17,23 @@
#include "minishell.h"
#include "ast.h"
-#include "eval.h"
-#include "ms_glob.h"
#include "lexer.h"
-
-/*
-** \brief Program entrypoint
-** \param argc Number of arguments in `argv`
-** \param argv Array of string, argument of the program
-** \param envp NULL terminated array of string representing the environment
-** \return 0 if ok, 1 otherwise
-*/
-
-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(LTAG_STR, "$TERM$LFS$TERM$TERM."));
- ft_vecpush(v, token_new(LTAG_STR, "$$LFS$TERM$TERM."));
- ft_vecpush(v, token_new(LTAG_STR, "*/*.c$TERM"));
- ft_vecpush(v, token_new(LTAG_STR, "src/*.c include/*.h"));
- ft_vecpush(v, token_new(LTAG_STR, "$A$B"));
-
- ft_vecpush(v, token_new(LTAG_STR, "\\$TERM"));
- ft_vecpush(v, token_new(LTAG_STR, "$TER\\M"));
- ft_vecpush(v, token_new(LTAG_STR, "\\\\"));
- ft_vecpush(v, token_new(LTAG_STR_SINGLE, "''''$TEST\\TEST"));
- ft_vecpush(v, token_new(LTAG_STR_DOUBLE, ",$TEST,$B,"));
-
- ft_vecpush(v, token_new(LTAG_STR_DOUBLE | LTAG_STICK, "$TEST"));
- ft_vecpush(v, token_new(LTAG_STR_DOUBLE | LTAG_STICK, "$TEST"));
- ft_vecpush(v, token_new(LTAG_STR_DOUBLE , "$TEST"));
- ft_vecpush(v, token_new(LTAG_STR_DOUBLE | LTAG_STICK, "$TEST"));
- ft_vecpush(v, token_new(LTAG_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);
-}
+#include "parser.h"
/////////////////////////////////////////////////////////////////////////////////////////
// lexer main
/////////////////////////////////////////////////////////////////////////////////////////
-#include "lexer.h"
+ 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);
-/* int main(void) */
-/* { */
-/* char **out; */
-/* int i = -1; */
-/* */
-/* out = lexer("\"echo\" \"* login_x\"<<AUTHORS; echo && ; salut;\"echo\"\"* login_x\""); */
-/* //out = lexer("echo * login_x << AUTHORS&&cd Desktop"); */
-/* while(out[++i]) */
-/* printf("%s\n", out[i]);; */
-/* exit(0); */
-/* return (0); */
-/* } */
+ lexer(input);
+ exit(0);
+ return (0);
+ } */
diff --git a/src/parse/lexer.c b/src/parse/lexer.c
deleted file mode 100644
index 2aa8a6f..0000000
--- a/src/parse/lexer.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-** \file lexer.c
-** \brief Lexer
-*/
-
-#include "minishell.h"
-
-/* static char **lex_len(char *input) */
-/* { */
-/* int i; */
-/* */
-/* i = 0; */
-/* while(input[i] != '\0') */
-/* { */
-/* lex_comp_cmd(input); */
-/* i++; */
-/* } */
-/* } */
-
-/* char **lexer(char *input) */
-/* { */
-/* if (!input) */
-/* return (NULL); */
-/* lex_len(input); */
-/* return (NULL); */
-/* } */
diff --git a/src/parse/parse.c b/src/parse/parse.c
index a0da5d9..6f9c99b 100644
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -4,15 +4,13 @@
*/
#include "parse.h"
+#include <stdio.h>
-t_ast *parse(char **input)
+t_ast *parse(t_ftlst *lst)
{
- /* int i = 0; */
+ t_ret *ret;
- (void)input;
- /* while (input[i] != '\0') */
- /* { */
- /* */
- /* } */
+ ret->rest = lst;
+ ret =
return NULL;
}