From eedfe4a0eeadcf76a54a14f365ba0dbf74aff1dd Mon Sep 17 00:00:00 2001 From: Loic Deridder Date: Wed, 15 Jan 2025 08:32:26 +0100 Subject: [PATCH] echo --- includes/builtins.h | 1 + srcs/builtins/echo.c | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/includes/builtins.h b/includes/builtins.h index f02cbfe..d8ab256 100644 --- a/includes/builtins.h +++ b/includes/builtins.h @@ -10,6 +10,7 @@ # include // void echo(char *msg, int flag); +void builtin_echo(char *arg); void builtin_exit(char *arg, bool depth); void builtin_pwd(char *arg); diff --git a/srcs/builtins/echo.c b/srcs/builtins/echo.c index 1bda5f9..42c7a95 100644 --- a/srcs/builtins/echo.c +++ b/srcs/builtins/echo.c @@ -1,8 +1,37 @@ #include "../../includes/builtins.h" -// void echo(char *msg, int flag) -// { -// printf("%s", msg); -// if (flag == 0) -// printf("\n"); -// } +int is_silentchar(char c) +{ + if (c == 'n' || c == '-' || c == ' ') + return (1); + else + return (0); +} + +int is_silent(char *str) +{ + int i; + + i = 4; + while (str[i] && str[i] == ' ') + i++; + if (str[i] && str[i] == '-') + { + i++; + if (str[i] && str[i] == 'n') + return (1); + } + return (0); +} + +void builtin_echo(char *arg) +{ + int i; + + i = 4; + while (arg[i] && is_silentchar(arg[i])) + i++; + printf("%s", &arg[i]); + if (!is_silent(arg)) + printf("\n"); +}