diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 17 | ||||
| -rwxr-xr-x | src/parse/parse.c | 27 | ||||
| -rw-r--r-- | src/preprocess.c | 17 |
3 files changed, 36 insertions, 25 deletions
@@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */ -/* Updated: 2020/06/16 10:11:30 by charles ### ########.fr */ +/* Updated: 2020/06/16 13:47:30 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ void token_debug(void *v) t_token *t; t= v; - printf("[%4d] (%s)\n", t->tag, t->content); + printf("[%4d %d] (%s)\n", t->tag, !!(t->tag & TAG_STICK), t->content); } int main(int argc, char **argv, char **envp) @@ -36,24 +36,23 @@ int main(int argc, char **argv, char **envp) env = env_from_array(envp); path = path_update(NULL, env_search(env, "PATH")); - + /* printf("%s\n", argv[2]); */ if (argc == 3 && ft_strcmp(argv[1], "-c") == 0) { t_ftlst *lex_out = lexer(ft_strdup(argv[2])); - ft_lstiter(lex_out, token_debug); + /* ft_lstiter(lex_out, token_debug); */ t_ret *parser_out = parse(lex_out); - /* printf("%p\n", parser_out->ast->cmd_argv); */ - /* printf("%p\n", parser_out->ast->redirs); */ - + /* printf("===cmd_argv===\n"); */ /* ft_lstiter(parser_out->ast->cmd_argv, token_debug); */ + /* printf("===redirs===\n"); */ /* ft_lstiter(parser_out->ast->redirs, token_debug); */ - //int eval_out = eval_cmd(env, path, parser_out->ast); - //(void)eval_out; + int eval_out = eval_cmd(env, path, parser_out->ast); + (void)eval_out; } ft_htdestroy(path, free); diff --git a/src/parse/parse.c b/src/parse/parse.c index 867325b..fe4f9a2 100755 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -43,21 +43,24 @@ t_ret *parse(t_ftlst *input) if (tag & TAG_IS_STR && tag & TAG_STICK) ret->rest = ret->rest->next; else + { + ret->rest = ret->rest->next; break; + } } } } - while(ret->ast->cmd_argv != NULL) - { - printf("[%s]\n", ((t_token *)ret->ast->cmd_argv->data)->content); - ret->ast->cmd_argv = ret->ast->cmd_argv->next; - } - while(ret->ast->redirs != NULL) - { - printf("[%s]\n", ((t_token *)ret->ast->redirs->data)->content); - ret->ast->redirs = ret->ast->redirs->next; - } - ast_destroy(ret->ast); - ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy); + /* while(ret->ast->cmd_argv != NULL) */ + /* { */ + /* printf("[%s]\n", ((t_token *)ret->ast->cmd_argv->data)->content); */ + /* ret->ast->cmd_argv = ret->ast->cmd_argv->next; */ + /* } */ + /* while(ret->ast->redirs != NULL) */ + /* { */ + /* printf("[%s]\n", ((t_token *)ret->ast->redirs->data)->content); */ + /* ret->ast->redirs = ret->ast->redirs->next; */ + /* } */ + /* ast_destroy(ret->ast); */ + /* ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy); */ return first; } diff --git a/src/preprocess.c b/src/preprocess.c index 9e61e25..eb6ac3b 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/15 13:30:04 by charles ### ########.fr */ +/* Updated: 2020/06/16 13:49:38 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -131,6 +131,7 @@ char **preprocess(t_ftlst **tokens, t_env env) while (++i < argv->size) { token = argv->data[i]; + /* printf("|%s| %d\n", token->content, token->tag & TAG_STICK); */ if (token->tag & TAG_STR_SINGLE) continue ; token->content = st_iterpolate_env(token->content, token->tag, env); @@ -138,18 +139,26 @@ char **preprocess(t_ftlst **tokens, t_env env) { if (ft_strchr(token->content, '*') != NULL) token->content = st_iterpolate_globs(token->content); - if ((i = st_splat_arg(argv, i)) == (size_t)-1) - return (NULL); + if (ft_strchr(token->content, ' ') != NULL) + { + if ((i = st_splat_arg(argv, i)) == (size_t)-1) + return (NULL); + if (token->tag & TAG_STICK) // FIXME temporary will not work with `echo *''` + ((t_token*)argv->data[i])->tag |= TAG_STICK; + } } } + /* printf("-------\n"); */ t_token *next; i = -1; while (++i < argv->size - 1) { token = argv->data[i]; + /* printf("|%s| %d\n", token->content, token->tag & TAG_STICK); */ while (token->tag & TAG_STICK && i + 1 < argv->size) { + /* printf("2|%s|\n", token->content); */ next = argv->data[i + 1]; token->content = ft_strjoinf_fst(token->content, next->content); if (token->content == NULL) @@ -175,7 +184,7 @@ char *preprocess_filename(t_ftlst **tokens, t_env env) return (NULL); if (strs[1] != NULL) { - // save tokens + /* save tokens */ error_eval_put(ERROR_AMBIGUOUS_REDIR, strs[1]); ft_split_destroy(strs); return (NULL); |
