Quellcode durchsuchen

:building_construction: Réorganisation fichier mysh

Loquicom vor 6 Jahren
Ursprung
Commit
5bcdd8532b
2 geänderte Dateien mit 51 neuen und 31 gelöschten Zeilen
  1. 33 31
      mysh.c
  2. 18 0
      mysh.h

+ 33 - 31
mysh.c

@@ -8,44 +8,16 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include "parser.h"
+#include "mysh.h"
 
-
+/* --- Fonctions privées --- */
 void test_write(){
     char* a = "azerty\n";
     int tmp = write(1, a, strlen(a));
     printf("%d\n", tmp);
 }
 
-void current_rep(){
-    char buffer[512];
-    if (getcwd(buffer, sizeof(buffer)) == NULL){
-        perror("Erreur getcwd() : ");
-    }
-    else {
-        printf("current working directory is: %s\n", buffer);
-    }
-}
-
-void cd(int argc, char** argv){
-    current_rep();
-    if(argc > 2) {
-        printf("too many arguments : 1 required, %d given\n", argc-1);
-    }
-    else {
-        if(argc == 1) {
-            if(chdir("/") == ERR){
-                perror("Erreur chdir() : ");
-            }
-        }
-        else {
-            if(chdir(argv[1]) == ERR){
-                printf("path does not exist\n");
-            }
-        }
-    }
-    current_rep();
-}
-
+/* --- Main --- */
 int main(int argc, char* argv[]) {
 
     /*CommandTab ct;
@@ -78,3 +50,33 @@ int main(int argc, char* argv[]) {
 
 }
 
+/* --- Commandes internes --- */
+void cd(int argc, char** argv){
+    if(argc > 2) {
+        printf("too many arguments : 1 required, %d given\n", argc-1);
+    }
+    else {
+        if(argc == 1) {
+            if(chdir("/") == ERR){
+                perror("Erreur chdir() : ");
+            }
+        }
+        else {
+            if(chdir(argv[1]) == ERR){
+                printf("path does not exist\n");
+            }
+        }
+    }
+    //show_current_dir("current working directory is: ", "\n");
+}
+
+/* --- Fonctions utilitaires --- */
+void show_current_dir(const char* before, const char* after){
+    char buffer[512];
+    if (getcwd(buffer, sizeof(buffer)) == NULL){
+        perror("Erreur getcwd() : ");
+    }
+    else {
+        printf("%s%s%s", before, buffer, after);
+    }
+}

+ 18 - 0
mysh.h

@@ -0,0 +1,18 @@
+/* 
+ * File:   mysh.h
+ * Author: Arthur Brandao
+ *
+ * Created on 6 novembre 2018
+ */
+
+#ifndef MYSH_H
+#define MYSH_H
+
+/* --- Fonctions utilitaires --- */
+void show_current_dir(const char*, const char*);
+
+/* --- Commandes internes --- */
+void cd(int, char**);
+
+#endif /* MYSH_H */
+