Browse Source

Ajout comportement par defaut set et setenv

Loquicom 6 years ago
parent
commit
59219854df
6 changed files with 32 additions and 4 deletions
  1. 4 4
      command.c
  2. 8 0
      ipc.c
  3. 5 0
      ipc.h
  4. 6 0
      subdiv.c
  5. 4 0
      variable.c
  6. 5 0
      variable.h

+ 4 - 4
command.c

@@ -221,8 +221,8 @@ int set_env(int argc, char** argv) {
     int length, pos = 0;
     //Verif les arguments
     if (argc < 2) {
-        error.print("too few arguments : 1 required, 0 given\n");
-        return EXIT_FAILURE;
+        show_shm_data();
+        return EXIT_SUCCESS;
     }
     if (argc > 2) {
         error.print("too many arguments : 1 required, %d given\n", argc - 1);
@@ -292,8 +292,8 @@ int set_local(int argc, char** argv){
     int length, pos = 0;
     //Verif les arguments
     if (argc < 2) {
-        error.print("too few arguments : 1 required, 0 given\n");
-        return EXIT_FAILURE;
+        show_local_data();
+        return EXIT_SUCCESS;
     }
     if (argc > 2) {
         error.print("too many arguments : 1 required, %d given\n", argc - 1);

+ 8 - 0
ipc.c

@@ -139,4 +139,12 @@ boolean remove_shm_data(char* key){
     V(&ipc.sem, SEMWAIT);
     V(&ipc.sem, SEMECRIRE);
     return res;
+}
+
+void show_shm_data(){
+    //Recup variable globale
+    subdiv* sd = (subdiv*) ipc.gestionnaire.adr;
+    char* mem = (char*) ipc.memoire.adr;
+    //Affiche
+    show_data_subdiv(sd, mem);
 }

+ 5 - 0
ipc.h

@@ -56,5 +56,10 @@ boolean add_shm_data(char*);
  */
 boolean remove_shm_data(char*);
 
+/**
+ * Affiche les variables dans la mémoire
+ */
+void show_shm_data();
+
 #endif /* IPC_H */
 

+ 6 - 0
subdiv.c

@@ -266,9 +266,11 @@ void show_subdiv(subdiv* sd) {
 }
 
 void show_data_subdiv(subdiv* sd, char* mem){
+    boolean vide = true;
     node* n = &sd->mem[0];
     while (n != NULL) {
         if(n->type == MEMSET){
+            vide = false;
             char* str = malloc(sizeof(char) * (n->length + 1));
             char* deb = mem + n->start;
             memset(str, 0, n->length + 1);
@@ -278,4 +280,8 @@ void show_data_subdiv(subdiv* sd, char* mem){
         }
         n = n->next;
     }
+    //Si vide
+    if(vide){
+        printf("Aucune variable en mémoire\n");
+    }
 }

+ 4 - 0
variable.c

@@ -157,4 +157,8 @@ boolean remove_local_data(char* key){
         return false;
     }
     return remove_data_subdiv(&localsd, localmem, key);
+}
+
+void show_local_data(){
+    show_data_subdiv(&localsd, localmem);
 }

+ 5 - 0
variable.h

@@ -45,5 +45,10 @@ boolean add_local_data(char*);
  */
 boolean remove_local_data(char*);
 
+/**
+ * Affiche les variables dans la mémoire
+ */
+void show_local_data();
+
 #endif /* VARIABLE_H */