From 1b32d0a1af2e147523e575480d04fc085da425cf Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 21 Apr 2020 19:07:31 +0200 Subject: Better echo --- src/ft_b_echo.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src') 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"); -- cgit v1.2.3