diff options
Diffstat (limited to 'src/s_com.c')
-rw-r--r-- | src/s_com.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/s_com.c b/src/s_com.c index a9d8f84..ebf7b87 100644 --- a/src/s_com.c +++ b/src/s_com.c @@ -12,23 +12,25 @@ #include <libft.h> #include <stdlib.h> +#include <limits.h> +#include "d_define.h" #include "f_fail.h" -#include "p_lcom.h" -#include "p_lcom_next.h" -#include "p_lcom_vars.h" +#include "p_args.h" +#include "p_lblock.h" +#include "p_lblock_next.h" +>>>>>>> master #include "s_struct.h" static int8_t - fill_com(char *words[], - t_com **com) + s_fill_com(char *words[], t_com **com) { /* TODO: norme is bav (for now)*/ int64_t i; int64_t j; - i = -1; - if (words[0]) + i = 0; + if (words[0] != NULL) { if (((*com)->bin = (char*)malloc((ft_strlen(words[0]) + 1) * sizeof(char))) == NULL) @@ -55,8 +57,7 @@ static int8_t } static void - com_cpy_env_fork(t_com **com, - t_msh *msh) + s_com_cpy_env_fork(t_com **com, t_msh *msh) { size_t i; size_t j; @@ -94,11 +95,12 @@ void } t_com - *s_com_new(char word[], - t_msh *msh) + *s_com_new(char word[], t_msh *msh) { + char nword[ARG_MAX]; t_com *com; char **words; + size_t ret; if ((com = (t_com*)malloc(sizeof(t_com))) == NULL) return (NULL); @@ -108,18 +110,25 @@ t_com com->rdrfd = 0; com->rdrpath = NULL; com->env_fork = NULL; - if (get_redir(word, &com) != 0) - return (NULL); - if ((words = p_subst_args(word, com->redir)) == NULL) + nword[0] = C_NUL; + ft_strlcpy(nword, word, ARG_MAX); + if (p_get_redir(nword, &com) != 0) return (NULL); - if ((words = p_subst_vars(words, msh)) == NULL) + if (msh->alias != NULL) + { + ret = p_subst_alias(nword, TRUE, msh); + while (ret != 0) + ret = p_subst_alias(nword, FALSE, msh); + } + p_subst_vars(nword, msh); + if ((words = p_split_args(nword, com->redir)) == NULL) return (NULL); if ((words = p_subst_home(words, msh)) == NULL) return (NULL); words = p_check_args_equals(words, msh); if (msh->env_fork_tmp[0][0] != '\0') - com_cpy_env_fork(&com, msh); - if (fill_com(words, &com) < 0) + s_com_cpy_env_fork(&com, msh); + if (s_fill_com(words, &com) < 0) { ft_delwords(words); return (NULL); |