bore

Unnamed repository
Log | Files | Refs | README

commit 9131e5cd54ec132273ef76e1b565caeee2ff31c4
parent cd005c8f7f4752e128a7e7c71807b4f7d42a5f08
Author: phoebos <ben@bvnf.space>
Date:   Tue, 21 Sep 2021 00:53:53 +0100

ls: add -F, -p

Diffstat:
MPROGRESS | 2+-
Mls.c | 36+++++++++++++++++++++++++++++++++---
2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/PROGRESS b/PROGRESS @@ -20,7 +20,7 @@ [ ] id [ ] kill [ ] ln -[ ] ls +[ ] ls [-1Fp] [ ] mkdir [ ] more [ ] mv diff --git a/ls.c b/ls.c @@ -7,7 +7,10 @@ #include <unistd.h> enum { - FLAG_1 = 1 << 0 + FLAG_1 = 1 << 0, + FLAG_F = 1 << 1, + FLAG_l = 1 << 2, + FLAG_p = 1 << 3, }; struct ent { @@ -19,6 +22,25 @@ int printname(struct ent *e, int flags) { printf("%s", e->name); + char s = 0; + if (flags & FLAG_p) + if (S_ISDIR(e->mode)) + s = '/'; + if (flags & FLAG_F) { + if (S_ISSOCK(e->mode)) + s = '='; + else if (S_ISDIR(e->mode)) + s = '/'; + else if (S_ISFIFO(e->mode)) + s = '|'; + else if (S_ISLNK(e->mode)) + s = '@'; + else if (e->mode & S_IXUSR || e->mode & S_IXGRP || e->mode & S_IXOTH) + s = '*'; + } + if (s != 0) + putc(s, stdout); + if (flags & FLAG_1) putc('\n', stdout); else @@ -70,12 +92,20 @@ main(int argc, char **argv) { int c, flags, ret_val; flags = ret_val = 0; - while ((c = getopt(argc, argv, "1l")) != -1) { + while ((c = getopt(argc, argv, "1Flp")) != -1) { switch (c) { case '1': - case 'l': flags |= FLAG_1; break; + case 'F': + flags |= FLAG_F; + break; + case 'l': + flags |= FLAG_l | FLAG_1; + break; + case 'p': + flags |= FLAG_p; + break; } } argv += optind - 1;