diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/eval/cmd.c | 16 | ||||
| -rw-r--r-- | src/eval/utils_eval.c | 34 | ||||
| -rw-r--r-- | src/main.c | 20 | ||||
| -rw-r--r-- | src/parse/parse.c | 11 | ||||
| -rw-r--r-- | src/parse/parse_error.c | 84 | ||||
| -rw-r--r-- | src/preprocess.c | 4 |
6 files changed, 69 insertions, 100 deletions
diff --git a/src/eval/cmd.c b/src/eval/cmd.c index 87c9bbf..c81c349 100644 --- a/src/eval/cmd.c +++ b/src/eval/cmd.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* cmd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/14 10:41:31 by charles #+# #+# */ -/* Updated: 2020/07/19 19:00:54 by charles ### ########.fr */ +/* Updated: 2020/07/20 14:53:40 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); + preprocess(tmp, env); + ft_lstiter(tmp, token_debug); + + 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/eval/utils_eval.c b/src/eval/utils_eval.c new file mode 100644 index 0000000..374411e --- /dev/null +++ b/src/eval/utils_eval.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils_eval.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/07/20 13:07:25 by nahaddac #+# #+# */ +/* Updated: 2020/07/20 14:51:40 by nahaddac ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "eval.h" + + +t_ftlst *split_token(t_ftlst **lst, enum e_token_tag tag) +{ + t_ftlst *curr; + t_ftlst *start; + + start = *lst; + curr = *lst; + while (curr != NULL || ((t_token *)curr->data)->tag & tag) + { + if (curr->next == NULL || (!(((t_token *)curr->next->data)->tag & tag))) + { + *lst = curr->next; + curr->next = NULL; + return start; + } + curr = curr->next; + } + return start; +} @@ -6,7 +6,7 @@ /* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <nahaddac@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <nahaddac@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ |
