diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-21 19:07:31 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-21 19:07:31 +0200 |
commit | 1b32d0a1af2e147523e575480d04fc085da425cf (patch) | |
tree | a6ca77b2da8e9aeee5118107cddb79c002135a38 /src/ft_b_echo.c | |
parent | Builtin exit is bav (diff) | |
download | 42-minishell-1b32d0a1af2e147523e575480d04fc085da425cf.tar.gz 42-minishell-1b32d0a1af2e147523e575480d04fc085da425cf.tar.bz2 42-minishell-1b32d0a1af2e147523e575480d04fc085da425cf.tar.xz 42-minishell-1b32d0a1af2e147523e575480d04fc085da425cf.tar.zst 42-minishell-1b32d0a1af2e147523e575480d04fc085da425cf.zip |
Better echo
Diffstat (limited to '')
-rw-r--r-- | src/ft_b_echo.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/ft_b_echo.c b/src/ft_b_echo.c index 6a3af34..abaf564 100644 --- a/src/ft_b_echo.c +++ b/src/ft_b_echo.c @@ -15,27 +15,36 @@ #include "ft_s_struct.h" #include "ft_u_utils.h" + /* TODO: norme, echo $variables, echo "quoted text" */ + uint8_t ft_b_echo(char *args[], t_msh *msh) { + const uint64_t argc = ft_get_argc((const char **)args); char **ptr; int8_t nopt; (void)msh; ptr = args; nopt = 0; - if (ft_strncmp(ptr[0], "-n", 2) == 0) - { - nopt = 1; - ptr += 1; - } - ft_printf("%s", *ptr); - ptr++; - while (*ptr) + if (argc >= 1) { - ft_printf(" %s", *ptr); - ptr++; + if (ft_strncmp(ptr[0], "-n", 2) == 0) + { + nopt = 1; + ptr += 1; + } + if (argc - nopt >= 1) + { + ft_printf("%s", *ptr); + ptr++; + while (*ptr) + { + ft_printf(" %s", *ptr); + ptr++; + } + } } if (nopt == 0) ft_printf("\n"); |