diff options
Diffstat (limited to 'src/ft_u_utils.c')
-rw-r--r-- | src/ft_u_utils.c | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/src/ft_u_utils.c b/src/ft_u_utils.c index cd9e53f..594f2c8 100644 --- a/src/ft_u_utils.c +++ b/src/ft_u_utils.c @@ -14,8 +14,24 @@ #include <stdlib.h> #include <stdint.h> +#include "ft_f_fail.h" +#include "ft_s_destroy.h" +#include "ft_s_lcom.h" #include "ft_s_struct.h" +uint64_t + ft_get_argc(const char *args[]) +{ + uint64_t argc; + + argc = 0; + while (args[argc]) + { + argc++; + } + return (argc); +} + char *ft_get_home_dir(char **envp) { @@ -35,15 +51,46 @@ char return (NULL); } -uint64_t - ft_get_argc(const char *args[]) +/* +** char * +** ft_subst_var_value(const char varname[], const t_msh *msh); +** +** DESCRIPTION +** The ft_subst_var_value() function returns +** a heap-allocated, null-terminated string +** that may later be free'd containing the +** value of the variable varname[] including +** the '$' prefix. NULL is returned if varname[] +** wasn't found. +*/ + +char + *ft_subst_var_value(const char varname[], + t_msh *msh) { - uint64_t argc; + char **p_env; + char *varval; - argc = 0; - while (args[argc]) + p_env = msh->envp; + varval = NULL; + while (*p_env) { - argc++; + if (!ft_strncmp(*p_env, varname + 1, ft_strlen(varname + 1) + 1)) + { + ft_printf("(%s)\n", *p_env); + while (**p_env != '\0' && **p_env != '=') + **p_env += 1; + if (**p_env == '=') + **p_env += 1; + if (!(varval = ft_strdup(*p_env))) + { + ft_lcom_clear(&msh->curr); + ft_s_destroy(msh); + ft_fail_alloc(msh); + } + return (varval); + } + p_env += 1; } - return (argc); + return (NULL); } |