Programmation de la commande ls -l - Il ne me manque plus que la couleur

Voila, j’ai ré écris la commande ls -l , mais je ne sais pas comment implémenter la couleur pour les différent types de fichier ( script, répertoire, etc… )

Voici mon code :

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>

main(int argc, char *argv[])
{
DIR *rep_cour; //crée un pointeur de type repertoire

struct dirent *entree; // crée un structure entrée repertoire
struct stat info;
struct pwent pass;

char user[4],group[4],other[4];
p=getpwuid(info.st_uid);
g=getgrgid(info.st_gid);

user[0]=(info.st_mode & S_IRUSR) ? ‘r’ : ‘-’);
user[1]=(info.st_mode & S_IWUSR) ? ‘w’ : ‘-’);
user[2]=(info.st_mode & S_IXUSR) ? ‘x’ : ‘-’);

group[0]=(info.st_mode & S_IRGRP) ? ‘r’ : ‘-’);
group[1]=(info.st_mode & S_IWGRP) ? ‘w’ : ‘-’);
group[2]=(info.st_mode & S_IXGRP) ? ‘x’ : ‘-’);

other[0]=(info.st_mode & S_IROTH) ? ‘r’ : ‘-’);
other[1]=(info.st_mode & S_IWOTH) ? ‘w’ : ‘-’);
other[2]=(info.st_mode & S_IXOTH) ? ‘x’ : ‘-’);

rep_cour = opendir(".");// met dans rep_cour ce qui est lu dans le repertoire courant

while (entree=readdir(rep_cour))// tant que il n’est pas arrivé a la fin du repertoire
{
if(entree->d_name[0] != ‘.’)//test si le premier est un caractère.
{
lstat(entree->d_name,&info);
printf("%d %d %s %s %s %s \n", entree->d_ino,info.st_nlink,user,group,other,p->d_name);// affiche le numéros d’i noeud et le nom du fichier
}
}

return 0;

}

Ou dois-je faire ces modifs ??

y’a une modif a faire dans le printf pour afficher en couleur. essaie en googelisant :slight_smile:

et tente ça :

http://www.bluesock.org/%7Ewillg/dev/ansi.html