summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/m_loop.c2
-rw-r--r--src/p_lcom_next.c32
-rw-r--r--src/s_init.c3
3 files changed, 7 insertions, 30 deletions
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);