From a55f16b240a61dbea25f678166d0b9e98e8d78a3 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 21 Apr 2020 17:56:16 +0200 Subject: Messy echo --- src/ft_b_echo.c | 21 ++++++++++++++++++--- src/ft_u_utils.c | 26 ++++++++++++++++++++++++++ src/ft_u_utils.h | 20 ++++++++++++++++++++ src/minishell.c | 1 + 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/ft_u_utils.c create mode 100644 src/ft_u_utils.h (limited to 'src') diff --git a/src/ft_b_echo.c b/src/ft_b_echo.c index 326967d..6a3af34 100644 --- a/src/ft_b_echo.c +++ b/src/ft_b_echo.c @@ -13,16 +13,31 @@ #include #include #include "ft_s_struct.h" +#include "ft_u_utils.h" uint8_t ft_b_echo(char *args[], t_msh *msh) { + char **ptr; + int8_t nopt; + (void)msh; - while (*args) + ptr = args; + nopt = 0; + if (ft_strncmp(ptr[0], "-n", 2) == 0) + { + nopt = 1; + ptr += 1; + } + ft_printf("%s", *ptr); + ptr++; + while (*ptr) { - ft_printf("%s\n", *args); - args++; + ft_printf(" %s", *ptr); + ptr++; } + if (nopt == 0) + ft_printf("\n"); return (0); } diff --git a/src/ft_u_utils.c b/src/ft_u_utils.c new file mode 100644 index 0000000..f5df2f4 --- /dev/null +++ b/src/ft_u_utils.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_u_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include + +uint64_t + ft_get_argc(const char *args[]) +{ + uint64_t argc; + + argc = 0; + while (args[argc]) + { + argc++; + } + return (argc); +} diff --git a/src/ft_u_utils.h b/src/ft_u_utils.h new file mode 100644 index 0000000..1a3b324 --- /dev/null +++ b/src/ft_u_utils.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_u_utils.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_U_UTILS_H +#define FT_U_UTILS_H + +#include + +uint64_t ft_get_argc(const char *args[]); + +#endif diff --git a/src/minishell.c b/src/minishell.c index fc4c4be..412fae1 100644 --- a/src/minishell.c +++ b/src/minishell.c @@ -52,4 +52,5 @@ int ** m_ -> core minishell related ** p_ -> parse related ** s_ -> structs related +** u_ -> utils related */ -- cgit v1.2.3