[sbase] [dev] [ls] [PATCH] Add ls -A

From: <joshua_AT_cubesolving.com>
Date: Sat, 21 Feb 2015 05:56:50 +0000

Add ls -A.
I choose test in an else if due to long condition. Criticism welcome.

diff --git a/ls.c b/ls.c
index 8d2c3f6..03765c6 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -24,6 +24,7 @@ struct entry {
         ino_t ino;
 };
 
+static int Aflag = 0;
 static int aflag = 0;
 static int cflag = 0;
 static int dflag = 0;
_AT_@ -204,8 +205,11 @@ lsdir(const char *path)
         }
 
         while ((d = readdir(dp))) {
- if (d->d_name[0] == '.' && !aflag)
+ if (d->d_name[0] == '.' && !aflag && !Aflag)
                         continue;
+ else if (Aflag)
+ if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0)
+ continue;
                 if (Uflag){
                         mkent(&ent, d->d_name, Fflag || lflag || pflag || iflag, Lflag);
                         output(&ent);
_AT_@ -269,6 +273,9 @@ main(int argc, char *argv[])
         case '1':
                 /* ignore */
                 break;
+ case 'A':
+ Aflag = 1;
+ break;
         case 'a':
                 aflag = 1;
                 break;




Received on Sat Feb 21 2015 - 06:56:50 CET

This archive was generated by hypermail 2.3.0 : Sat Feb 21 2015 - 07:00:09 CET