![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Accepting filename as command line param and writing to it | silas.john | Shell Programming and Scripting | 9 | 02-06-2008 06:26 AM |
| writing your own command in unix/linux | Amardeep | High Level Programming | 3 | 03-15-2007 06:49 PM |
| Writing to a floppy | jlrusso | Filesystems, Disks and Memory | 2 | 09-23-2003 11:04 PM |
| writing to /tmp | vtran4270 | UNIX for Advanced & Expert Users | 3 | 04-04-2003 01:22 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Re-writing ls -F command
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:
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
Code:
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/ |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
It looks like you are trying to append an asterisk if both S_IXUSR and S_IFLNK are set. But earlier in your massive "if" statement you have already tested for S_IFLNK being set all by itself. So no condition can allow to reach the point where you append an asterisk.
Even if you square this away, you have a couple of other problems. S_IFLNK is a symlink, so instead of appending a blank (and what would be the point of that anyway), you want to append an at-sign. Also, I think that for executables, you want to ensure first that S_IFREG is set and second that one or more of S_IXUSR, S_IXGRP, or S_IXOTH is set. |
|
#3
|
|||
|
|||
|
well I only added the && part for the executables after it didnt work in the first place. I ran ls -la regularly and saw that the executables had symbolic links so added to && part to see if it worked since the executables proved true for both conditions.
I HAD the "@" for the links, but took it off so that I could actually SEE what I was lookin at when I ran it...that's the purpose of the white space instead of the symbol. I was going to replace it after I was completely through with the program. However, I am going to take a look @ the other things you suggested and get back at you. Thanks |
|
#4
|
|||
|
|||
|
problem solved
Quote:
Thanks. It turned out that the executables needed to be placed before the links because it was negating it. |
|||
| Google The UNIX and Linux Forums |