Add ls -A implementation

Thanks joshua@cubesolving.com!
This commit is contained in:
sin 2015-02-21 09:30:08 +00:00
parent 6abce61877
commit 9c30fbf018
3 changed files with 14 additions and 5 deletions

2
README
View File

@ -41,7 +41,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
=* ln yes none =* ln yes none
=* logger yes none =* logger yes none
=* logname 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 =* md5sum non-posix none
=* mkdir yes none =* mkdir yes none
=* mkfifo yes none =* mkfifo yes none

6
ls.1
View File

@ -1,4 +1,4 @@
.Dd February 18, 2015 .Dd February 21, 2015
.Dt LS 1 .Dt LS 1
.Os sbase .Os sbase
.Sh NAME .Sh NAME
@ -6,7 +6,7 @@
.Nd list directory contents .Nd list directory contents
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl 1acdFHhiLlqrtUu .Op Fl 1AacdFHhiLlqrtUu
.Op Ar file ... .Op Ar file ...
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
@ -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. are given the current directory is listed.
.Sh OPTIONS .Sh OPTIONS
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl A
List all entries except for '.' and '..'.
.It Fl a .It Fl a
Show hidden files (those beginning with '.'). Show hidden files (those beginning with '.').
.It Fl c .It Fl c

11
ls.c
View File

@ -24,6 +24,7 @@ struct entry {
ino_t ino; ino_t ino;
}; };
static int Aflag = 0;
static int aflag = 0; static int aflag = 0;
static int cflag = 0; static int cflag = 0;
static int dflag = 0; static int dflag = 0;
@ -204,8 +205,11 @@ lsdir(const char *path)
} }
while ((d = readdir(dp))) { while ((d = readdir(dp))) {
if (d->d_name[0] == '.' && !aflag) if (d->d_name[0] == '.' && !aflag && !Aflag)
continue; continue;
else if (Aflag)
if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0)
continue;
if (Uflag){ if (Uflag){
mkent(&ent, d->d_name, Fflag || lflag || pflag || iflag, Lflag); mkent(&ent, d->d_name, Fflag || lflag || pflag || iflag, Lflag);
output(&ent); output(&ent);
@ -256,7 +260,7 @@ ls(const struct entry *ent)
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s [-1acdFHhiLlqrtUu] [file ...]\n", argv0); eprintf("usage: %s [-1AacdFHhiLlqrtUu] [file ...]\n", argv0);
} }
int int
@ -269,6 +273,9 @@ main(int argc, char *argv[])
case '1': case '1':
/* ignore */ /* ignore */
break; break;
case 'A':
Aflag = 1;
break;
case 'a': case 'a':
aflag = 1; aflag = 1;
break; break;