summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-05-01 14:40:02 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-05-01 14:40:02 +0200
commitaae7ad207625996732f133188fc7a403855ce86d (patch)
tree86c3745fe3a224b0de82216ed314f022a4a64db5 /src
parentMerge branch 'vars' (diff)
download42-minishell-aae7ad207625996732f133188fc7a403855ce86d.tar.gz
42-minishell-aae7ad207625996732f133188fc7a403855ce86d.tar.bz2
42-minishell-aae7ad207625996732f133188fc7a403855ce86d.tar.xz
42-minishell-aae7ad207625996732f133188fc7a403855ce86d.tar.zst
42-minishell-aae7ad207625996732f133188fc7a403855ce86d.zip
Vars not ok
Diffstat (limited to 'src')
-rw-r--r--src/ft_d_define.h1
-rw-r--r--src/ft_p_lcom_next.c13
-rw-r--r--src/ft_u_vars.c19
-rw-r--r--src/minishell.c9
4 files changed, 28 insertions, 14 deletions
diff --git a/src/ft_d_define.h b/src/ft_d_define.h
index e5fd22f..4152e0d 100644
--- a/src/ft_d_define.h
+++ b/src/ft_d_define.h
@@ -37,6 +37,7 @@
#define FT_ZER_VAR "$0"
#define FT_RET_VAR "$?"
+#define FT_PID_VAR "$$"
/*
** ====== FAIL MSG ======
diff --git a/src/ft_p_lcom_next.c b/src/ft_p_lcom_next.c
index 07fadbe..8313b08 100644
--- a/src/ft_p_lcom_next.c
+++ b/src/ft_p_lcom_next.c
@@ -29,7 +29,8 @@ static int8_t
varval = NULL;
s_varname = NULL;
varlen = i + 1;
- while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$')
+ while ((*p_words)[varlen] != '\0' &&
+ !ft_ischarset("$=/#@%^*+{}[],.?-", (*p_words)[varlen]))
varlen += 1;
if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen - i)))
return (-1);
@@ -48,12 +49,16 @@ char
int64_t i;
p_words = words;
+ i = 0;
while (*p_words)
{
- while ((i = ft_strlchr(*p_words, '$')) != -1)
+ while ((i = ft_strlchr((*p_words), '$')) != -1)
{
- if (ft_subst_those_vars(i, p_words, msh) != 0)
- return (NULL);
+ if (*(*p_words) + i - 1 != '\\')
+ {
+ if (ft_subst_those_vars(i, p_words, msh) != 0)
+ return (NULL);
+ }
}
p_words += 1;
}
diff --git a/src/ft_u_vars.c b/src/ft_u_vars.c
index 99f35bb..cb020e3 100644
--- a/src/ft_u_vars.c
+++ b/src/ft_u_vars.c
@@ -85,8 +85,8 @@ static char
}
static char
- *ft_get_special(const char varname[],
- t_msh *msh)
+ *ft_get_special_var(const char varname[],
+ t_msh *msh)
{
char *varval;
@@ -113,6 +113,15 @@ static char
return (NULL);
}
+static char
+ *ft_get_cstm_vr(const char varname[],
+ t_msh *msh)
+{
+ (void)varname;
+ (void)msh;
+ return (NULL);
+}
+
/*
** char *
** ft_subst_var_value(const char varname[], const t_msh *msh);
@@ -136,7 +145,11 @@ char
char *rvarname;
varval = NULL;
- if ((varval = ft_get_special(varname, msh)) != NULL)
+ if ((varval = ft_get_special_var(varname, msh)) != NULL)
+ {
+ return (varval);
+ }
+ else if ((varval = ft_get_cstm_vr(varname, msh)) != NULL)
{
return (varval);
}
diff --git a/src/minishell.c b/src/minishell.c
index 37e1520..ee79f8f 100644
--- a/src/minishell.c
+++ b/src/minishell.c
@@ -30,14 +30,9 @@ int
t_msh *msh;
int32_t ret;
- char *str;
- str = ft_strdup("qwe\'");
- ft_printf("%s\n", str);
- str = ft_strsubst(str, "\'", "");
- ft_printf("%s\n", str);
- return (0);
/* TODO: increment $SHLVL */
- /* TODO: also set $SHELL */
+ /* TODO: also set $SHELL | maybe not bash does not set $SHELL */
+ /* only zsh does */
/* TODO: handle general variables | $var */
if (!(msh = ft_init_msh(argv, envp)))
{