refonte de la gestion des cmd dans parsing

This commit is contained in:
hugogogo
2021-10-29 13:26:38 +02:00
parent b1b8a61921
commit 15bc4d2158
7 changed files with 182 additions and 48 deletions

View File

@@ -28,35 +28,29 @@ int nbr_argv(t_token *token)
return (i);
}
// T_T
// T_L
// T_G
// T_P
// T_D
// T_D
// T_W
void handle_argv(t_token **token, t_cmd *cmd)
{
int argc;
int i;
argc = nbr_argv(*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;
}
if (*token && (*token)->id == T_PIPE)
*token = (*token)->next;
}
//void handle_argv(t_token **token, t_cmd *cmd)
//{
// int argc;
// int i;
//
// argc = nbr_argv(*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;
// }
// if (*token && (*token)->id == T_PIPE)
// *token = (*token)->next;
//}
/*
void handle_fd(t_token *token, t_cmd **cmd)
{
int *pipes_fd;
@@ -142,15 +136,15 @@ t_cmd **fill_cmd(t_token *token, char **envp)
int pipes;
int i;
pipes = nbr_pipes(token);
cmd = ft_calloc(pipes + 2, sizeof(t_cmd*));
cmd[pipes + 1] = NULL;
i = -1;
while (++i <= pipes)
{
cmd[i] = ft_calloc(1, sizeof(t_cmd));
ft_bzero(cmd[i], sizeof(t_cmd));
}
// pipes = nbr_pipes(token);
// cmd = ft_calloc(pipes + 2, sizeof(t_cmd*));
// cmd[pipes + 1] = NULL;
// i = -1;
// while (++i <= pipes)
// {
// cmd[i] = ft_calloc(1, sizeof(t_cmd));
// ft_bzero(cmd[i], sizeof(t_cmd));
// }
i = 0;
while (i <= pipes)
{
@@ -162,4 +156,4 @@ t_cmd **fill_cmd(t_token *token, char **envp)
}
return(cmd);
}
*/