From 6805673bff96379c03ba32e681f8fb40aad52adc Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 6 Sep 2020 22:12:15 +0200 Subject: Improvement --- src/p_lcom_next.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) (limited to 'src/p_lcom_next.c') diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c index 7ae0331..2f675f3 100644 --- a/src/p_lcom_next.c +++ b/src/p_lcom_next.c @@ -25,32 +25,8 @@ /* TODO: norme */ -/* static int8_t */ -/* p_subst_those_vars(int64_t i, */ -/* char **p_words, */ -/* t_msh *msh) */ -/* { */ -/* size_t varlen; */ -/* char *s_varname; */ -/* char *varval; */ - -/* varval = NULL; */ -/* s_varname = NULL; */ -/* varlen = i + 1; */ -/* while ((*p_words)[varlen] != '\0' && */ -/* ft_ischarset("$=/#@%^*+{}[],.-", (*p_words)[varlen]) == FALSE) */ -/* varlen += 1; */ -/* if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen - i))) */ -/* return (-1); */ -/* varval = u_get_var_value(s_varname, msh); */ -/* *p_words = ft_strsubst(*p_words, s_varname, varval); */ -/* ft_memdel((void*)&s_varname); */ -/* ft_memdel((void*)&varval); */ -/* return (0); */ -/* } */ - static char - *p_subst_this_var(int64_t i, char word[], t_msh *msh) + *p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh) { char tmp[4096]; char varval[4096]; @@ -68,9 +44,9 @@ static char ft_strlcpy(tmp, ptr + varlen, varlen); word = ft_nrealloc(word, i, i + ft_strlen(varval) + ft_strlen(tmp) + 1); ft_strlcpy(word + i, varval, ft_strlen(varval) + 1); - ft_strlcpy(word + i + ft_strlen(varval), tmp, ft_strlen(tmp) + 1); + ft_strlcpy(word + (i + ft_strlen(varval)), tmp, ft_strlen(tmp) + 1); ft_printf("[%s]\n", word); - exit(0); + *(p) = word + (i + ft_strlen(varval) - 1); return (word); } @@ -84,7 +60,7 @@ char { if (*ptr == '$' && u_is_not_escaped(word, ptr) == TRUE) { - if ((word = p_subst_this_var((ptr - word), word, msh)) == NULL) + if ((word = p_subst_this_var(&ptr, (ptr - word), word, msh)) == NULL) return (NULL); } ptr++; -- cgit v1.2.3