| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #define _DEFAULT_SOURCE
- #include <dirent.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <string.h>
- #include "parser.h"
- #include "error.h"
- #include "color.h"
- #include "constante.h"
- void lsBasics(int argc, char* argv[]){
- char buffer[BUFFER_SIZE];
- struct dirent** contentsDir;
- struct stat info;
- char path[BUFFER_SIZE];
- char permission[10] = "----------";
- int i = 0, nbFile, opt;
- boolean hiddenFile = false;
- boolean checksubDir = false;
- //Recuperation chemin actuel
- if (getcwd(buffer, sizeof (buffer)) == NULL) {
- addperror("Erreur getcwd()");
- 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){
- 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);
- 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;
- }
- int main(int argc, char* argv[]){
- lsBasics(argc, argv);
- printf(RESET);
- }
|