Skip to content

Commit

Permalink
Make ls -k switch off --block-size, document it, and two fixes to lib…
Browse files Browse the repository at this point in the history
…/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.
  • Loading branch information
landley committed Aug 15, 2023
1 parent 8deb589 commit 4c535fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions toys/posix/ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 4c535fe

Please sign in to comment.