|
@@ -11,13 +11,19 @@
|
|
|
#include "error.h"
|
|
|
#include "str.h"
|
|
|
#include "parser.h"
|
|
|
+#include "mysh.h"
|
|
|
+#include "execute.h"
|
|
|
#include "command.h"
|
|
|
|
|
|
/* --- Extern --- */
|
|
|
extern Error error;
|
|
|
-char* cmdlist[3] = {
|
|
|
+extern pid_t last;
|
|
|
+extern int status_cmd;
|
|
|
+extern int result_cmd;
|
|
|
+char* cmdlist[NB_CMD] = {
|
|
|
"cd",
|
|
|
"exit",
|
|
|
+ "status",
|
|
|
NULL
|
|
|
};
|
|
|
boolean exitsh = false;
|
|
@@ -113,7 +119,12 @@ int launch_internal_command(Command* cmd) {
|
|
|
else if (strncmp(cmd->name, cmdlist[1], length) == 0) {
|
|
|
result = exit_sh(cmd->argc, cmd->argv);
|
|
|
return result;
|
|
|
- }
|
|
|
+ }
|
|
|
+ //status
|
|
|
+ else if (strncmp(cmd->name, cmdlist[2], length) == 0) {
|
|
|
+ result = status(cmd->argc, cmd->argv);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
//Aucune commande
|
|
|
else {
|
|
|
return SHELL_FAIL;
|
|
@@ -149,4 +160,18 @@ int cd(int argc, char** argv) {
|
|
|
int exit_sh(int argc, char** argv){
|
|
|
exitsh = true;
|
|
|
return EXIT_SUCCESS;
|
|
|
+}
|
|
|
+
|
|
|
+int status(int argc, char** argv){
|
|
|
+ if(!(last != -1 && status_cmd != -1)){
|
|
|
+ error.print("Aucune commande executée\n");
|
|
|
+ return EXIT_FAILURE;
|
|
|
+ }
|
|
|
+ //En fonction du status
|
|
|
+ if(result_cmd == SHELL_FAIL){
|
|
|
+ printf("%d terminé anormalement\n", last);
|
|
|
+ } else {
|
|
|
+ printf("%d terminé avec comme code de retour %d\n", last, status_cmd);
|
|
|
+ }
|
|
|
+ return EXIT_SUCCESS;
|
|
|
}
|