From 2ba94f8c24215dce9ff9911967d0146ad6c5e4ea Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 3 Oct 2020 16:03:30 +0200 Subject: Normed s_com --- src/s_com.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/s_com.c') diff --git a/src/s_com.c b/src/s_com.c index baa6401..594fd11 100644 --- a/src/s_com.c +++ b/src/s_com.c @@ -24,7 +24,7 @@ #include "p_subst_vars.h" #include "p_redirs.h" #include "s_lredir.h" -#include "s_struct.h" +#include "s_struct.h" /* ** TODO: norme @@ -90,7 +90,22 @@ void s_com_destroy(t_com **com) if (ptr->rdr != NULL) s_lredir_clear(&ptr->rdr); ft_memdel((void*)&ptr); +} +static void *s_get_nword(char nword[], char word[], t_com *com, t_msh *msh) +{ + nword[0] = C_NUL; + ft_strlcpy(nword, word, ARG_MAX); + if (p_redirs(nword, &com, msh) != 0) + return (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); + return (nword); } t_com *s_com_new(char word[], t_msh *msh) @@ -106,20 +121,9 @@ t_com *s_com_new(char word[], t_msh *msh) com->env_fork = NULL; com->bin = NULL; com->rdr = NULL; - nword[0] = C_NUL; - ft_strlcpy(nword, word, ARG_MAX); - if (p_redirs(nword, &com, msh) != 0) - return (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)) == NULL) - return (NULL); - if ((words = p_subst_home(words, msh)) == NULL) + if (s_get_nword(nword, word, com, msh) == NULL + || (words = p_split_args(nword)) == NULL + || (words = p_subst_home(words, msh)) == NULL) return (NULL); words = p_check_args_equals(words, msh); if (msh->env_fork_tmp[0][0] != '\0') -- cgit v1.2.3