Browse Source

add function getotp for a and R

MaxenceBacquet 6 năm trước cách đây
mục cha
commit
d18207cce7
1 tập tin đã thay đổi với 26 bổ sung4 xóa
  1. 26 4
      myls.c

+ 26 - 4
myls.c

@@ -8,6 +8,7 @@
 #include "parser.h"
 #include "error.h"
 #include "color.h"
+#include "constante.h"
 
 
 void lsBasics(int argc, char* argv[]){
@@ -15,7 +16,10 @@ void lsBasics(int argc, char* argv[]){
     struct dirent** contentsDir;
     struct stat info;
     char path[BUFFER_SIZE];
-    int i = 0, nbFile;
+    char permission[10] = "----------";
+    int i = 0, nbFile, opt;
+    boolean hiddenFile = false;
+    boolean checksubDir = false;
 
     //Recuperation chemin actuel
     if (getcwd(buffer, sizeof (buffer)) == NULL) {
@@ -23,31 +27,49 @@ void lsBasics(int argc, char* argv[]){
         return;
     }
 
-    //Ouverture et lecture DIR
+    //Ouverture et lecture DIR - inutile
     /*if((path = opendir(buffer)) == NULL){
         addperror("Erreur opendir()")
         return;
     }*/
 
     //Recup la liste des fichiers dans le dossier courant
-    nbFile = scandir(buffer, &contentsDir, 0, alphasort);
+    nbFile = scandir(".", &contentsDir, 0, alphasort);
     if (nbFile < 0) {
         addperror("Erreur scandir()");
         return;
     }
 
+    //Gestion des options
+    while((opt = getopt(argc, argv, "aR")) != ERR){
+        switch(opt){
+            case 'a' : 
+                hiddenFile = true;
+                break;
+            case 'R' : 
+                checksubDir = true;
+                break;
+            default:
+                addperror("getotp error");
+        }
+    }
+
+    //enleve les fichiers caches
+    while(i < nbFile && !hiddenFile && *contentsDir[i]->d_name == '.') i++;
+
     //Affiche les fichiers
     while(i < nbFile){
         strcpy(path, buffer);
         strcat(path, "/");
         strcat(path, contentsDir[i]->d_name);
-        printf("%s\n", path);
         if(stat(path, &info) == ERR)
             addperror("Erreur stat");
         printf("%d  %ld  %s\n", info.st_mode, info.st_size, contentsDir[i]->d_name);
         i++;
     }
 
+    printf("%d   %d\n", hiddenFile, checksubDir);
+
     return;
 }