|
@@ -10,14 +10,51 @@
|
|
|
#include "color.h"
|
|
|
#include "constante.h"
|
|
|
|
|
|
+int printDir(struct dirent** contentsDir, char* path, int nbFile, struct stat info,
|
|
|
+ boolean hiddenFile){
|
|
|
|
|
|
-void lsBasics(int argc, char* argv[]){
|
|
|
+ //char permission[10] = "----------";
|
|
|
+ int j = 0;
|
|
|
+
|
|
|
+ //enleve les fichiers caches
|
|
|
+ while(j < nbFile && !hiddenFile && *contentsDir[j]->d_name == '.') j++;
|
|
|
+
|
|
|
+ //Affiche les fichiers
|
|
|
+ while(j < nbFile){
|
|
|
+ /*switch(info.st_mode){
|
|
|
+ case S_IRUSR:
|
|
|
+ permission[1] = 'r';
|
|
|
+ case S_IWUSR:
|
|
|
+ permission[2] = 'w';
|
|
|
+ case S_IXUSR:
|
|
|
+ permission[3] = 'x';
|
|
|
+ case S_IRGRP:
|
|
|
+ permission[4] = 'r';
|
|
|
+ case S_IWGRP:
|
|
|
+ permission[5] = 'w';
|
|
|
+ case S_IXGRP:
|
|
|
+ permission[6] = 'x';
|
|
|
+ case S_IROTH:
|
|
|
+ permission[7] = 'r';
|
|
|
+ case S_IWOTH:
|
|
|
+ permission[8] = 'w';
|
|
|
+ case S_IXOTH:
|
|
|
+ permission[9] = 'x';
|
|
|
+ }*/
|
|
|
+ printf("%d %ld %s\n", info.st_mode, info.st_size, contentsDir[j]->d_name);
|
|
|
+ //printf("%s", permission);
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+void ls(int argc, char* argv[]){
|
|
|
char buffer[BUFFER_SIZE];
|
|
|
+ char path[BUFFER_SIZE];
|
|
|
struct dirent** contentsDir;
|
|
|
struct stat info;
|
|
|
- char path[BUFFER_SIZE];
|
|
|
- char permission[10] = "----------";
|
|
|
- int i = 0, nbFile, opt;
|
|
|
+ int i = 1, j = 0, displayed = 0, nbFile, opt;
|
|
|
boolean hiddenFile = false;
|
|
|
boolean checksubDir = false;
|
|
|
|
|
@@ -27,19 +64,6 @@ void lsBasics(int argc, char* argv[]){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- //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(".", &contentsDir, 0, alphasort);
|
|
|
- if (nbFile < 0) {
|
|
|
- addperror("Erreur scandir()");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
//Gestion des options
|
|
|
while((opt = getopt(argc, argv, "aR")) != ERR){
|
|
|
switch(opt){
|
|
@@ -54,18 +78,43 @@ void lsBasics(int argc, char* argv[]){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //enleve les fichiers caches
|
|
|
- while(i < nbFile && !hiddenFile && *contentsDir[i]->d_name == '.') i++;
|
|
|
+ //Time to display
|
|
|
+ for(i = 1; i < argc; i++){
|
|
|
+ if(argv[i][0] != '-'){
|
|
|
+ strcpy(path, buffer);
|
|
|
+ strcat(path, "/");
|
|
|
+ strcat(path, argv[i]);
|
|
|
+ if(stat(path, &info) == ERR)
|
|
|
+ addperror("Erreur stat");
|
|
|
+ if(S_ISDIR(info.st_mode)){
|
|
|
+ nbFile = scandir(argv[i], &contentsDir, 0, alphasort);
|
|
|
+ if (nbFile < 0) {
|
|
|
+ addperror("Erreur scandir()");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ printf("%s : \n\n", argv[i]);
|
|
|
+ strcpy(path, buffer);
|
|
|
+ strcat(path, "/");
|
|
|
+ strcat(path, contentsDir[j]->d_name);
|
|
|
+ displayed = printDir(contentsDir, path, nbFile, info, hiddenFile);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ printf("%d %ld %s\n", info.st_mode, info.st_size, argv[i]);
|
|
|
+ displayed = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //Affiche les fichiers
|
|
|
- while(i < nbFile){
|
|
|
+ if(!displayed){
|
|
|
+ nbFile = scandir(".", &contentsDir, 0, alphasort);
|
|
|
+ if (nbFile < 0) {
|
|
|
+ addperror("Erreur scandir()");
|
|
|
+ return;
|
|
|
+ }
|
|
|
strcpy(path, buffer);
|
|
|
strcat(path, "/");
|
|
|
- strcat(path, contentsDir[i]->d_name);
|
|
|
- if(stat(path, &info) == ERR)
|
|
|
- addperror("Erreur stat");
|
|
|
- printf("%d %ld %s\n", info.st_mode, info.st_size, contentsDir[i]->d_name);
|
|
|
- i++;
|
|
|
+ strcat(path, contentsDir[j]->d_name);
|
|
|
+ displayed = printDir(contentsDir, path, nbFile, info, hiddenFile);
|
|
|
}
|
|
|
|
|
|
printf("%d %d\n", hiddenFile, checksubDir);
|
|
@@ -75,6 +124,6 @@ void lsBasics(int argc, char* argv[]){
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]){
|
|
|
- lsBasics(argc, argv);
|
|
|
+ ls(argc, argv);
|
|
|
printf(RESET);
|
|
|
}
|