summaryrefslogtreecommitdiffstats
path: root/src/u_vars.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-19 16:59:38 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-19 16:59:38 +0200
commit49b6183dc0171ac040bdd2faf6f8efa0448567c5 (patch)
treeeaff08562cedef9bf4267b0d17efce0485d2f51e /src/u_vars.c
parentTODO update (diff)
download42-minishell-49b6183dc0171ac040bdd2faf6f8efa0448567c5.tar.gz
42-minishell-49b6183dc0171ac040bdd2faf6f8efa0448567c5.tar.bz2
42-minishell-49b6183dc0171ac040bdd2faf6f8efa0448567c5.tar.xz
42-minishell-49b6183dc0171ac040bdd2faf6f8efa0448567c5.tar.zst
42-minishell-49b6183dc0171ac040bdd2faf6f8efa0448567c5.zip
Cleaner variables handling $0 $1 $2 $3
Diffstat (limited to '')
-rw-r--r--src/u_vars.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/u_vars.c b/src/u_vars.c
index 28040b4..eafcace 100644
--- a/src/u_vars.c
+++ b/src/u_vars.c
@@ -54,16 +54,25 @@ static void
size_t dstsize,
t_msh *msh)
{
- char tmp[4];
+ char tmp[255];
+ int32_t n;
if (ft_strncmp(varname, FT_RET_VAR, 3) == 0)
{
ft_uitoa_s(tmp, msh->ret);
ft_strlcpy(str, tmp, 4);
}
- else if (ft_strncmp(varname, FT_ZER_VAR, 3) == 0)
+ else if (ft_strncmp(varname, FT_ARGC_VAR, 3) == 0)
{
- ft_strlcpy(str, msh->shname, dstsize);
+ ft_uitoa_s(tmp, msh->argc);
+ ft_strlcpy(str, tmp, 255);
+ }
+ else if (ft_strlen(varname) == 2 && ft_isdigit(*(varname + 1)) == TRUE)
+ {
+ if ((n = ft_atoi(varname + 1)) < msh->argc)
+ ft_strlcpy(str, msh->argv[n], dstsize);
+ else
+ (void)ft_memcpy(str, "", 1 * sizeof(char));
}
}