cmd argv fill with word and without redirections
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user