bore

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

commit a4a97949e33195bc2a81ee05aa11f76707c8d885
parent 05371b27d32de17361a9b3647ee949b72bb20ea2
Author: phoebos <ben@bvnf.space>
Date:   Tue, 12 Oct 2021 21:41:36 +0100

ls: add -q

Diffstat:
MPROGRESS | 2+-
Mls.c | 23+++++++++++++++++++----
2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/PROGRESS b/PROGRESS @@ -22,7 +22,7 @@ [ ] id [ ] kill [ ] ln -[ ] ls [-1AFacipu] +[ ] ls [-1AFacipuq] [ ] mkdir [ ] more [ ] mv diff --git a/ls.c b/ls.c @@ -1,3 +1,4 @@ +#include <ctype.h> #include <dirent.h> #include <errno.h> #include <fcntl.h> @@ -21,6 +22,7 @@ enum { FLAG_l = 1 << 6, FLAG_p = 1 << 7, FLAG_u = 1 << 8, + FLAG_q = 1 << 9, }; struct ent { @@ -71,6 +73,16 @@ pretty_print_perms(mode_t mode) { printf(" "); } +void +qprint(const char *name, int qflag) { + for (const char *c = name; *c; c++) { + if (isprint(*c) || !qflag) + putchar(*c); + else + putchar('?'); + } +} + int printname(struct ent *e, uint32_t flags) { if (flags & FLAG_i) @@ -129,7 +141,7 @@ printname(struct ent *e, uint32_t flags) { printf("%s ", buf); } - printf("%s", e->name); + qprint(e->name, flags & FLAG_q); char s = 0; if (flags & FLAG_p) @@ -239,10 +251,10 @@ main(int argc, char **argv) { uint32_t flags; flags = ret_val = 0; - while ((c = getopt(argc, argv, "1AFachilpu")) != -1) { + while ((c = getopt(argc, argv, "1AFachilpuq")) != -1) { switch (c) { case '1': - flags |= FLAG_1; + flags |= FLAG_1 | FLAG_q; break; case 'A': flags |= FLAG_A; @@ -257,7 +269,7 @@ main(int argc, char **argv) { flags |= FLAG_c; break; case 'h': - printf("usage: %s [-1AFacilpu]\n", argv[0]); + printf("usage: %s [-1AFacilpuq]\n", argv[0]); return 0; case 'i': flags |= FLAG_i; @@ -271,6 +283,9 @@ main(int argc, char **argv) { case 'u': flags |= FLAG_u; break; + case 'q': + flags |= FLAG_q; + break; } } argv += optind - 1;