diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-26 18:27:38 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-26 18:27:38 +0200 |
commit | 4e79c9227066b84632bafb3dda439f463c1e922b (patch) | |
tree | 5bf5662c5a8ab7529a7802e1235256d866fef233 /src/ft_u_vars.c | |
parent | Nice vars gathering (diff) | |
download | 42-minishell-4e79c9227066b84632bafb3dda439f463c1e922b.tar.gz 42-minishell-4e79c9227066b84632bafb3dda439f463c1e922b.tar.bz2 42-minishell-4e79c9227066b84632bafb3dda439f463c1e922b.tar.xz 42-minishell-4e79c9227066b84632bafb3dda439f463c1e922b.tar.zst 42-minishell-4e79c9227066b84632bafb3dda439f463c1e922b.zip |
Got special variables running
Diffstat (limited to '')
-rw-r--r-- | src/ft_u_vars.c | 39 |
1 files changed, 34 insertions, 5 deletions
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 <stdlib.h> #include <stdint.h> +#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); } |