summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-06 22:12:15 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-06 22:12:15 +0200
commit6805673bff96379c03ba32e681f8fb40aad52adc (patch)
treeb1a9b1978ba4f7577e8544bcccf8ccc08c360037
parentCool (diff)
download42-minishell-6805673bff96379c03ba32e681f8fb40aad52adc.tar.gz
42-minishell-6805673bff96379c03ba32e681f8fb40aad52adc.tar.bz2
42-minishell-6805673bff96379c03ba32e681f8fb40aad52adc.tar.xz
42-minishell-6805673bff96379c03ba32e681f8fb40aad52adc.tar.zst
42-minishell-6805673bff96379c03ba32e681f8fb40aad52adc.zip
Improvement
-rw-r--r--TODO.org2
-rw-r--r--src/m_loop.c2
-rw-r--r--src/p_lcom_next.c32
-rw-r--r--src/s_init.c3
4 files changed, 8 insertions, 31 deletions
diff --git a/TODO.org b/TODO.org
index 5db08f1..c19ad6c 100644
--- a/TODO.org
+++ b/TODO.org
@@ -17,7 +17,7 @@
** DONE [#C] fix that goddamn exit(2) 25 leak
** DONE [#C] lpipes leaks on builtins (same as above man)
** DONE [#C] leaks on builtins (same as above man)
-** TODO [#C] Variables stack rework
+** DONE [#C] Variables stack rework
** TODO [#C] Handle memory
** TODO [#C] Go full stack to ken dash in the ass
** TODO [#C] Handle comments better #
diff --git a/src/m_loop.c b/src/m_loop.c
index d5a3ceb..0a810a0 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -40,7 +40,7 @@ void
int32_t fd;
char histfile[PATH_MAX];
- if (ft_strlen(msh->hist) > 0)
+ if (msh->hist[0] != C_NUL && ft_strlen(msh->hist) > 0)
{
u_get_var_value(histfile, "$HISTFILE", PATH_MAX, msh);
if (histfile[0] != C_NUL)
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++;
diff --git a/src/s_init.c b/src/s_init.c
index 8fc8a79..55f9cf0 100644
--- a/src/s_init.c
+++ b/src/s_init.c
@@ -169,12 +169,13 @@ t_msh
return (NULL);
/* TODO: shname: care about "./", try with symlinks */
msh->envp = NULL;
- if (!(msh->envp = dupenv(envp)))
+ if ((msh->envp = dupenv(envp)) == NULL)
return (NULL);
msh->ret = 0;
init_buptr(msh);
msh->curr = NULL;
msh->vars = NULL;
+ msh->hist[0] = '\0';
set_cwd(cwd, msh);
if ((msh->cwd = ft_strdup(cwd)) == NULL)
return (NULL);