Implémentation d’echo

This commit is contained in:
rick 2021-02-20 18:34:43 +01:00
parent f044af9e8d
commit b84699a3f7
Signed by: Rick
GPG key ID: 2B593F087240EE99
3 changed files with 48 additions and 1 deletions

View file

@ -4,7 +4,9 @@
* @date 2021 * @date 2021
*/ */
#include "vars.h"
#include "essential_shell.h" #include "essential_shell.h"
#include "oui-dire.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -63,7 +65,21 @@ int native_command(char *command[])
int ret = 1; /* 0 si commande non native */ int ret = 1; /* 0 si commande non native */
if (!strcmp(command[0], "cd")) if (!strcmp(command[0], "cd"))
change_dir(command[1]); 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 else
ret = 0; ret = 0;
return ret; return ret;

21
src/boitoutil/oui-dire.c Normal file
View file

@ -0,0 +1,21 @@
/**
*/
#include "oui-dire.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void echo(char *args)
{
char tmp = *args;
int i = 0;
while (tmp != '\0')
{
putchar(tmp);
i++;
tmp = *(args + i);
}
putchar('\n');
}

10
src/boitoutil/oui-dire.h Normal file
View file

@ -0,0 +1,10 @@
/**
*/
#ifndef _OUIDIRE_
# define _OUIDIRE_
void usage();
void echo(char *args);
#endif