summaryrefslogtreecommitdiffstats
path: root/src/u_vars_next.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/u_vars_next.c34
1 files changed, 31 insertions, 3 deletions
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));
}
}