[hackers] [sbase] Add ls -A implementation || sin

From: <git_AT_suckless.org>
Date: Sat, 21 Feb 2015 10:33:31 +0100 (CET)

commit 310dc6e6f5d3ce556f22b1a0f53a7da95bd40843
Author: sin <sin_AT_2f30.org>
Date: Sat Feb 21 09:30:08 2015 +0000

    Add ls -A implementation
    
    Thanks joshua_AT_cubesolving.com!

diff --git a/README b/README
index fdd81df..cc3869e 100644
--- a/README
+++ b/README
_AT_@ -41,7 +41,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
 =* ln yes none
 =* logger yes none
 =* logname yes none
-= ls no -A, (-C), -R, -S, -f, -m, -n, -s, -x
+= ls no (-C), -R, -S, -f, -m, -n, -s, -x
 =* md5sum non-posix none
 =* mkdir yes none
 =* mkfifo yes none
diff --git a/ls.1 b/ls.1
index d46e97c..841e1bb 100644
--- a/ls.1
+++ b/ls.1
_AT_@ -1,4 +1,4 @@
-.Dd February 18, 2015
+.Dd February 21, 2015
 .Dt LS 1
 .Os sbase
 .Sh NAME
_AT_@ -6,7 +6,7 @@
 .Nd list directory contents
 .Sh SYNOPSIS
 .Nm
-.Op Fl 1acdFHhiLlqrtUu
+.Op Fl 1AacdFHhiLlqrtUu
 .Op Ar file ...
 .Sh DESCRIPTION
 .Nm
_AT_@ -14,6 +14,8 @@ lists each given file, and the contents of each given directory. If no files
 are given the current directory is listed.
 .Sh OPTIONS
 .Bl -tag -width Ds
+.It Fl A
+List all entries except for '.' and '..'.
 .It Fl a
 Show hidden files (those beginning with '.').
 .It Fl c
diff --git a/ls.c b/ls.c
index 8d2c3f6..5db22d8 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_@ -256,7 +260,7 @@ ls(const struct entry *ent)
 static void
 usage(void)
 {
- eprintf("usage: %s [-1acdFHhiLlqrtUu] [file ...]\n", argv0);
+ eprintf("usage: %s [-1AacdFHhiLlqrtUu] [file ...]\n", argv0);
 }
 
 int
_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 - 10:33:31 CET

This archive was generated by hypermail 2.3.0 : Sat Feb 21 2015 - 10:36:38 CET