From 52bb7cc0f234776cd19c7a608b06578150d4695a Mon Sep 17 00:00:00 2001 From: nass1pro Date: Mon, 20 Jul 2020 14:55:11 +0200 Subject: update eval_cmd --- split_token | 301 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 split_token (limited to 'split_token') diff --git a/split_token b/split_token new file mode 100644 index 0000000..7aa5020 --- /dev/null +++ b/split_token @@ -0,0 +1,301 @@ +diff --git a/include/eval.h b/include/eval.h +index 88142cd..88b6578 100644 +--- a/include/eval.h ++++ b/include/eval.h +@@ -6,7 +6,7 @@ + /* By: charles +#+ +:+ +#+ */ + /* +#+#+#+#+#+ +#+ */ + /* Created: 2020/04/01 17:05:30 by charles #+# #+# */ +-/* Updated: 2020/07/15 17:03:05 by charles ### ########.fr */ ++/* Updated: 2020/07/20 13:22:26 by nahaddac ### ########.fr */ + /* */ + /* ************************************************************************** */ + +@@ -58,6 +58,7 @@ int eval(int fds[2], 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); ++t_ftlst *split_token(t_ftlst **lst, enum e_token_tag); + + /* + ** redir.c +diff --git a/include/lexer.h b/include/lexer.h +index ab2a448..f40db56 100644 +--- a/include/lexer.h ++++ b/include/lexer.h +@@ -6,7 +6,7 @@ + /* By: nahaddac +#+ +:+ +#+ */ + /* +#+#+#+#+#+ +#+ */ + /* Created: 2020/06/19 10:51:26 by nahaddac #+# #+# */ +-/* Updated: 2020/07/16 07:10:58 by nahaddac ### ########.fr */ ++/* Updated: 2020/07/20 11:07:13 by nahaddac ### ########.fr */ + /* */ + /* ************************************************************************** */ + +diff --git a/libft b/libft +index 450e36f..0fc1e47 160000 +--- a/libft ++++ b/libft +@@ -1 +1 @@ +-Subproject commit 450e36f8ddf974e503731288c8d8bb8c62e67e47 ++Subproject commit 0fc1e473e3bae0e1df32228ff72b9ab654fd2ac3 +diff --git a/minishell_test b/minishell_test +index 520742c..a90b8ed 160000 +--- a/minishell_test ++++ b/minishell_test +@@ -1 +1 @@ +-Subproject commit 520742c77fc3d52301c54b7d678948f9c7c69ac6 ++Subproject commit a90b8ed1561e1edd05e2689e566727acedf4ff68 +diff --git a/src/eval/cmd.c b/src/eval/cmd.c +index 87c9bbf..adb4d1c 100644 +--- a/src/eval/cmd.c ++++ b/src/eval/cmd.c +@@ -3,10 +3,10 @@ + /* ::: :::::::: */ + /* cmd.c :+: :+: :+: */ + /* +:+ +:+ +:+ */ +-/* By: charles +#+ +:+ +#+ */ ++/* By: charles +#+ +:+ +#+ */ + /* +#+#+#+#+#+ +#+ */ + /* Created: 2020/06/14 10:41:31 by charles #+# #+# */ +-/* Updated: 2020/07/19 19:00:54 by charles ### ########.fr */ ++/* Updated: 2020/07/20 14:17:32 by nahaddac ### ########.fr */ + /* */ + /* ************************************************************************** */ + +@@ -14,6 +14,7 @@ + + pid_t g_child_pid = -1; + int g_last_status_code = 0; ++void token_debug(void *v); + + /* + ** \brief Wrap a function in a fork +@@ -91,6 +92,8 @@ int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast) + { + t_fork_param_cmd param; + char **argv; ++ char *id; ++ t_ftlst *tmp; + + if (!redir_extract(ast->redirs, env, fds)) + { +@@ -105,7 +108,14 @@ int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast) + && ((t_token*)ast->cmd_argv->data)->tag & TAG_IS_STR + && utils_start_with_valid_identifier(((t_token*)ast->cmd_argv->data)->content)) + { +- if (env_export_full(param.env_local, ((t_token*)ast->cmd_argv->data)->content) == NULL) ++ id = ((t_token*)ast->cmd_argv->data)->content; ++ *ft_strchr(id, '=') = '\0'; ++ ((t_token*)ast->cmd_argv->data)->content = ft_strchr(id, '\0') + 1; ++ tmp = split_token(&ast->cmd_argv, TAG_STICK); ++ ft_lstiter(tmp, token_debug); ++ printf("%s\n", ((t_token *)ast->cmd_argv->data)->content); ++ ++ if (env_export(param.env_local,id, ((t_token*)ast->cmd_argv->data)->content) == NULL) + return (-1); + ft_lstpop_front(&ast->cmd_argv, (void (*)(void*))token_destroy); + } +diff --git a/src/main.c b/src/main.c +index 85df51f..e1b956a 100644 +--- a/src/main.c ++++ b/src/main.c +@@ -6,7 +6,7 @@ + /* By: cacharle +#+ +:+ +#+ */ + /* +#+#+#+#+#+ +#+ */ + /* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */ +-/* Updated: 2020/07/19 20:22:37 by charles ### ########.fr */ ++/* Updated: 2020/07/20 11:21:23 by nahaddac ### ########.fr */ + /* */ + /* ************************************************************************** */ + +@@ -32,10 +32,10 @@ void ast_print(int level, t_ast *ast); + ** pipeline + ** cmd variable preprocess + ** PATH with no permission, link and other file system fun stuff +-** escape lexer ++** escape lexer ------- ok + ** escape split preprocessing (escaped spaces) + ** signal on whole line instead of single command +-** parsing error ++** parsing error ------ ok + ** env local to current minishell process + ** BETTER ERROR HANDLING IS BECOMING URGENT (spagetti code everywhere) + */ +@@ -67,12 +67,12 @@ int main(int argc, char **argv, char **envp) + path = path_update(NULL, env_search(env, "PATH")); + + char *env_exec_path; +- if ((env_exec_path = ft_htget(path, "env")) == NULL) +- { +- errorf("env: command not found\n"); +- return (127); +- } +- env_export(env, "_", env_exec_path); ++ // if ((env_exec_path = ft_htget(path, "env")) == NULL) ++ // { ++ // errorf("env: command not found\n"); ++ // return (127); ++ // } ++ // env_export(env, "_", env_exec_path); + + g_last_status_code = 0; + signal(SIGINT, signal_sigint); +@@ -104,7 +104,7 @@ int main(int argc, char **argv, char **envp) + if (parser_out == NULL || parser_out->syntax_error) + return (1); + +- //ast_print(0, parser_out->ast); ++ ast_print(0, parser_out->ast); + + /* printf("===cmd_argv===\n"); */ + /* ft_lstiter(parser_out->ast->cmd_argv, token_debug); */ +diff --git a/src/parse/parse.c b/src/parse/parse.c +index 89102bc..29b3ccb 100644 +--- a/src/parse/parse.c ++++ b/src/parse/parse.c +@@ -6,7 +6,7 @@ + /* By: nahaddac +#+ +:+ +#+ */ + /* +#+#+#+#+#+ +#+ */ + /* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */ +-/* Updated: 2020/07/19 19:25:29 by charles ### ########.fr */ ++/* Updated: 2020/07/20 10:26:14 by nahaddac ### ########.fr */ + /* */ + /* ************************************************************************** */ + +@@ -47,6 +47,13 @@ t_ret *parse_redir(t_ftlst *input, t_ftlst **redirs) + + push_token(redirs, input->data); + input = input->next; ++ if (input == NULL) ++ { ++ errorf("syntax error near unexpected token `newline'\n", NULL); ++ tmp = ret_wrap_ast(NULL, NULL); ++ tmp->syntax_error = true; ++ return tmp; ++ } + tag = ((t_token *)input->data)->tag; + while(input != NULL + && input->next != NULL +@@ -91,7 +98,7 @@ t_ret *parse_cmd(t_ftlst *input) + else if (tag & TAG_IS_REDIR) + { + tmp = parse_redir(input, &ast->redirs); +- if (tmp->syntax_error || tmp == NULL) ++ if (tmp == NULL || tmp->syntax_error) + return tmp; + input = tmp->rest; + } +diff --git a/src/parse/parse_error.c b/src/parse/parse_error.c +index 42d46ea..84b06b2 100644 +--- a/src/parse/parse_error.c ++++ b/src/parse/parse_error.c +@@ -6,90 +6,8 @@ + /* By: nahaddac +#+ +:+ +#+ */ + /* +#+#+#+#+#+ +#+ */ + /* Created: 2020/06/18 15:09:48 by nahaddac #+# #+# */ +-/* Updated: 2020/07/17 11:24:23 by nahaddac ### ########.fr */ ++/* Updated: 2020/07/20 10:46:26 by nahaddac ### ########.fr */ + /* */ + /* ************************************************************************** */ + + #include "parser.h" +- +-// t_token *error_syntax_parent(t_ftlst *in) +-// { +-// t_token *tk; +-// t_ftlst *first; +-// +-// first = in; +-// while(in != NULL) +-// { +-// tk = in->data; +-// if (tk->tag & TAG_PARENT_OPEN || tk->tag & TAG_PARENT_CLOSE) +-// printf("%s\n", "coucouc"); +-// in = in->next; +-// } +-// return first; +-// } +- +-// int out_error_first(t_token *tk) +-// { +-// int i; +-// +-// i = 0; +-// if(tk->tag & TAG_IS_SEP) +-// return(1); +-// if (tk->tag & TAG_IS_REDIR) +-// { +-// while(tk->content[i]) +-// i++; +-// if (tk->tag & TAG_REDIR_APPEND && i <= 2) +-// return (0); +-// else +-// return(1); +-// } +-// return(0); +-// } +-// +-// t_token *error_syntax_simple(t_ftlst *in) +-// { +-// t_token *tk; +-// size_t i; +-// /* t_ftlst *first; */ +-// +-// tk = in->data; +-// /* first = in; */ +-// if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR)) +-// { +-// if (out_error_first(tk)) +-// { +-// i = ft_strlen(tk->content); +-// if (i >= 2) +-// tk->content[2] = '\0'; +-// tk->content = +-// ft_strjoin3("minishell: syntax error near unexpected token `", +-// tk->content, "'"); +-// return(tk); +-// } +-// } +-// while(in != NULL) +-// { +-// i = 0; +-// tk = in->data; +-// if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR)) +-// { +-// if (((t_token *)in->next->data)->tag & +-// ((t_token*)in->next->data)->tag & TAG_IS_SEP || +-// (((t_token*)in->next->data)->tag & TAG_IS_REDIR)) +-// { +-// tk = in->next->data; +-// i = ft_strlen(tk->content); +-// if (i >= 3) +-// tk->content[2] = '\0'; +-// tk->content = +-// ft_strjoin3("minishell: syntax error near unexpected token `", +-// tk->content, "'"); +-// printf("%s\n",tk->content ); +-// return(tk); +-// } +-// } +-// in = in->next; +-// } +-// return 0; +-// } +diff --git a/src/preprocess.c b/src/preprocess.c +index 2a884df..a834624 100644 +--- a/src/preprocess.c ++++ b/src/preprocess.c +@@ -3,10 +3,10 @@ + /* ::: :::::::: */ + /* preprocess.c :+: :+: :+: */ + /* +:+ +:+ +:+ */ +-/* By: charles +#+ +:+ +#+ */ ++/* By: charles +#+ +:+ +#+ */ + /* +#+#+#+#+#+ +#+ */ + /* Created: 2020/04/03 08:58:49 by charles #+# #+# */ +-/* Updated: 2020/07/19 19:01:53 by charles ### ########.fr */ ++/* Updated: 2020/07/20 14:12:41 by nahaddac ### ########.fr */ + /* */ + /* ************************************************************************** */ + -- cgit