diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-19 16:59:38 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-19 16:59:38 +0200 |
commit | 49b6183dc0171ac040bdd2faf6f8efa0448567c5 (patch) | |
tree | eaff08562cedef9bf4267b0d17efce0485d2f51e /src/u_vars.c | |
parent | TODO update (diff) | |
download | 42-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 'src/u_vars.c')
-rw-r--r-- | src/u_vars.c | 15 |
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)); } } |