bore

basic core utilities (PD)
git clone git://bvnf.space/bore.git
Log | Files | Refs | README

commit 4aab5d90ec47ab29ac7c9ac5d8218c1a1723f7e2
parent fb2cc147c900d213cff819c4581befe225ea39db
Author: phoebos <ben@bvnf.space>
Date:   Tue, 12 Oct 2021 11:11:30 +0100

ls: add -A

Diffstat:
MPROGRESS | 2+-
Mls.c | 24+++++++++++++++++-------
2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/PROGRESS b/PROGRESS @@ -22,7 +22,7 @@ [ ] id [ ] kill [ ] ln -[ ] ls [-1Fap] +[ ] ls [-1AFap] [ ] mkdir [ ] more [ ] mv diff --git a/ls.c b/ls.c @@ -9,10 +9,11 @@ enum { FLAG_1 = 1 << 0, - FLAG_F = 1 << 1, - FLAG_a = 1 << 2, - FLAG_l = 1 << 3, - FLAG_p = 1 << 4, + FLAG_A = 1 << 1, + FLAG_F = 1 << 2, + FLAG_a = 1 << 3, + FLAG_l = 1 << 4, + FLAG_p = 1 << 5, }; struct ent { @@ -68,7 +69,13 @@ ls(const char *path, int flags) { return 1; } for (i = 0; i < n; i++) { - if (~flags & FLAG_a && dp[i]->d_name[0] == '.') + if (~flags & FLAG_a && ~flags & FLAG_A && dp[i]->d_name[0] == '.') + /* if no -A or -a, skip \.* */ + continue; + if (flags & FLAG_A && dp[i]->d_name[0] == '.' + && (dp[i]->d_name[1] == '\0' + || (dp[i]->d_name[1] == '.' && dp[i]->d_name[2] == '\0'))) + /* if -A, skip '.' or '..' */ continue; struct stat stt; @@ -98,11 +105,14 @@ main(int argc, char **argv) { int c, flags, ret_val; flags = ret_val = 0; - while ((c = getopt(argc, argv, "1Fahlp")) != -1) { + while ((c = getopt(argc, argv, "1AFahlp")) != -1) { switch (c) { case '1': flags |= FLAG_1; break; + case 'A': + flags |= FLAG_A; + break; case 'F': flags |= FLAG_F; break; @@ -110,7 +120,7 @@ main(int argc, char **argv) { flags |= FLAG_a; break; case 'h': - printf("usage: %s [-1Falp]\n", argv[0]); + printf("usage: %s [-1AFalp]\n", argv[0]); return 0; case 'l': flags |= FLAG_l | FLAG_1;