summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_d_define.h1
-rw-r--r--src/ft_s_init.c5
-rw-r--r--src/ft_s_init.h3
-rw-r--r--src/ft_u_vars.c39
-rw-r--r--src/minishell.c2
5 files changed, 40 insertions, 10 deletions
diff --git a/src/ft_d_define.h b/src/ft_d_define.h
index b1e9a72..e5fd22f 100644
--- a/src/ft_d_define.h
+++ b/src/ft_d_define.h
@@ -19,7 +19,6 @@
** ====== CLASSICS ======
*/
-#define FT_DEFAULT_SHNAME "minishell"
#define FT_PS_ONE "minishell ~> "
#define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|type"
#define FT_BUILTINS_COUNT 8
diff --git a/src/ft_s_init.c b/src/ft_s_init.c
index 5de17c1..46dac90 100644
--- a/src/ft_s_init.c
+++ b/src/ft_s_init.c
@@ -19,7 +19,8 @@
#include "ft_s_init.h"
t_msh
- *ft_init_msh(char *envp[])
+ *ft_init_msh(const char *argv[],
+ char *envp[])
{
t_msh *msh;
@@ -27,7 +28,7 @@ t_msh
return (NULL);
if (!(msh->ps_one = ft_strdup(FT_PS_ONE)))
return (NULL);
- if (!(msh->shname = ft_strdup(FT_DEFAULT_SHNAME)))
+ if (!(msh->shname = ft_strdup(argv[0])))
return (NULL);
msh->cwd = NULL;
msh->cwd = getcwd(NULL, 0);
diff --git a/src/ft_s_init.h b/src/ft_s_init.h
index c5ce54a..e860925 100644
--- a/src/ft_s_init.h
+++ b/src/ft_s_init.h
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include "ft_s_struct.h"
-t_msh *ft_init_msh(char *envp[]);
+t_msh *ft_init_msh(const char *argv[],
+ char *envp[]);
#endif
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);
}
diff --git a/src/minishell.c b/src/minishell.c
index 36ba25a..f5216a8 100644
--- a/src/minishell.c
+++ b/src/minishell.c
@@ -31,7 +31,7 @@ int
/* TODO: increment $SHLVL */
/* TODO: handle general variables | $var */
- if (!(msh = ft_init_msh(envp)))
+ if (!(msh = ft_init_msh(argv, envp)))
{
ft_dprintf(2, "%s\n", strerror(errno));
return (FT_RET_ALLOC);