From a862f8557ee89a2f4bc27626aac3508adadad261 Mon Sep 17 00:00:00 2001 From: rick Date: Wed, 24 Feb 2021 02:23:21 +0100 Subject: [PATCH] Ajout export pour init. var. (#6 #5) --- src/boitoutil/essential_shell.c | 16 ++++++++++++++++ src/boitoutil/essential_shell.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/boitoutil/essential_shell.c b/src/boitoutil/essential_shell.c index 80eafcb..217dd81 100644 --- a/src/boitoutil/essential_shell.c +++ b/src/boitoutil/essential_shell.c @@ -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); diff --git a/src/boitoutil/essential_shell.h b/src/boitoutil/essential_shell.h index 21004a3..030a1bf 100644 --- a/src/boitoutil/essential_shell.h +++ b/src/boitoutil/essential_shell.h @@ -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);