summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/m_minishell.c12
-rw-r--r--src/p_lcom.c1
-rw-r--r--src/u_vars_next.c34
3 files changed, 39 insertions, 8 deletions
diff --git a/src/m_minishell.c b/src/m_minishell.c
index e14dbdc..9306955 100644
--- a/src/m_minishell.c
+++ b/src/m_minishell.c
@@ -31,7 +31,8 @@ int
char *const envp[])
{
int32_t ret;
- char *str;
+ char *str_one;
+ char *str_two;
t_msh *msh;
/* TODO: handle general variables | $var */
@@ -41,9 +42,12 @@ int
return (FT_RET_ALLOC);
}
u_subst_var_value("$SHLVL",
- str = ft_itoa(ft_atoi(u_get_var_value("$SHLVL", msh)) + 1), msh);
- ft_memdel((void*)&str);
- lvars_add_front(&msh->vars, lvars_new("var", "value"));
+ str_one =ft_itoa(
+ ft_atoi(str_two = u_get_var_value("$SHLVL", msh)) + 1), msh);
+ ft_memdel((void*)&str_one);
+ ft_memdel((void*)&str_two);
+ /* TODO: delet this */
+ u_subst_var_value("$var", "value", msh);
ret = m_argv(argc, argv, msh);
s_destroy(msh);
return (ret);
diff --git a/src/p_lcom.c b/src/p_lcom.c
index f47e2c1..2dbd505 100644
--- a/src/p_lcom.c
+++ b/src/p_lcom.c
@@ -139,7 +139,6 @@ int8_t
while (i <= count && words[i])
{
next = FALSE;
- /* TODO: split pipes here */
if (ft_strchr(words[i], '|'))
{
if (!(link = lcom_new(NULL, msh)))
diff --git a/src/u_vars_next.c b/src/u_vars_next.c
index 8e02c26..5660449 100644
--- a/src/u_vars_next.c
+++ b/src/u_vars_next.c
@@ -14,10 +14,12 @@
#include <inttypes.h>
#include <stdlib.h>
+#include "d_enum.h"
+#include "s_lvars.h"
#include "s_struct.h"
static int64_t
- u_get_var_line(const char varname[],
+ u_get_env_var_line(const char varname[],
t_msh *msh)
{
char **env_ptr;
@@ -37,6 +39,28 @@ static int64_t
return (-1);
}
+static t_bool
+ u_get_custom_var_existance(const char varname[],
+ t_msh *msh)
+{
+ t_lvars *ptr;
+
+ ptr = msh->vars;
+ while (ptr &&
+ ft_strncmp(varname, ptr->name, ft_strlen(varname)) != 0)
+ {
+ ptr = ptr->next;
+ }
+ if (ptr != NULL)
+ {
+ return (TRUE);
+ }
+ else
+ {
+ return (FALSE);
+ }
+}
+
/*
** void
** u_subst_var_value(const char varname[], const char newval[], t_msh *msh);
@@ -55,7 +79,7 @@ void
char new_line_fmt[2048];
int64_t env_line;
- if ((env_line = u_get_var_line(varname + 1, msh)) > -1)
+ if ((env_line = u_get_env_var_line(varname + 1, msh)) > -1)
{
ft_memdel((void*)&msh->envp[env_line]);
ft_sprintf(new_line_fmt, "%s=%s", varname + 1, newval);
@@ -67,8 +91,12 @@ void
(void)ft_strlcpy(msh->envp[env_line],
new_line_fmt, ft_strlen(new_line_fmt) + 1);
}
+ else if ((env_line = u_get_custom_var_existance(varname + 1, msh)) == TRUE)
+ {
+ lvars_rebind(&msh->vars, varname + 1, newval);
+ }
else
{
- /* TODO: Search in custom vars */
+ lvars_add_front(&msh->vars, lvars_new(varname + 1, newval));
}
}