Ajout export pour init. var. (#6 #5)

This commit is contained in:
rick 2021-02-24 02:23:21 +01:00
parent af2081caaf
commit a862f8557e
Signed by: Rick
GPG Key ID: 2B593F087240EE99
2 changed files with 17 additions and 0 deletions

View File

@ -40,6 +40,8 @@ int native_command(char *command[])
change_dir(command);
else if (!strcmp(command[0], "exit"))
thus_exit(command);
else if (!strcmp(command[0], "export"))
thus_export(command);
else if (!strcmp(command[0], "ouï-dire") || !strcmp(command[0], "oui-dire")
|| !strcmp(command[0], "echo"))
{
@ -98,6 +100,20 @@ void thus_exit(char *command[])
need_exit = 1;
}
void thus_export(char *command[])
{
char f = '=';
char *token = strtok(command[1], &f);
char *var = token;
token = strtok(NULL, &f);
char *val;
if (token == NULL)
val = "";
else
val = token;
setenv(var, val, 1);
}
void ctrl_c_handler()
{
//kill(pid, SIGTERM);

View File

@ -26,6 +26,7 @@ extern int need_exit; /* 0 = pas besoin de sortir, 1 = commande exit appelée */
int native_command(char *command[]);
void change_dir(char *command[]);
void thus_exit(char *command[]);
void thus_export(char *command[]);
void ctrl_c_handler();
void error(int code, int type, char *message);