From b84699a3f7e7042a1253f8eaf8c6f19edbc4f08f Mon Sep 17 00:00:00 2001 From: rick Date: Sat, 20 Feb 2021 18:34:43 +0100 Subject: [PATCH] =?UTF-8?q?Impl=C3=A9mentation=20d=E2=80=99echo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/boitoutil/essential_shell.c | 18 +++++++++++++++++- src/boitoutil/oui-dire.c | 21 +++++++++++++++++++++ src/boitoutil/oui-dire.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/boitoutil/oui-dire.c create mode 100644 src/boitoutil/oui-dire.h diff --git a/src/boitoutil/essential_shell.c b/src/boitoutil/essential_shell.c index 5e51f60..b3102a0 100644 --- a/src/boitoutil/essential_shell.c +++ b/src/boitoutil/essential_shell.c @@ -4,7 +4,9 @@ * @date 2021 */ +#include "vars.h" #include "essential_shell.h" +#include "oui-dire.h" #include #include @@ -63,7 +65,21 @@ int native_command(char *command[]) int ret = 1; /* 0 si commande non native */ if (!strcmp(command[0], "cd")) change_dir(command[1]); - + if (!strcmp(command[0], "ouï-dire") || !strcmp(command[0], "oui-dire") + || !strcmp(command[0], "echo")) + { + char *tmp = calloc(MAX_LENGTH, sizeof(char)); + int i = 1; + while (command[i] != NULL) + { + strcat(tmp, command[i]); + *(tmp + strlen(tmp)) = ' '; + i++; + } + if (i == 2) + *(tmp + strlen(tmp) - 1) = '\0'; + echo(tmp); + } else ret = 0; return ret; diff --git a/src/boitoutil/oui-dire.c b/src/boitoutil/oui-dire.c new file mode 100644 index 0000000..6cf03f6 --- /dev/null +++ b/src/boitoutil/oui-dire.c @@ -0,0 +1,21 @@ +/** + */ + +#include "oui-dire.h" + +#include +#include +#include + +void echo(char *args) +{ + char tmp = *args; + int i = 0; + while (tmp != '\0') + { + putchar(tmp); + i++; + tmp = *(args + i); + } + putchar('\n'); +} diff --git a/src/boitoutil/oui-dire.h b/src/boitoutil/oui-dire.h new file mode 100644 index 0000000..3bd1e35 --- /dev/null +++ b/src/boitoutil/oui-dire.h @@ -0,0 +1,10 @@ +/** + */ + +#ifndef _OUIDIRE_ +# define _OUIDIRE_ + +void usage(); +void echo(char *args); + +#endif