PDA

View Full Version : Re-writing ls -F in C++



Unregistered
03-19-2002, 12:50 PM
...on a Unix box.

As the subject states, I am re-writing the ls -F command in C++, but I am having trouble adding some of the Formatting characters to the files names. Here is my code:



if (strcmp(buff, "-F")==0)
{
struct stat s;
stat(direntp->d_name,&s);
cout<<direntp->d_name;
if(s.st_mode & S_IFDIR)
cout<<"/"<<endl;
else
if(s.st_mode & S_IFIFO)
cout<<"|"<<endl;
else
if(s.st_mode & S_IFLNK)
cout<<" "<<endl;
else
if(s.st_mode & S_IFDOOR)
cout<<">"<<endl;
else
if(s.st_mode & S_IFSOCK)
cout<<"="<<endl;
else
if((s.st_mode & S_IXUSR) && (s.st_mode & S_IFLNK))
cout<<"*"<<endl;
else
cout<<"?"<<endl;
}//end if


It is adding the correct formatting character ("/") for directories, but not for my execuatble files such as "a.out" and "paige_sh" which should have an asterick (*). Here is a sample run:



mars:$ a.out
-F
./
../
shell1.cpp
env.c
core

a.out
modshell2.1.cpp
read_command
shell.sh
shell
test.sh
ansipr
shell2.c.save
paige_sh
modshell1.2.cpp
modshell1.3.cpp
gid.c
modshell2.3.cpp
1814shell.cpp
cpplist
uid.c
listfile.txt
listDir.cpp
modshell2.cpp
modshell2.2.cpp
rewritels.cpp
writels2.cpp
justafile.txt
justafile2.txt
justadir/
justadir2/


can anyone help?? Thanks.

Unregistered
03-21-2002, 08:39 AM
never mind...fixed it myself