Implémentation d’echo
This commit is contained in:
parent
f044af9e8d
commit
b84699a3f7
3 changed files with 48 additions and 1 deletions
|
@ -4,7 +4,9 @@
|
|||
* @date 2021
|
||||
*/
|
||||
|
||||
#include "vars.h"
|
||||
#include "essential_shell.h"
|
||||
#include "oui-dire.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -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;
|
||||
|
|
21
src/boitoutil/oui-dire.c
Normal file
21
src/boitoutil/oui-dire.c
Normal 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
10
src/boitoutil/oui-dire.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
*/
|
||||
|
||||
#ifndef _OUIDIRE_
|
||||
# define _OUIDIRE_
|
||||
|
||||
void usage();
|
||||
void echo(char *args);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue