From 4e79c9227066b84632bafb3dda439f463c1e922b Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 26 Apr 2020 18:27:38 +0200 Subject: Got special variables running --- src/ft_u_vars.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'src/ft_u_vars.c') diff --git a/src/ft_u_vars.c b/src/ft_u_vars.c index 4d10aeb..80288e6 100644 --- a/src/ft_u_vars.c +++ b/src/ft_u_vars.c @@ -14,6 +14,7 @@ #include #include +#include "ft_d_define.h" #include "ft_f_fail.h" #include "ft_s_destroy.h" #include "ft_s_lcom.h" @@ -39,7 +40,7 @@ static char } static char - *ft_dup_val(char *p_env, + *ft_dup_env(char *p_env, char *rvarname, t_msh *msh) { @@ -72,7 +73,7 @@ static char *p_env += 1; if (**p_env == '=') *p_env += 1; - varval = ft_dup_val(*p_env, rvarname, msh); + varval = ft_dup_env(*p_env, rvarname, msh); return (varval); } p_env += 1; @@ -80,6 +81,35 @@ static char return (NULL); } +static char + *ft_get_special(const char varname[], + t_msh *msh) +{ + char *varval; + + if (!ft_strncmp(varname, FT_RET_VAR, 3)) + { + if (!(varval = ft_uitoa(msh->ret))) + { + ft_lcom_clear(&msh->curr); + ft_s_destroy(msh); + ft_fail_alloc(msh); + } + return (varval); + } + else if (!ft_strncmp(varname, FT_ZER_VAR, 3)) + { + if (!(varval = ft_strdup(msh->shname))) + { + ft_lcom_clear(&msh->curr); + ft_s_destroy(msh); + ft_fail_alloc(msh); + } + return (varval); + } + return (NULL); +} + /* ** char * ** ft_subst_var_value(const char varname[], const t_msh *msh); @@ -98,19 +128,18 @@ char t_msh *msh) { /* TODO: check behaviour on empty vars -> "QWE=" */ - /* TODO: add support for special variables -> "$? $0..." */ /* TODO: add support for global variables -> "$hey $nigga..." */ char *varval; char *rvarname; varval = NULL; - rvarname = ft_set_rva(varname, msh); - if ((varval = ft_get_special()) != NULL) + if ((varval = ft_get_special(varname, msh)) != NULL) { return (varval); } else { + rvarname = ft_set_rva(varname, msh); varval = ft_get_frm_env(rvarname, msh); return (varval); } -- cgit v1.2.3