From 4c535fe4adb1b282b58354dfa442f858128e2168 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 15 Aug 2023 18:22:10 -0500 Subject: [PATCH] Make ls -k switch off --block-size, document it, and two fixes to lib/args.c. 1) handle the high bit octal escape syntax in [-abc] 2) switching off an option sets it back to the default value, not 0. --- lib/args.c | 4 ++-- toys/posix/ls.c | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/args.c b/lib/args.c index 53258279..edf06e99 100644 --- a/lib/args.c +++ b/lib/args.c @@ -135,7 +135,7 @@ static void forget_arg(struct opts *opt) { if (opt->arg) { if (opt->type=='*') llist_traverse((void *)*opt->arg, free); - *opt->arg = 0; + *opt->arg = opt->val[2].l; } } @@ -365,7 +365,7 @@ static int parse_optflaglist(struct getoptflagstate *gof) if (*options==1) break; if (CFG_TOYBOX_DEBUG && !opt) error_exit("[] unknown target %c", *options); - if (opt->c == *options) { + if (opt->c == (127&*options)) { bits |= ll; break; } diff --git a/toys/posix/ls.c b/toys/posix/ls.c index 3e1fad17..f3a5e92b 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -10,11 +10,10 @@ * add -Z -ll --color * Posix says the -l date format should vary based on how recent it is * and we do --time-style=long-iso instead - * ignore -k because we default to 1024 byte blocks * Deviations from gnu: -N switches off -q (no --show-control-chars) * No --quoting-style=shell-escape, mostly because no short or long opt for it -USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(block-size)#=1024<1(show-control-chars)\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\377(block-size)#=1024<1\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb][-k\377]", TOYFLAG_BIN|TOYFLAG_LOCALE)) config LS bool "ls" @@ -37,16 +36,17 @@ config LS output formats: -1 list one file per line -C columns (sorted vertically) -g like -l but no owner -h human readable sizes - -l long (show full details) -ll long with nanoseconds (--full-time) - -m comma separated -n long with numeric uid/gid - -o long without group column -r reverse order - -w set column width -x columns (horizontal sort) + -k reset --block-size to default -l long (show full details) + -m comma separated -ll long with nanoseconds (--full-time) + -n long with numeric uid/gid -o long without group column + -r reverse order -w set column width + -x columns (horizontal sort) sort by: (also --sort=longname,longname... ends with alphabetical) -c ctime -r reverse -S size -t time -u atime -U none -X extension -! dirfirst -~ nocase - --block-size N block size (default 1024) + --block-size N block size (default 1024, -k resets to 1024) --color =always (default) =auto (when stdout is tty) =never exe=green suid=red suidfile=redback stickydir=greenback device=yellow symlink=turquoise/red dir=blue socket=purple -- 2.39.2