From 75987a117e3162e5b2026ad5c95d22fda2e8cff3 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Sat, 30 Oct 2021 10:20:43 +0200 Subject: [PATCH] cmd argv fill with word and without redirections --- srcs/parsing/parsing.c | 79 +++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/srcs/parsing/parsing.c b/srcs/parsing/parsing.c index cccb14d..b5f6452 100644 --- a/srcs/parsing/parsing.c +++ b/srcs/parsing/parsing.c @@ -51,65 +51,54 @@ t_cmd **create_cmd(t_token *token_list, size_t cmd_nbr) // T_DGREAT, //'>>' // T_WORD // count nbr word in cmd, minus redirection and heredoc -int next_cmd(t_token **token) +int next_cmd(t_token *token) { int i; i = 0; - while (*token && (*token)->id != T_PIPE) + while (token && token->id != T_PIPE) { - if ((*token)->id != T_WORD) + if (token->id != T_WORD) i--; else i++; - *token = (*token)->next; + token = token->next; } - if (*token && (*token)->id == T_PIPE) - *token = (*token)->next; + if (token && token->id == T_PIPE) + token = token->next; return (i); } -void handle_argv(t_token *token, t_cmd **cmd_arr, size_t cmd_nbr) +void handle_argv(t_token *token, t_cmd **cmd, size_t cmd_nbr) { int argc; + int j; int i; - (void)cmd_arr; - (void)token; - (void)cmd_nbr; + i = 0; while (cmd_nbr) { - argc = next_cmd(&token); - cmd->argv = calloc(argc + 1, sizeof(char *)); - cmd->argv[argc] = NULL; -// i = 0; -// while (token && token->id != T_PIPE) -// { -// if (token->id == T_WORD) -// { -// cmd->argv[i] = ft_strdup(token->content); -// i++; -// } -// token = token->next; -// } -// cmd_nbr--; + argc = next_cmd(token); + cmd[i]->argv = calloc(argc + 1, sizeof(char *)); + cmd[i]->argv[argc] = NULL; + j = 0; + while (token && token->id != T_PIPE) + { + if (token->id == T_WORD) + { + cmd[i]->argv[j] = ft_strdup(token->content); + j++; + } + else if (token->id != T_PIPE) + token = token->next; + if (token->id != T_PIPE) + token = token->next; + } + if (token && token->id == T_PIPE) + token = token->next; + cmd_nbr--; + i++; } - -// cmd->argv = calloc(argc + 1, sizeof(char *)); -// cmd->argv[argc] = NULL; - -// i = 0; -// while (*token && (*token)->id != T_PIPE) -// { -// if ((*token)->id == T_WORD) -// { -// cmd->argv[i] = ft_strdup((*token)->content); -// i++; -// } -// *token = (*token)->next; -// } -// if (*token && (*token)->id == T_PIPE) -// *token = (*token)->next; } t_cmd **parsing(t_token *token_list, char **envp) @@ -137,6 +126,16 @@ t_cmd **parsing(t_token *token_list, char **envp) // cmd_expansion(cmd_arr, envp); handle_argv(token_list, cmd_arr, cmd_nbr); + +int j; +j = 0; +while (cmd_arr[j]) +{ + printf("%i\n", j); + print_matrix(cmd_arr[j]->argv, " / "); + j++; +} + // if (!handle_builtin(token, cmd[i])) // handle_cmd(cmd[i]->argv, envp);